use of org.springframework.tests.sample.beans.ITestBean in project spring-framework by spring-projects.
the class ProxyFactoryBeanTests method testPrototypeInterceptorSingletonTarget.
@Test
public void testPrototypeInterceptorSingletonTarget() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(CONTEXT, CLASS));
ITestBean bean1 = (ITestBean) bf.getBean("prototypeTestBeanProxySingletonTarget");
ITestBean bean2 = (ITestBean) bf.getBean("prototypeTestBeanProxySingletonTarget");
bean1.setAge(1);
bean2.setAge(2);
assertEquals(2, bean1.getAge());
((Lockable) bean1).lock();
try {
bean1.setAge(5);
fail("expected LockedException");
} catch (LockedException ex) {
// expected
}
try {
bean2.setAge(6);
} catch (LockedException ex) {
fail("did not expect LockedException");
}
}
use of org.springframework.tests.sample.beans.ITestBean in project spring-framework by spring-projects.
the class ProxyFactoryBeanTests method testIsDynamicProxyWhenInterfaceSpecified.
@Test
public void testIsDynamicProxyWhenInterfaceSpecified() {
ITestBean test1 = (ITestBean) factory.getBean("test1");
assertTrue("test1 is a dynamic proxy", Proxy.isProxyClass(test1.getClass()));
}
use of org.springframework.tests.sample.beans.ITestBean in project spring-framework by spring-projects.
the class ProxyFactoryBeanTests method testIsDynamicProxyWhenAutodetectingInterfacesForPrototype.
@Test
public void testIsDynamicProxyWhenAutodetectingInterfacesForPrototype() {
ITestBean test1 = (ITestBean) factory.getBean("test4");
assertTrue("test4 is a dynamic proxy", Proxy.isProxyClass(test1.getClass()));
}
use of org.springframework.tests.sample.beans.ITestBean in project spring-framework by spring-projects.
the class UnsupportedInterceptor method testMultipleProxies.
@Test
public void testMultipleProxies() {
TestBean target = new TestBean();
target.setAge(20);
TestBean target2 = new TestBean();
target2.setAge(21);
ITestBean proxy1 = getAdvisedProxy(target);
ITestBean proxy2 = getAdvisedProxy(target2);
assertSame(proxy1.getClass(), proxy2.getClass());
assertEquals(target.getAge(), proxy1.getAge());
assertEquals(target2.getAge(), proxy2.getAge());
}
use of org.springframework.tests.sample.beans.ITestBean in project spring-framework by spring-projects.
the class UnsupportedInterceptor method testProxyAProxyWithAdditionalInterface.
@Test
public void testProxyAProxyWithAdditionalInterface() {
ITestBean target = new TestBean();
mockTargetSource.setTarget(target);
AdvisedSupport as = new AdvisedSupport();
as.setTargetSource(mockTargetSource);
as.addAdvice(new NopInterceptor());
as.addInterface(Serializable.class);
CglibAopProxy cglib = new CglibAopProxy(as);
ITestBean proxy1 = (ITestBean) cglib.getProxy();
mockTargetSource.setTarget(proxy1);
as = new AdvisedSupport(new Class<?>[] {});
as.setTargetSource(mockTargetSource);
as.addAdvice(new NopInterceptor());
cglib = new CglibAopProxy(as);
ITestBean proxy2 = (ITestBean) cglib.getProxy();
assertTrue(proxy2 instanceof Serializable);
}
Aggregations