use of test.mixin.Lockable 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
}
}
use of test.mixin.Lockable in project spring-framework by spring-projects.
the class SelectivePrototypeTargetSourceCreator method testCommonInterceptorAndAdvisor.
/**
* Check that we can provide a common interceptor that will
* appear in the chain before "specific" interceptors,
* which are sourced from matching advisors
*/
@Test
public void testCommonInterceptorAndAdvisor() throws Exception {
BeanFactory bf = new ClassPathXmlApplicationContext(COMMON_INTERCEPTORS_CONTEXT, CLASS);
ITestBean test1 = (ITestBean) bf.getBean("test1");
assertTrue(AopUtils.isAopProxy(test1));
Lockable lockable1 = (Lockable) test1;
NopInterceptor nop1 = (NopInterceptor) bf.getBean("nopInterceptor");
NopInterceptor nop2 = (NopInterceptor) bf.getBean("pointcutAdvisor", Advisor.class).getAdvice();
ITestBean test2 = (ITestBean) bf.getBean("test2");
Lockable lockable2 = (Lockable) test2;
// Locking should be independent; nop is shared
assertFalse(lockable1.locked());
assertFalse(lockable2.locked());
// equals 2 calls on shared nop, because it's first and sees calls
// against the Lockable interface introduced by the specific advisor
assertEquals(2, nop1.getCount());
assertEquals(0, nop2.getCount());
lockable1.lock();
assertTrue(lockable1.locked());
assertFalse(lockable2.locked());
assertEquals(5, nop1.getCount());
assertEquals(0, nop2.getCount());
PackageVisibleMethod packageVisibleMethod = (PackageVisibleMethod) bf.getBean("packageVisibleMethod");
assertEquals(5, nop1.getCount());
assertEquals(0, nop2.getCount());
packageVisibleMethod.doSomething();
assertEquals(6, nop1.getCount());
assertEquals(1, nop2.getCount());
assertTrue(packageVisibleMethod instanceof Lockable);
Lockable lockable3 = (Lockable) packageVisibleMethod;
lockable3.lock();
assertTrue(lockable3.locked());
lockable3.unlock();
assertFalse(lockable3.locked());
}
Aggregations