Search in sources :

Example 31 with AdvisedSupport

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

Example 32 with AdvisedSupport

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

the class AopProxyUtilsTests method testCompleteProxiedInterfacesAdvisedIncluded.

@Test
public void testCompleteProxiedInterfacesAdvisedIncluded() {
    AdvisedSupport as = new AdvisedSupport();
    as.addInterface(ITestBean.class);
    as.addInterface(Comparable.class);
    as.addInterface(Advised.class);
    Class<?>[] completedInterfaces = AopProxyUtils.completeProxiedInterfaces(as);
    assertThat(completedInterfaces.length).isEqualTo(4);
    // Can't assume ordering for others, so use a list
    List<?> l = Arrays.asList(completedInterfaces);
    assertThat(l.contains(Advised.class)).isTrue();
    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)

Example 33 with AdvisedSupport

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

the class AopProxyUtilsTests method testCompleteProxiedInterfacesWorksWithNullOpaque.

@Test
public void testCompleteProxiedInterfacesWorksWithNullOpaque() {
    AdvisedSupport as = new AdvisedSupport();
    as.setOpaque(true);
    Class<?>[] completedInterfaces = AopProxyUtils.completeProxiedInterfaces(as);
    assertThat(completedInterfaces.length).isEqualTo(1);
}
Also used : AdvisedSupport(cn.taketoday.aop.framework.AdvisedSupport) Test(org.junit.jupiter.api.Test)

Example 34 with AdvisedSupport

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

the class NoneProxyMethodGenerator method generate.

@Override
public boolean generate(Method method, GeneratorContext context) {
    final AdvisedSupport config = context.getConfig();
    final MethodInterceptor[] interceptors = context.getConfig().getInterceptors(method, context.getTargetClass());
    if (ObjectUtils.isEmpty(interceptors)) {
        final TargetSource targetSource = config.getTargetSource();
        if (targetSource.isStatic()) {
            invokeStaticTarget(method, context);
        } else {
            invokeTargetFromTargetSource(method, context);
        }
        return true;
    }
    return false;
}
Also used : TargetSource(cn.taketoday.aop.TargetSource) MethodInterceptor(org.aopalliance.intercept.MethodInterceptor) AdvisedSupport(cn.taketoday.aop.framework.AdvisedSupport)

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