Search in sources :

Example 1 with DefaultPointcutAdvisor

use of cn.taketoday.aop.support.DefaultPointcutAdvisor in project today-infrastructure by TAKETODAY.

the class AbstractAopProxyTests method testCannotAddAdvisorWhenFrozenUsingCast.

/**
 * Check that casting to Advised can't get around advice freeze.
 */
@Test
public void testCannotAddAdvisorWhenFrozenUsingCast() throws Throwable {
    TestBean target = new TestBean();
    target.setAge(21);
    ProxyFactory pc = new ProxyFactory(target);
    assertThat(pc.isFrozen()).isFalse();
    pc.addAdvice(new NopInterceptor());
    ITestBean proxied = (ITestBean) createProxy(pc);
    pc.setFrozen(true);
    Advised advised = (Advised) proxied;
    assertThat(pc.isFrozen()).isTrue();
    assertThatExceptionOfType(AopConfigException.class).as("Shouldn't be able to add Advisor when frozen").isThrownBy(() -> advised.addAdvisor(new DefaultPointcutAdvisor(new NopInterceptor()))).withMessageContaining("frozen");
    // Check it still works: proxy factory state shouldn't have been corrupted
    assertThat(proxied.getAge()).isEqualTo(target.getAge());
    assertThat(advised.getAdvisors().length).isEqualTo(1);
}
Also used : ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) NopInterceptor(cn.taketoday.aop.testfixture.interceptor.NopInterceptor) SerializableNopInterceptor(cn.taketoday.aop.testfixture.interceptor.SerializableNopInterceptor) ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) TestBean(cn.taketoday.beans.testfixture.beans.TestBean) DefaultPointcutAdvisor(cn.taketoday.aop.support.DefaultPointcutAdvisor) Test(org.junit.jupiter.api.Test)

Example 2 with DefaultPointcutAdvisor

use of cn.taketoday.aop.support.DefaultPointcutAdvisor in project today-infrastructure by TAKETODAY.

the class AspectJPrecedenceComparatorTests method createSpringAOPAfterAdvice.

private Advisor createSpringAOPAfterAdvice(int order) {
    AfterReturningAdvice advice = (returnValue, method) -> {
    };
    DefaultPointcutAdvisor advisor = new DefaultPointcutAdvisor(this.anyOldPointcut, advice);
    advisor.setOrder(order);
    return advisor;
}
Also used : BeforeEach(org.junit.jupiter.api.BeforeEach) AspectJAfterAdvice(cn.taketoday.aop.aspectj.AspectJAfterAdvice) Advisor(cn.taketoday.aop.Advisor) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) AspectJAroundAdvice(cn.taketoday.aop.aspectj.AspectJAroundAdvice) Test(org.junit.jupiter.api.Test) AspectJAfterThrowingAdvice(cn.taketoday.aop.aspectj.AspectJAfterThrowingAdvice) AspectJMethodBeforeAdvice(cn.taketoday.aop.aspectj.AspectJMethodBeforeAdvice) DefaultPointcutAdvisor(cn.taketoday.aop.support.DefaultPointcutAdvisor) AfterReturningAdvice(cn.taketoday.aop.AfterReturningAdvice) BeforeAdvice(cn.taketoday.aop.BeforeAdvice) AbstractAspectJAdvice(cn.taketoday.aop.aspectj.AbstractAspectJAdvice) AspectJPointcutAdvisor(cn.taketoday.aop.aspectj.AspectJPointcutAdvisor) AspectJExpressionPointcut(cn.taketoday.aop.aspectj.AspectJExpressionPointcut) Method(java.lang.reflect.Method) AspectJAfterReturningAdvice(cn.taketoday.aop.aspectj.AspectJAfterReturningAdvice) AfterReturningAdvice(cn.taketoday.aop.AfterReturningAdvice) AspectJAfterReturningAdvice(cn.taketoday.aop.aspectj.AspectJAfterReturningAdvice) DefaultPointcutAdvisor(cn.taketoday.aop.support.DefaultPointcutAdvisor)

Example 3 with DefaultPointcutAdvisor

use of cn.taketoday.aop.support.DefaultPointcutAdvisor in project today-infrastructure by TAKETODAY.

the class AspectJPrecedenceComparatorTests method createSpringAOPBeforeAdvice.

private Advisor createSpringAOPBeforeAdvice(int order) {
    BeforeAdvice advice = new BeforeAdvice() {
    };
    DefaultPointcutAdvisor advisor = new DefaultPointcutAdvisor(this.anyOldPointcut, advice);
    advisor.setOrder(order);
    return advisor;
}
Also used : AspectJMethodBeforeAdvice(cn.taketoday.aop.aspectj.AspectJMethodBeforeAdvice) BeforeAdvice(cn.taketoday.aop.BeforeAdvice) DefaultPointcutAdvisor(cn.taketoday.aop.support.DefaultPointcutAdvisor)

