use of test.mixin.LockedException in project spring-framework by spring-projects.
the class AbstractAopProxyTests method testTestBeanIntroduction.
private void testTestBeanIntroduction(ProxyFactory pc) {
int newAge = 65;
ITestBean itb = (ITestBean) createProxy(pc);
itb.setAge(newAge);
assertEquals(newAge, itb.getAge());
Lockable lockable = (Lockable) itb;
assertFalse(lockable.locked());
lockable.lock();
assertEquals(newAge, itb.getAge());
try {
itb.setAge(1);
fail("Setters should fail when locked");
} catch (LockedException ex) {
// ok
}
assertEquals(newAge, itb.getAge());
// Unlock
assertTrue(lockable.locked());
lockable.unlock();
itb.setAge(1);
assertEquals(1, itb.getAge());
}
use of test.mixin.LockedException in project spring-framework by spring-projects.
the class ProxyFactoryBeanTests method testPrototypeAdvisor.
@Test
public void testPrototypeAdvisor() {
DefaultListableBeanFactory bf = new DefaultListableBeanFactory();
new XmlBeanDefinitionReader(bf).loadBeanDefinitions(new ClassPathResource(CONTEXT, CLASS));
ITestBean bean1 = (ITestBean) bf.getBean("prototypeTestBeanProxy");
ITestBean bean2 = (ITestBean) bf.getBean("prototypeTestBeanProxy");
bean1.setAge(3);
bean2.setAge(4);
assertEquals(3, bean1.getAge());
assertEquals(4, bean2.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 test.mixin.LockedException 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 test.mixin.LockedException in project spring-framework by spring-projects.
the class CreatesTestBean method testJdkIntroductionAppliesToCreatedObjectsNotFactoryBean.
@Test
public void testJdkIntroductionAppliesToCreatedObjectsNotFactoryBean() {
ITestBean tb = (ITestBean) beanFactory.getBean("factory-introductionUsingJdk");
NopInterceptor nop = (NopInterceptor) beanFactory.getBean("introductionNopInterceptor");
assertEquals("NOP should not have done any work yet", 0, nop.getCount());
assertTrue(AopUtils.isJdkDynamicProxy(tb));
int age = 5;
tb.setAge(age);
assertEquals(age, tb.getAge());
assertTrue("Introduction was made", tb instanceof TimeStamped);
assertEquals(0, ((TimeStamped) tb).getTimeStamp());
assertEquals(3, nop.getCount());
ITestBean tb2 = (ITestBean) beanFactory.getBean("second-introductionUsingJdk");
// Check two per-instance mixins were distinct
Lockable lockable1 = (Lockable) tb;
Lockable lockable2 = (Lockable) tb2;
assertFalse(lockable1.locked());
assertFalse(lockable2.locked());
tb.setAge(65);
assertEquals(65, tb.getAge());
lockable1.lock();
assertTrue(lockable1.locked());
// Shouldn't affect second
assertFalse(lockable2.locked());
// Can still mod second object
tb2.setAge(12);
// But can't mod first
try {
tb.setAge(6);
fail("Mixin should have locked this object");
} catch (LockedException ex) {
// Ok
}
}
use of test.mixin.LockedException in project spring-framework by spring-projects.
the class CreatesTestBean method testJdkIntroduction.
@Test
public void testJdkIntroduction() {
ITestBean tb = (ITestBean) beanFactory.getBean("introductionUsingJdk");
NopInterceptor nop = (NopInterceptor) beanFactory.getBean("introductionNopInterceptor");
assertEquals(0, nop.getCount());
assertTrue(AopUtils.isJdkDynamicProxy(tb));
int age = 5;
tb.setAge(age);
assertEquals(age, tb.getAge());
assertTrue("Introduction was made", tb instanceof TimeStamped);
assertEquals(0, ((TimeStamped) tb).getTimeStamp());
assertEquals(3, nop.getCount());
assertEquals("introductionUsingJdk", tb.getName());
ITestBean tb2 = (ITestBean) beanFactory.getBean("second-introductionUsingJdk");
// Check two per-instance mixins were distinct
Lockable lockable1 = (Lockable) tb;
Lockable lockable2 = (Lockable) tb2;
assertFalse(lockable1.locked());
assertFalse(lockable2.locked());
tb.setAge(65);
assertEquals(65, tb.getAge());
lockable1.lock();
assertTrue(lockable1.locked());
// Shouldn't affect second
assertFalse(lockable2.locked());
// Can still mod second object
tb2.setAge(12);
// But can't mod first
try {
tb.setAge(6);
fail("Mixin should have locked this object");
} catch (LockedException ex) {
// Ok
}
}
Aggregations