Search in sources :

Example 6 with CglibAopProxy

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);
}
Also used : CglibAopProxy(cn.taketoday.aop.framework.CglibAopProxy) ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) TestBean(cn.taketoday.beans.testfixture.beans.TestBean) ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) CglibAopProxy(cn.taketoday.aop.framework.CglibAopProxy) AopProxy(cn.taketoday.aop.framework.AopProxy) AdvisedSupport(cn.taketoday.aop.framework.AdvisedSupport) Test(org.junit.jupiter.api.Test)

Example 7 with CglibAopProxy

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");
}
Also used : CglibAopProxy(cn.taketoday.aop.framework.CglibAopProxy) AdvisedSupport(cn.taketoday.aop.framework.AdvisedSupport) Test(org.junit.jupiter.api.Test)

Example 8 with CglibAopProxy

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");
}
Also used : CglibAopProxy(cn.taketoday.aop.framework.CglibAopProxy) NopInterceptor(cn.taketoday.aop.NopInterceptor) CglibAopProxy(cn.taketoday.aop.framework.CglibAopProxy) AopProxy(cn.taketoday.aop.framework.AopProxy) AdvisedSupport(cn.taketoday.aop.framework.AdvisedSupport) Test(org.junit.jupiter.api.Test)

Example 9 with CglibAopProxy

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();
}
Also used : ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) CglibAopProxy(cn.taketoday.aop.framework.CglibAopProxy) NopInterceptor(cn.taketoday.aop.NopInterceptor) Serializable(java.io.Serializable) TestBean(cn.taketoday.beans.testfixture.beans.TestBean) ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) AdvisedSupport(cn.taketoday.aop.framework.AdvisedSupport) Test(org.junit.jupiter.api.Test)

Example 10 with CglibAopProxy

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);
}
Also used : ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) CglibAopProxy(cn.taketoday.aop.framework.CglibAopProxy) NopInterceptor(cn.taketoday.aop.NopInterceptor) TestBean(cn.taketoday.beans.testfixture.beans.TestBean) ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) AdvisedSupport(cn.taketoday.aop.framework.AdvisedSupport) Test(org.junit.jupiter.api.Test)

Aggregations

AdvisedSupport (cn.taketoday.aop.framework.AdvisedSupport)10 CglibAopProxy (cn.taketoday.aop.framework.CglibAopProxy)10 Test (org.junit.jupiter.api.Test)10 NopInterceptor (cn.taketoday.aop.NopInterceptor)7 AopProxy (cn.taketoday.aop.framework.AopProxy)6 ITestBean (cn.taketoday.beans.testfixture.beans.ITestBean)3 TestBean (cn.taketoday.beans.testfixture.beans.TestBean)3 AopConfigException (cn.taketoday.aop.framework.AopConfigException)1 ApplicationContextException (cn.taketoday.context.ApplicationContextException)1 Serializable (java.io.Serializable)1 Assertions.assertThatIllegalArgumentException (org.assertj.core.api.Assertions.assertThatIllegalArgumentException)1