use of org.springframework.beans.testfixture.beans.ITestBean in project spring-framework by spring-projects.
the class ThreadLocalTargetSourceTests method testUseDifferentManagedInstancesInSameThread.
/**
* Check we can use two different ThreadLocalTargetSources
* managing objects of different types without them interfering
* with one another.
*/
@Test
public void testUseDifferentManagedInstancesInSameThread() {
SideEffectBean apartment = (SideEffectBean) beanFactory.getBean("apartment");
assertThat(apartment.getCount()).isEqualTo(INITIAL_COUNT);
apartment.doWork();
assertThat(apartment.getCount()).isEqualTo((INITIAL_COUNT + 1));
ITestBean test = (ITestBean) beanFactory.getBean("threadLocal2");
assertThat(test.getName()).isEqualTo("Rod");
assertThat(test.getSpouse().getName()).isEqualTo("Kerry");
}
use of org.springframework.beans.testfixture.beans.ITestBean in project spring-framework by spring-projects.
the class TraceBeforeAdvice method testAfterReturningAdviceWithoutJoinPoint.
private long testAfterReturningAdviceWithoutJoinPoint(String file, int howmany, String technology) {
ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS);
StopWatch sw = new StopWatch();
sw.start(howmany + " repeated after returning advice invocations with " + technology);
ITestBean adrian = (ITestBean) bf.getBean("adrian");
assertThat(AopUtils.isAopProxy(adrian)).isTrue();
Advised a = (Advised) adrian;
assertThat(a.getAdvisors().length >= 3).isTrue();
// Hits joinpoint
adrian.setAge(25);
for (int i = 0; i < howmany; i++) {
adrian.setAge(i);
}
sw.stop();
System.out.println(sw.prettyPrint());
return sw.getLastTaskTimeMillis();
}
use of org.springframework.beans.testfixture.beans.ITestBean in project spring-framework by spring-projects.
the class TraceBeforeAdvice method testMix.
private long testMix(String file, int howmany, String technology) {
ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS);
StopWatch sw = new StopWatch();
sw.start(howmany + " repeated mixed invocations with " + technology);
ITestBean adrian = (ITestBean) bf.getBean("adrian");
assertThat(AopUtils.isAopProxy(adrian)).isTrue();
Advised a = (Advised) adrian;
assertThat(a.getAdvisors().length >= 3).isTrue();
for (int i = 0; i < howmany; i++) {
// Hit all 3 joinpoints
adrian.getAge();
adrian.getName();
adrian.setAge(i);
// Invoke three non-advised methods
adrian.getDoctor();
adrian.getLawyer();
adrian.getSpouse();
}
sw.stop();
System.out.println(sw.prettyPrint());
return sw.getLastTaskTimeMillis();
}
use of org.springframework.beans.testfixture.beans.ITestBean in project spring-framework by spring-projects.
the class TraceBeforeAdvice method testBeforeAdviceWithoutJoinPoint.
private long testBeforeAdviceWithoutJoinPoint(String file, int howmany, String technology) {
ClassPathXmlApplicationContext bf = new ClassPathXmlApplicationContext(file, CLASS);
StopWatch sw = new StopWatch();
sw.start(howmany + " repeated before advice invocations with " + technology);
ITestBean adrian = (ITestBean) bf.getBean("adrian");
assertThat(AopUtils.isAopProxy(adrian)).isTrue();
Advised a = (Advised) adrian;
assertThat(a.getAdvisors().length >= 3).isTrue();
assertThat(adrian.getName()).isEqualTo("adrian");
for (int i = 0; i < howmany; i++) {
adrian.getName();
}
sw.stop();
System.out.println(sw.prettyPrint());
return sw.getLastTaskTimeMillis();
}
use of org.springframework.beans.testfixture.beans.ITestBean in project spring-framework by spring-projects.
the class AopNamespaceHandlerProxyTargetClassTests method testIsClassProxy.
@Test
public void testIsClassProxy() {
ITestBean bean = getTestBean();
assertThat(AopUtils.isCglibProxy(bean)).as("Should be a CGLIB proxy").isTrue();
assertThat(((Advised) bean).isExposeProxy()).as("Should expose proxy").isTrue();
}
Aggregations