use of org.springframework.aop.framework.Advised in project spring-framework by spring-projects.
the class JoinPointMonitorAtAspectJAspect method checkXmlAspect.
private void checkXmlAspect(String appContextFile) {
ApplicationContext context = new ClassPathXmlApplicationContext(appContextFile, getClass());
ICounter counter = (ICounter) context.getBean("counter");
assertTrue("Proxy didn't get created", counter instanceof Advised);
counter.increment();
JoinPointMonitorAspect callCountingAspect = (JoinPointMonitorAspect) context.getBean("monitoringAspect");
assertEquals("Advise didn't get executed", 1, callCountingAspect.beforeExecutions);
assertEquals("Advise didn't get executed", 1, callCountingAspect.aroundExecutions);
}
use of org.springframework.aop.framework.Advised in project spring-framework by spring-projects.
the class SelectivePrototypeTargetSourceCreator method testCustomPrototypeTargetSource.
@Test
public void testCustomPrototypeTargetSource() throws Exception {
CountingTestBean.count = 0;
BeanFactory bf = new ClassPathXmlApplicationContext(CUSTOM_TARGETSOURCE_CONTEXT, CLASS);
ITestBean test = (ITestBean) bf.getBean("prototypeTest");
assertTrue(AopUtils.isAopProxy(test));
Advised advised = (Advised) test;
assertTrue(advised.getTargetSource() instanceof PrototypeTargetSource);
assertEquals("Rod", test.getName());
// Check that references survived prototype creation
assertEquals("Kerry", test.getSpouse().getName());
assertEquals("Only 2 CountingTestBeans instantiated", 2, CountingTestBean.count);
CountingTestBean.count = 0;
}
use of org.springframework.aop.framework.Advised in project spring-framework by spring-projects.
the class SelectivePrototypeTargetSourceCreator method testLazyInitTargetSource.
@Test
public void testLazyInitTargetSource() throws Exception {
CountingTestBean.count = 0;
BeanFactory bf = new ClassPathXmlApplicationContext(CUSTOM_TARGETSOURCE_CONTEXT, CLASS);
ITestBean test = (ITestBean) bf.getBean("lazyInitTest");
assertTrue(AopUtils.isAopProxy(test));
Advised advised = (Advised) test;
assertTrue(advised.getTargetSource() instanceof LazyInitTargetSource);
assertEquals("No CountingTestBean instantiated yet", 0, CountingTestBean.count);
assertEquals("Rod", test.getName());
assertEquals("Kerry", test.getSpouse().getName());
assertEquals("Only 1 CountingTestBean instantiated", 1, CountingTestBean.count);
CountingTestBean.count = 0;
}
use of org.springframework.aop.framework.Advised in project spring-framework by spring-projects.
the class CommonsPool2TargetSourceTests method testProxySerializableWithoutConfigMixin.
@Test
public void testProxySerializableWithoutConfigMixin() throws Exception {
Person pooled = (Person) beanFactory.getBean("pooledPerson");
//System.out.println(((Advised) pooled).toProxyConfigString());
assertTrue(((Advised) pooled).getTargetSource() instanceof CommonsPool2TargetSource);
//((Advised) pooled).setTargetSource(new SingletonTargetSource(new SerializablePerson()));
Person serialized = (Person) SerializationTestUtils.serializeAndDeserialize(pooled);
assertTrue(((Advised) serialized).getTargetSource() instanceof SingletonTargetSource);
serialized.setAge(25);
assertEquals(25, serialized.getAge());
}
use of org.springframework.aop.framework.Advised in project spring-framework by spring-projects.
the class EnableAsyncTests method customAsyncAnnotationIsPropagated.
@Test
public void customAsyncAnnotationIsPropagated() {
AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
ctx.register(CustomAsyncAnnotationConfig.class, CustomAsyncBean.class);
ctx.refresh();
Object bean = ctx.getBean(CustomAsyncBean.class);
assertTrue(AopUtils.isAopProxy(bean));
boolean isAsyncAdvised = false;
for (Advisor advisor : ((Advised) bean).getAdvisors()) {
if (advisor instanceof AsyncAnnotationAdvisor) {
isAsyncAdvised = true;
break;
}
}
assertTrue("bean was not async advised as expected", isAsyncAdvised);
}
Aggregations