use of cn.taketoday.aop.framework.CglibAopProxy in project today-framework by TAKETODAY.
the class UnsupportedInterceptor method testProxyCanBeClassNotInterface.
@Test
public void testProxyCanBeClassNotInterface() {
TestBean raw = new TestBean();
raw.setAge(32);
mockTargetSource.setTarget(raw);
AdvisedSupport pc = new AdvisedSupport();
pc.setTargetSource(mockTargetSource);
AopProxy aop = new CglibAopProxy(pc);
Object proxy = aop.getProxy();
assertThat(AopUtils.isCglibProxy(proxy)).isTrue();
assertThat(proxy instanceof ITestBean).isTrue();
assertThat(proxy instanceof TestBean).isTrue();
TestBean tb = (TestBean) proxy;
assertThat(tb.getAge()).isEqualTo(32);
}
use of cn.taketoday.aop.framework.CglibAopProxy in project today-framework by TAKETODAY.
the class UnsupportedInterceptor method testUnadvisedProxyCreationWithCallDuringConstructor.
@Test
public void testUnadvisedProxyCreationWithCallDuringConstructor() {
CglibTestBean target = new CglibTestBean();
target.setName("Rob Harrop");
AdvisedSupport pc = new AdvisedSupport();
pc.setFrozen(true);
pc.setTarget(target);
CglibAopProxy aop = new CglibAopProxy(pc);
CglibTestBean proxy = (CglibTestBean) aop.getProxy();
assertThat(proxy).as("Proxy should not be null").isNotNull();
assertThat(proxy.getName()).as("Constructor overrode the value of name").isEqualTo("Rob Harrop");
}
use of cn.taketoday.aop.framework.CglibAopProxy in project today-framework by TAKETODAY.
the class UnsupportedInterceptor method testToStringInvocation.
@Test
public void testToStringInvocation() {
PrivateCglibTestBean bean = new PrivateCglibTestBean();
bean.setName("Rob Harrop");
AdvisedSupport as = new AdvisedSupport();
as.setTarget(bean);
as.addAdvice(new NopInterceptor());
AopProxy aop = new CglibAopProxy(as);
PrivateCglibTestBean proxy = (PrivateCglibTestBean) aop.getProxy();
assertThat(proxy.toString()).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 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();
assertThat(proxy2 instanceof Serializable).isTrue();
}
use of cn.taketoday.aop.framework.CglibAopProxy in project today-framework by TAKETODAY.
the class UnsupportedInterceptor method testProxyAProxy.
@Test
public void testProxyAProxy() {
ITestBean target = new TestBean();
mockTargetSource.setTarget(target);
AdvisedSupport as = new AdvisedSupport();
as.setTargetSource(mockTargetSource);
as.addAdvice(new NopInterceptor());
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);
assertThat(cglib.getProxy()).isInstanceOf(ITestBean.class);
}
Aggregations