Search in sources :

Example 21 with Advisor

use of cn.taketoday.aop.Advisor in project today-framework 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)

Example 22 with Advisor

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

the class PerThisAspect method twoAdvicesOnOneAspect.

@Test
void twoAdvicesOnOneAspect() {
    TestBean target = new TestBean();
    TwoAdviceAspect twoAdviceAspect = new TwoAdviceAspect();
    List<Advisor> advisors = getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(twoAdviceAspect, "someBean"));
    assertThat(advisors.size()).as("Two advice methods found").isEqualTo(2);
    ITestBean itb = (ITestBean) createProxy(target, advisors, ITestBean.class);
    itb.setName("");
    assertThat(itb.getAge()).isEqualTo(0);
    int newAge = 32;
    itb.setAge(newAge);
    assertThat(itb.getAge()).isEqualTo(1);
}
Also used : ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) TestBean(cn.taketoday.beans.testfixture.beans.TestBean) Advisor(cn.taketoday.aop.Advisor) TwoAdviceAspect(test.aop.TwoAdviceAspect) JoinPoint(org.aspectj.lang.JoinPoint) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) Test(org.junit.jupiter.api.Test)

Example 23 with Advisor

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

the class PerThisAspect method multiplePerTargetAspectsWithOrderAnnotation.

@Test
void multiplePerTargetAspectsWithOrderAnnotation() throws Exception {
    TestBean target = new TestBean();
    int realAge = 65;
    target.setAge(realAge);
    List<Advisor> advisors = new ArrayList<>();
    PerTargetAspectWithOrderAnnotation10 aspect1 = new PerTargetAspectWithOrderAnnotation10();
    aspect1.count = 100;
    advisors.addAll(getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(aspect1, "someBean1")));
    PerTargetAspectWithOrderAnnotation5 aspect2 = new PerTargetAspectWithOrderAnnotation5();
    advisors.addAll(getFixture().getAdvisors(new SingletonMetadataAwareAspectInstanceFactory(aspect2, "someBean2")));
    OrderComparator.sort(advisors);
    TestBean itb = (TestBean) createProxy(target, advisors, TestBean.class);
    assertThat(itb.getAge()).as("Around advice must NOT apply").isEqualTo(realAge);
    // Hit the method in the per clause to instantiate the aspect
    itb.getSpouse();
    assertThat(itb.getAge()).as("Around advice must apply").isEqualTo(0);
    assertThat(itb.getAge()).as("Around advice must apply").isEqualTo(1);
}
Also used : ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) TestBean(cn.taketoday.beans.testfixture.beans.TestBean) ArrayList(java.util.ArrayList) Advisor(cn.taketoday.aop.Advisor) JoinPoint(org.aspectj.lang.JoinPoint) ProceedingJoinPoint(org.aspectj.lang.ProceedingJoinPoint) Test(org.junit.jupiter.api.Test)

Example 24 with Advisor

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

the class AspectJPrecedenceComparatorTests method testSameAdvisorPrecedenceDifferentAspectAfterAdvice.

@Test
public void testSameAdvisorPrecedenceDifferentAspectAfterAdvice() {
    Advisor advisor1 = createAspectJAfterAdvice(HIGH_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("nothing to say about order here").isEqualTo(0);
    advisor1 = createAspectJAfterReturningAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, LATE_ADVICE_DECLARATION_ORDER, "someAspect");
    advisor2 = createAspectJAfterThrowingAdvice(HIGH_PRECEDENCE_ADVISOR_ORDER, EARLY_ADVICE_DECLARATION_ORDER, "someOtherAspect");
    assertThat(this.comparator.compare(advisor1, advisor2)).as("nothing to say about order here").isEqualTo(0);
}
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 25 with Advisor

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

the class AspectJPrecedenceComparatorTests method testSameAspectAfterAdvice.

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

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