Search in sources :

Example 26 with Advisor

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

the class AspectJPrecedenceComparatorTests method testSameAspectOneOfEach.

@Test
public void testSameAspectOneOfEach() {
    Advisor advisor1 = createAspectJAfterAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someAspect");
    Advisor advisor2 = createAspectJBeforeAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someAspect");
    assertThat(this.comparator.compare(advisor1, advisor2)).as("advisor1 and advisor2 not comparable").isEqualTo(1);
}
Also used : Advisor(cn.taketoday.aop.Advisor) DefaultPointcutAdvisor(cn.taketoday.aop.support.DefaultPointcutAdvisor) AspectJPointcutAdvisor(cn.taketoday.aop.aspectj.AspectJPointcutAdvisor) Test(org.junit.jupiter.api.Test)

Example 27 with Advisor

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

the class AspectJPrecedenceComparatorTests method testHigherAdvisorPrecedenceAfterAdvice.

@Test
public void testHigherAdvisorPrecedenceAfterAdvice() {
    Advisor advisor1 = createAspectJAfterAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someAspect");
    Advisor advisor2 = createAspectJAroundAdvice(LOW_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someOtherAspect");
    assertThat(this.comparator.compare(advisor1, advisor2)).as("advisor1 sorted before advisor2").isEqualTo(-1);
    advisor1 = createAspectJAfterReturningAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someAspect");
    advisor2 = createAspectJAfterThrowingAdvice(LOW_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someOtherAspect");
    assertThat(this.comparator.compare(advisor1, advisor2)).as("advisor2 sorted after advisor1").isEqualTo(-1);
}
Also used : Advisor(cn.taketoday.aop.Advisor) DefaultPointcutAdvisor(cn.taketoday.aop.support.DefaultPointcutAdvisor) AspectJPointcutAdvisor(cn.taketoday.aop.aspectj.AspectJPointcutAdvisor) Test(org.junit.jupiter.api.Test)

Example 28 with Advisor

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

the class AspectJPrecedenceComparatorTests method testLowerAdvisorPrecedenceNoAfterAdvice.

@Test
public void testLowerAdvisorPrecedenceNoAfterAdvice() {
    Advisor advisor1 = createAspectJBeforeAdvice(LOW_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someAspect");
    Advisor advisor2 = createAspectJBeforeAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someOtherAspect");
    assertThat(this.comparator.compare(advisor1, advisor2)).as("advisor1 sorted after advisor2").isEqualTo(1);
    advisor1 = createAspectJBeforeAdvice(LOW_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someAspect");
    advisor2 = createAspectJAroundAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someOtherAspect");
    assertThat(this.comparator.compare(advisor1, advisor2)).as("advisor1 sorted after advisor2").isEqualTo(1);
}
Also used : Advisor(cn.taketoday.aop.Advisor) DefaultPointcutAdvisor(cn.taketoday.aop.support.DefaultPointcutAdvisor) AspectJPointcutAdvisor(cn.taketoday.aop.aspectj.AspectJPointcutAdvisor) Test(org.junit.jupiter.api.Test)

Example 29 with Advisor

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

the class ProxyFactoryTests method testIndexOfMethods.

@Test
public void testIndexOfMethods() {
    TestBean target = new TestBean();
    ProxyFactory pf = new ProxyFactory(target);
    NopInterceptor nop = new NopInterceptor();
    Advisor advisor = new DefaultPointcutAdvisor(new CountingBeforeAdvice());
    Advised advised = (Advised) pf.getProxy();
    // Can use advised and ProxyFactory interchangeably
    advised.addAdvice(nop);
    pf.addAdvisor(advisor);
    assertThat(pf.indexOf(new NopInterceptor())).isEqualTo(-1);
    assertThat(pf.indexOf(nop)).isEqualTo(0);
    assertThat(pf.indexOf(advisor)).isEqualTo(1);
    assertThat(advised.indexOf(new DefaultPointcutAdvisor(null))).isEqualTo(-1);
}
Also used : NopInterceptor(cn.taketoday.aop.testfixture.interceptor.NopInterceptor) ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) TestBean(cn.taketoday.beans.testfixture.beans.TestBean) Advisor(cn.taketoday.aop.Advisor) DefaultPointcutAdvisor(cn.taketoday.aop.support.DefaultPointcutAdvisor) DefaultIntroductionAdvisor(cn.taketoday.aop.support.DefaultIntroductionAdvisor) DefaultPointcutAdvisor(cn.taketoday.aop.support.DefaultPointcutAdvisor) CountingBeforeAdvice(cn.taketoday.aop.testfixture.advice.CountingBeforeAdvice) Test(org.junit.jupiter.api.Test)

Example 30 with Advisor

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

the class ProxyFactoryTests method testRemoveAdvisorByIndex.

@Test
public void testRemoveAdvisorByIndex() {
    TestBean target = new TestBean();
    ProxyFactory pf = new ProxyFactory(target);
    NopInterceptor nop = new NopInterceptor();
    CountingBeforeAdvice cba = new CountingBeforeAdvice();
    Advisor advisor = new DefaultPointcutAdvisor(cba);
    pf.addAdvice(nop);
    pf.addAdvisor(advisor);
    NopInterceptor nop2 = new NopInterceptor();
    pf.addAdvice(nop2);
    ITestBean proxied = (ITestBean) pf.getProxy();
    proxied.setAge(5);
    assertThat(cba.getCalls()).isEqualTo(1);
    assertThat(nop.getCount()).isEqualTo(1);
    assertThat(nop2.getCount()).isEqualTo(1);
    // Removes counting before advisor
    pf.removeAdvisor(1);
    assertThat(proxied.getAge()).isEqualTo(5);
    assertThat(cba.getCalls()).isEqualTo(1);
    assertThat(nop.getCount()).isEqualTo(2);
    assertThat(nop2.getCount()).isEqualTo(2);
    // Removes Nop1
    pf.removeAdvisor(0);
    assertThat(proxied.getAge()).isEqualTo(5);
    assertThat(cba.getCalls()).isEqualTo(1);
    assertThat(nop.getCount()).isEqualTo(2);
    assertThat(nop2.getCount()).isEqualTo(3);
    // Check out of bounds
    try {
        pf.removeAdvisor(-1);
    } catch (AopConfigException ex) {
    // Ok
    }
    try {
        pf.removeAdvisor(2);
    } catch (AopConfigException ex) {
    // Ok
    }
    assertThat(proxied.getAge()).isEqualTo(5);
    assertThat(nop2.getCount()).isEqualTo(4);
}
Also used : ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) NopInterceptor(cn.taketoday.aop.testfixture.interceptor.NopInterceptor) ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) TestBean(cn.taketoday.beans.testfixture.beans.TestBean) Advisor(cn.taketoday.aop.Advisor) DefaultPointcutAdvisor(cn.taketoday.aop.support.DefaultPointcutAdvisor) DefaultIntroductionAdvisor(cn.taketoday.aop.support.DefaultIntroductionAdvisor) DefaultPointcutAdvisor(cn.taketoday.aop.support.DefaultPointcutAdvisor) CountingBeforeAdvice(cn.taketoday.aop.testfixture.advice.CountingBeforeAdvice) Test(org.junit.jupiter.api.Test)

Aggregations

Advisor (cn.taketoday.aop.Advisor)76 Test (org.junit.jupiter.api.Test)70 DefaultPointcutAdvisor (cn.taketoday.aop.support.DefaultPointcutAdvisor)52 ITestBean (cn.taketoday.beans.testfixture.beans.ITestBean)43 TestBean (cn.taketoday.beans.testfixture.beans.TestBean)41 DefaultIntroductionAdvisor (cn.taketoday.aop.support.DefaultIntroductionAdvisor)32 NopInterceptor (cn.taketoday.aop.testfixture.interceptor.NopInterceptor)22 AspectJPointcutAdvisor (cn.taketoday.aop.aspectj.AspectJPointcutAdvisor)21 StaticMethodMatcherPointcutAdvisor (cn.taketoday.aop.support.StaticMethodMatcherPointcutAdvisor)20 CountingBeforeAdvice (cn.taketoday.aop.testfixture.advice.CountingBeforeAdvice)16 Method (java.lang.reflect.Method)16 SerializableNopInterceptor (cn.taketoday.aop.testfixture.interceptor.SerializableNopInterceptor)14 LockMixinAdvisor (test.mixin.LockMixinAdvisor)14 Advised (cn.taketoday.aop.framework.Advised)13 NopInterceptor (cn.taketoday.aop.NopInterceptor)10 ProxyFactory (cn.taketoday.aop.framework.ProxyFactory)10 Nullable (cn.taketoday.lang.Nullable)10 NameMatchMethodPointcut (cn.taketoday.aop.support.NameMatchMethodPointcut)8 JoinPoint (org.aspectj.lang.JoinPoint)8 ProceedingJoinPoint (org.aspectj.lang.ProceedingJoinPoint)8