use of org.springframework.tests.aop.interceptor.NopInterceptor in project spring-framework by spring-projects.
the class UnsupportedInterceptor method testPackageMethodInvocation.
@Test
public void testPackageMethodInvocation() {
PackageMethodTestBean bean = new PackageMethodTestBean();
bean.value = "foo";
mockTargetSource.setTarget(bean);
AdvisedSupport as = new AdvisedSupport();
as.setTargetSource(mockTargetSource);
as.addAdvice(new NopInterceptor());
AopProxy aop = new CglibAopProxy(as);
PackageMethodTestBean proxy = (PackageMethodTestBean) aop.getProxy();
assertTrue(AopUtils.isCglibProxy(proxy));
assertEquals(proxy.getClass().getClassLoader(), bean.getClass().getClassLoader());
assertEquals("foo", proxy.getString());
}
use of org.springframework.tests.aop.interceptor.NopInterceptor 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);
}
use of org.springframework.tests.aop.interceptor.NopInterceptor in project spring-framework by spring-projects.
the class UnsupportedInterceptor method testExceptionHandling.
@Test
public void testExceptionHandling() {
ExceptionThrower bean = new ExceptionThrower();
mockTargetSource.setTarget(bean);
AdvisedSupport as = new AdvisedSupport();
as.setTargetSource(mockTargetSource);
as.addAdvice(new NopInterceptor());
AopProxy aop = new CglibAopProxy(as);
ExceptionThrower proxy = (ExceptionThrower) aop.getProxy();
try {
proxy.doTest();
} catch (Exception ex) {
assertTrue("Invalid exception class", ex instanceof ApplicationContextException);
}
assertTrue("Catch was not invoked", proxy.isCatchInvoked());
assertTrue("Finally was not invoked", proxy.isFinallyInvoked());
}
use of org.springframework.tests.aop.interceptor.NopInterceptor in project spring-framework by spring-projects.
the class CreatesTestBean method jdkAssertions.
private void jdkAssertions(ITestBean tb, int nopInterceptorCount) {
NopInterceptor nop = (NopInterceptor) beanFactory.getBean("nopInterceptor");
assertEquals(0, nop.getCount());
assertTrue(AopUtils.isJdkDynamicProxy(tb));
int age = 5;
tb.setAge(age);
assertEquals(age, tb.getAge());
assertEquals(2 * nopInterceptorCount, nop.getCount());
}
use of org.springframework.tests.aop.interceptor.NopInterceptor 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
}
}
Aggregations