Example 4 with DefaultPointcutAdvisor

use of cn.taketoday.aop.support.DefaultPointcutAdvisor in project today-infrastructure by TAKETODAY.

the class CallCountingInterceptor method getAdvisedProxy.

private TestBean getAdvisedProxy(String pointcutExpression, CallCountingInterceptor interceptor) {
    TestBean target = new TestBean();
    Pointcut pointcut = getPointcut(pointcutExpression);
    DefaultPointcutAdvisor advisor = new DefaultPointcutAdvisor();
    advisor.setAdvice(interceptor);
    advisor.setPointcut(pointcut);
    ProxyFactory pf = new ProxyFactory();
    pf.setTarget(target);
    pf.addAdvisor(advisor);
    return (TestBean) pf.getProxy();
}
Also used : Pointcut(cn.taketoday.aop.Pointcut) TestBean(cn.taketoday.beans.testfixture.beans.TestBean) ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) ProxyFactory(cn.taketoday.aop.framework.ProxyFactory) DefaultPointcutAdvisor(cn.taketoday.aop.support.DefaultPointcutAdvisor)

Example 5 with DefaultPointcutAdvisor

use of cn.taketoday.aop.support.DefaultPointcutAdvisor in project today-infrastructure by TAKETODAY.

the class TrickyAspectJPointcutExpressionTests method testManualProxyJavaWithStaticPointcutAndTwoClassLoaders.

@Test
public void testManualProxyJavaWithStaticPointcutAndTwoClassLoaders() throws Exception {
    LogUserAdvice logAdvice = new LogUserAdvice();
    AspectJExpressionPointcut pointcut = new AspectJExpressionPointcut();
    pointcut.setExpression(String.format("execution(* %s.TestService.*(..))", getClass().getName()));
    // Test with default class loader first...
    testAdvice(new DefaultPointcutAdvisor(pointcut, logAdvice), logAdvice, new TestServiceImpl(), "TestServiceImpl");
    // Then try again with a different class loader on the target...
    SimpleThrowawayClassLoader loader = new SimpleThrowawayClassLoader(TestServiceImpl.class.getClassLoader());
    // Make sure the interface is loaded from the  parent class loader
    loader.excludeClass(TestService.class.getName());
    loader.excludeClass(TestException.class.getName());
    TestService other = (TestService) loader.loadClass(TestServiceImpl.class.getName()).getDeclaredConstructor().newInstance();
    testAdvice(new DefaultPointcutAdvisor(pointcut, logAdvice), logAdvice, other, "TestServiceImpl");
}
Also used : DefaultPointcutAdvisor(cn.taketoday.aop.support.DefaultPointcutAdvisor) Test(org.junit.jupiter.api.Test)

Aggregations

DefaultPointcutAdvisor (cn.taketoday.aop.support.DefaultPointcutAdvisor)73 Test (org.junit.jupiter.api.Test)61 ITestBean (cn.taketoday.beans.testfixture.beans.ITestBean)35 TestBean (cn.taketoday.beans.testfixture.beans.TestBean)32 Advisor (cn.taketoday.aop.Advisor)22 NopInterceptor (cn.taketoday.aop.testfixture.interceptor.NopInterceptor)22 DefaultIntroductionAdvisor (cn.taketoday.aop.support.DefaultIntroductionAdvisor)20 ProxyFactory (cn.taketoday.aop.framework.ProxyFactory)17 DefaultAdvisorAutoProxyCreator (cn.taketoday.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator)16 SimpleTraceInterceptor (cn.taketoday.aop.interceptor.SimpleTraceInterceptor)16 RootBeanDefinition (cn.taketoday.beans.factory.support.RootBeanDefinition)16 CountingBeforeAdvice (cn.taketoday.aop.testfixture.advice.CountingBeforeAdvice)14 SerializableNopInterceptor (cn.taketoday.aop.testfixture.interceptor.SerializableNopInterceptor)14 NopInterceptor (cn.taketoday.aop.NopInterceptor)10 NameMatchMethodPointcut (cn.taketoday.aop.support.NameMatchMethodPointcut)8 StaticMethodMatcherPointcutAdvisor (cn.taketoday.aop.support.StaticMethodMatcherPointcutAdvisor)8 Pointcut (cn.taketoday.aop.Pointcut)7 Advised (cn.taketoday.aop.framework.Advised)7 MethodInterceptor (org.aopalliance.intercept.MethodInterceptor)7 LockMixinAdvisor (test.mixin.LockMixinAdvisor)6