use of cn.taketoday.aop.framework.CglibAopProxy in project today-framework by TAKETODAY.
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();
assertThat(AopUtils.isCglibProxy(proxy)).isTrue();
assertThat(bean.getClass().getClassLoader()).isEqualTo(proxy.getClass().getClassLoader());
assertThat(proxy.getString()).isEqualTo("foo");
}
use of cn.taketoday.aop.framework.CglibAopProxy in project today-framework by TAKETODAY.
the class UnsupportedInterceptor method testProtectedMethodInvocation.
@Test
public void testProtectedMethodInvocation() {
ProtectedMethodTestBean bean = new ProtectedMethodTestBean();
bean.value = "foo";
mockTargetSource.setTarget(bean);
AdvisedSupport as = new AdvisedSupport();
as.setTargetSource(mockTargetSource);
as.addAdvice(new NopInterceptor());
AopProxy aop = new CglibAopProxy(as);
ProtectedMethodTestBean proxy = (ProtectedMethodTestBean) aop.getProxy();
assertThat(AopUtils.isCglibProxy(proxy)).isTrue();
assertThat(bean.getClass().getClassLoader()).isEqualTo(proxy.getClass().getClassLoader());
assertThat(proxy.getString()).isEqualTo("foo");
}
use of cn.taketoday.aop.framework.CglibAopProxy in project today-framework by TAKETODAY.
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) {
assertThat(ex instanceof ApplicationContextException).as("Invalid exception class").isTrue();
}
assertThat(proxy.isCatchInvoked()).as("Catch was not invoked").isTrue();
assertThat(proxy.isFinallyInvoked()).as("Finally was not invoked").isTrue();
}
use of cn.taketoday.aop.framework.CglibAopProxy in project today-framework by TAKETODAY.
the class UnsupportedInterceptor method testMethodInvocationDuringConstructor.
@Test
public void testMethodInvocationDuringConstructor() {
CglibTestBean bean = new CglibTestBean();
bean.setName("Rob Harrop");
AdvisedSupport as = new AdvisedSupport();
as.setTarget(bean);
as.addAdvice(new NopInterceptor());
AopProxy aop = new CglibAopProxy(as);
CglibTestBean proxy = (CglibTestBean) aop.getProxy();
assertThat(proxy.getName()).as("The name property has been overwritten by the constructor").isEqualTo("Rob Harrop");
}
use of cn.taketoday.aop.framework.CglibAopProxy in project today-framework by TAKETODAY.
the class UnsupportedInterceptor method testWithNoArgConstructor.
@Test
public void testWithNoArgConstructor() {
NoArgCtorTestBean target = new NoArgCtorTestBean("b", 1);
target.reset();
mockTargetSource.setTarget(target);
AdvisedSupport pc = new AdvisedSupport();
pc.setTargetSource(mockTargetSource);
CglibAopProxy aop = new CglibAopProxy(pc);
aop.setConstructorArguments(new Object[] { "Rob Harrop", 22 }, new Class<?>[] { String.class, int.class });
NoArgCtorTestBean proxy = (NoArgCtorTestBean) aop.getProxy();
assertThat(proxy).isNotNull();
boolean called = proxy.called;
assertThat(called).isTrue();
}
Aggregations