Search in sources :

Example 6 with Advisor

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

the class AspectJPrecedenceComparatorTests method testLowerAdvisorPrecedenceAfterAdvice.

@Test
public void testLowerAdvisorPrecedenceAfterAdvice() {
    Advisor advisor1 = createAspectJAfterAdvice(LOW_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someAspect");
    Advisor advisor2 = createAspectJAroundAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someOtherAspect");
    assertThat(this.comparator.compare(advisor1, advisor2)).as("advisor1 sorted after advisor2").isEqualTo(1);
    advisor1 = createSpringAOPAfterAdvice(LOW_PRECEDENCE_ADVISOR_ORDER);
    advisor2 = createAspectJAfterThrowingAdvice(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 7 with Advisor

use of cn.taketoday.aop.Advisor in project today-infrastructure 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 8 with Advisor

use of cn.taketoday.aop.Advisor 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 9 with Advisor

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

the class AspectJPrecedenceComparatorTests method testSameAspectNoAfterAdvice.

@Test
public void testSameAspectNoAfterAdvice() {
    Advisor advisor1 = createAspectJBeforeAdvice(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 sorted before advisor2").isEqualTo(-1);
    advisor1 = createAspectJBeforeAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someAspect");
    advisor2 = createAspectJAroundAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someAspect");
    assertThat(this.comparator.compare(advisor1, advisor2)).as("advisor2 sorted before 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 10 with Advisor

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

the class EnableAsyncTests method customAsyncAnnotationIsPropagated.

@Test
public void customAsyncAnnotationIsPropagated() {
    AnnotationConfigApplicationContext ctx = new AnnotationConfigApplicationContext();
    ctx.register(CustomAsyncAnnotationConfig.class, CustomAsyncBean.class);
    ctx.refresh();
    Object bean = ctx.getBean(CustomAsyncBean.class);
    assertThat(AopUtils.isAopProxy(bean)).isTrue();
    boolean isAsyncAdvised = false;
    for (Advisor advisor : ((Advised) bean).getAdvisors()) {
        if (advisor instanceof AsyncAnnotationAdvisor) {
            isAsyncAdvised = true;
            break;
        }
    }
    assertThat(isAsyncAdvised).as("bean was not async advised as expected").isTrue();
    ctx.close();
}
Also used : AnnotationConfigApplicationContext(cn.taketoday.context.annotation.AnnotationConfigApplicationContext) Advised(cn.taketoday.aop.framework.Advised) Advisor(cn.taketoday.aop.Advisor) 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