use of org.springframework.aop.framework.Advised in project spring-framework by spring-projects.
the class ScriptingDefaultsTests method defaultRefreshCheckDelay.
@Test
public void defaultRefreshCheckDelay() throws Exception {
ApplicationContext context = new ClassPathXmlApplicationContext(CONFIG);
Advised advised = (Advised) context.getBean("testBean");
AbstractRefreshableTargetSource targetSource = ((AbstractRefreshableTargetSource) advised.getTargetSource());
Field field = AbstractRefreshableTargetSource.class.getDeclaredField("refreshCheckDelay");
field.setAccessible(true);
long delay = ((Long) field.get(targetSource)).longValue();
assertEquals(5000L, delay);
}
use of org.springframework.aop.framework.Advised in project cxf by apache.
the class SpringAopClassHelper method getRealObjectInternal.
protected Object getRealObjectInternal(Object o) {
if (o instanceof Advised) {
try {
Advised advised = (Advised) o;
Object target = advised.getTargetSource().getTarget();
// could be a proxy of a proxy.....
return getRealObjectInternal(target);
} catch (Exception ex) {
// ignore
}
}
return o;
}
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());
}
Aggregations