Search in sources :

Example 11 with AdvisedSupport

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

Example 12 with AdvisedSupport

use of cn.taketoday.aop.framework.AdvisedSupport 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 13 with AdvisedSupport

use of cn.taketoday.aop.framework.AdvisedSupport in project today-framework by TAKETODAY.

the class JdkDynamicAopProxyTests method testInterceptorIsInvokedWithNoTarget.

@Test
public void testInterceptorIsInvokedWithNoTarget() {
    // Test return value
    final int age = 25;
    MethodInterceptor mi = (invocation -> age);
    AdvisedSupport pc = new AdvisedSupport(ITestBean.class);
    pc.addAdvice(mi);
    AopProxy aop = createAopProxy(pc);
    ITestBean tb = (ITestBean) aop.getProxy();
    assertThat(tb.getAge()).as("correct return value").isEqualTo(age);
}
Also used : ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) MethodInterceptor(org.aopalliance.intercept.MethodInterceptor) AopProxy(cn.taketoday.aop.framework.AopProxy) JdkDynamicAopProxy(cn.taketoday.aop.framework.JdkDynamicAopProxy) AdvisedSupport(cn.taketoday.aop.framework.AdvisedSupport) Test(org.junit.jupiter.api.Test)

Example 14 with AdvisedSupport

use of cn.taketoday.aop.framework.AdvisedSupport in project today-framework by TAKETODAY.

the class JdkDynamicAopProxyTests method testProxyIsJustInterface.

@Test
public void testProxyIsJustInterface() {
    TestBean raw = new TestBean();
    raw.setAge(32);
    AdvisedSupport pc = new AdvisedSupport(ITestBean.class);
    pc.setTarget(raw);
    JdkDynamicAopProxy aop = new JdkDynamicAopProxy(pc);
    Object proxy = aop.getProxy();
    boolean condition = proxy instanceof ITestBean;
    assertThat(condition).isTrue();
    boolean condition1 = proxy instanceof TestBean;
    assertThat(condition1).isFalse();
}
Also used : ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) JdkDynamicAopProxy(cn.taketoday.aop.framework.JdkDynamicAopProxy) 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 15 with AdvisedSupport

use of cn.taketoday.aop.framework.AdvisedSupport in project today-framework by TAKETODAY.

the class AopProxyUtilsTests method testCompleteProxiedInterfacesAdvisedNotIncludedOpaque.

@Test
public void testCompleteProxiedInterfacesAdvisedNotIncludedOpaque() {
    AdvisedSupport as = new AdvisedSupport();
    as.setOpaque(true);
    as.addInterface(ITestBean.class);
    as.addInterface(Comparable.class);
    Class<?>[] completedInterfaces = AopProxyUtils.completeProxiedInterfaces(as);
    assertThat(completedInterfaces.length).isEqualTo(3);
    // Can't assume ordering for others, so use a list
    List<?> l = Arrays.asList(completedInterfaces);
    assertThat(l.contains(Advised.class)).isFalse();
    assertThat(l.contains(ITestBean.class)).isTrue();
    assertThat(l.contains(Comparable.class)).isTrue();
}
Also used : AdvisedSupport(cn.taketoday.aop.framework.AdvisedSupport) Test(org.junit.jupiter.api.Test)

Aggregations

AdvisedSupport (cn.taketoday.aop.framework.AdvisedSupport)34 Test (org.junit.jupiter.api.Test)27 AopProxy (cn.taketoday.aop.framework.AopProxy)17 ITestBean (cn.taketoday.beans.testfixture.beans.ITestBean)12 CglibAopProxy (cn.taketoday.aop.framework.CglibAopProxy)11 TestBean (cn.taketoday.beans.testfixture.beans.TestBean)9 MethodInterceptor (org.aopalliance.intercept.MethodInterceptor)9 NopInterceptor (cn.taketoday.aop.NopInterceptor)8 MethodInvocation (org.aopalliance.intercept.MethodInvocation)7 AopConfigException (cn.taketoday.aop.framework.AopConfigException)5 JdkDynamicAopProxy (cn.taketoday.aop.framework.JdkDynamicAopProxy)4 TargetSource (cn.taketoday.aop.TargetSource)3 Assertions.assertThatIllegalArgumentException (org.assertj.core.api.Assertions.assertThatIllegalArgumentException)3 LockedException (cn.taketoday.aop.mixin.LockedException)2 FileNotFoundException (java.io.FileNotFoundException)2 IOException (java.io.IOException)2 UndeclaredThrowableException (java.lang.reflect.UndeclaredThrowableException)2 MarshalException (java.rmi.MarshalException)2 SQLException (java.sql.SQLException)2 Assertions.assertThatIllegalStateException (org.assertj.core.api.Assertions.assertThatIllegalStateException)2