Search in sources :

Example 11 with Pointcut

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

the class AnnotationMatchingPointcutTests method classLevelAndMethodLevelPointcuts.

@Test
public void classLevelAndMethodLevelPointcuts() {
    Pointcut pointcut1 = new AnnotationMatchingPointcut(Qualifier.class, Qualifier.class, true);
    Pointcut pointcut2 = new AnnotationMatchingPointcut(Qualifier.class, Qualifier.class, true);
    Pointcut pointcut3 = new AnnotationMatchingPointcut(Qualifier.class, Qualifier.class);
    assertThat(pointcut1.getClassFilter().getClass()).isEqualTo(AnnotationClassFilter.class);
    assertThat(pointcut2.getClassFilter().getClass()).isEqualTo(AnnotationClassFilter.class);
    assertThat(pointcut3.getClassFilter().getClass()).isEqualTo(AnnotationClassFilter.class);
    assertThat(pointcut1.getClassFilter().toString()).contains(Qualifier.class.getName());
    assertThat(pointcut1.getMethodMatcher().getClass()).isEqualTo(AnnotationMethodMatcher.class);
    assertThat(pointcut2.getMethodMatcher().getClass()).isEqualTo(AnnotationMethodMatcher.class);
    assertThat(pointcut3.getMethodMatcher().getClass()).isEqualTo(AnnotationMethodMatcher.class);
    assertThat(pointcut1.getMethodMatcher().toString()).contains(Qualifier.class.getName());
    assertThat(pointcut1).isEqualTo(pointcut2);
    assertThat(pointcut1).isNotEqualTo(pointcut3);
    assertThat(pointcut1.hashCode()).isEqualTo(pointcut2.hashCode());
    // #1 and #3 have equivalent hash codes even though equals() returns false.
    assertThat(pointcut1.hashCode()).isEqualTo(pointcut3.hashCode());
    assertThat(pointcut1.toString()).isEqualTo(pointcut2.toString());
}
Also used : Pointcut(cn.taketoday.aop.Pointcut) AnnotationMatchingPointcut(cn.taketoday.aop.support.annotation.AnnotationMatchingPointcut) AnnotationMatchingPointcut(cn.taketoday.aop.support.annotation.AnnotationMatchingPointcut) Qualifier(jakarta.inject.Qualifier) Test(org.junit.jupiter.api.Test)

Example 12 with Pointcut

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

the class AnnotationMatchingPointcutTests method methodLevelPointcuts.

@Test
public void methodLevelPointcuts() {
    Pointcut pointcut1 = new AnnotationMatchingPointcut(null, Qualifier.class, true);
    Pointcut pointcut2 = new AnnotationMatchingPointcut(null, Qualifier.class, true);
    Pointcut pointcut3 = new AnnotationMatchingPointcut(null, Qualifier.class);
    assertThat(pointcut1.getClassFilter().getClass().getSimpleName()).isEqualTo("AnnotationCandidateClassFilter");
    assertThat(pointcut2.getClassFilter().getClass().getSimpleName()).isEqualTo("AnnotationCandidateClassFilter");
    assertThat(pointcut3.getClassFilter().getClass().getSimpleName()).isEqualTo("AnnotationCandidateClassFilter");
    assertThat(pointcut1.getClassFilter().toString()).contains(Qualifier.class.getName());
    assertThat(pointcut1.getMethodMatcher().getClass()).isEqualTo(AnnotationMethodMatcher.class);
    assertThat(pointcut2.getMethodMatcher().getClass()).isEqualTo(AnnotationMethodMatcher.class);
    assertThat(pointcut3.getMethodMatcher().getClass()).isEqualTo(AnnotationMethodMatcher.class);
    assertThat(pointcut1).isEqualTo(pointcut2);
    assertThat(pointcut1).isNotEqualTo(pointcut3);
    assertThat(pointcut1.hashCode()).isEqualTo(pointcut2.hashCode());
    // #1 and #3 have equivalent hash codes even though equals() returns false.
    assertThat(pointcut1.hashCode()).isEqualTo(pointcut3.hashCode());
    assertThat(pointcut1.toString()).isEqualTo(pointcut2.toString());
}
Also used : Pointcut(cn.taketoday.aop.Pointcut) AnnotationMatchingPointcut(cn.taketoday.aop.support.annotation.AnnotationMatchingPointcut) AnnotationMatchingPointcut(cn.taketoday.aop.support.annotation.AnnotationMatchingPointcut) Qualifier(jakarta.inject.Qualifier) Test(org.junit.jupiter.api.Test)

Example 13 with Pointcut

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

the class AnnotationMatchingPointcutTests method classLevelPointcuts.

@Test
public void classLevelPointcuts() {
    Pointcut pointcut1 = new AnnotationMatchingPointcut(Qualifier.class, true);
    Pointcut pointcut2 = new AnnotationMatchingPointcut(Qualifier.class, true);
    Pointcut pointcut3 = new AnnotationMatchingPointcut(Qualifier.class);
    assertThat(pointcut1.getClassFilter().getClass()).isEqualTo(AnnotationClassFilter.class);
    assertThat(pointcut2.getClassFilter().getClass()).isEqualTo(AnnotationClassFilter.class);
    assertThat(pointcut3.getClassFilter().getClass()).isEqualTo(AnnotationClassFilter.class);
    assertThat(pointcut1.getClassFilter().toString()).contains(Qualifier.class.getName());
    assertThat(pointcut1.getMethodMatcher()).isEqualTo(MethodMatcher.TRUE);
    assertThat(pointcut2.getMethodMatcher()).isEqualTo(MethodMatcher.TRUE);
    assertThat(pointcut3.getMethodMatcher()).isEqualTo(MethodMatcher.TRUE);
    assertThat(pointcut1).isEqualTo(pointcut2);
    assertThat(pointcut1).isNotEqualTo(pointcut3);
    assertThat(pointcut1.hashCode()).isEqualTo(pointcut2.hashCode());
    // #1 and #3 have equivalent hash codes even though equals() returns false.
    assertThat(pointcut1.hashCode()).isEqualTo(pointcut3.hashCode());
    assertThat(pointcut1.toString()).isEqualTo(pointcut2.toString());
}
Also used : Pointcut(cn.taketoday.aop.Pointcut) AnnotationMatchingPointcut(cn.taketoday.aop.support.annotation.AnnotationMatchingPointcut) AnnotationMatchingPointcut(cn.taketoday.aop.support.annotation.AnnotationMatchingPointcut) Qualifier(jakarta.inject.Qualifier) Test(org.junit.jupiter.api.Test)

Example 14 with Pointcut

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

the class AnnotationMatchingPointcutTests method classLevelPointcuts.

@Test
void classLevelPointcuts() {
    Pointcut pointcut1 = new AnnotationMatchingPointcut(Qualifier.class, true);
    Pointcut pointcut2 = new AnnotationMatchingPointcut(Qualifier.class, true);
    Pointcut pointcut3 = new AnnotationMatchingPointcut(Qualifier.class);
    assertThat(pointcut1.getClassFilter().getClass()).isEqualTo(AnnotationClassFilter.class);
    assertThat(pointcut2.getClassFilter().getClass()).isEqualTo(AnnotationClassFilter.class);
    assertThat(pointcut3.getClassFilter().getClass()).isEqualTo(AnnotationClassFilter.class);
    assertThat(pointcut1.getClassFilter().toString()).contains(Qualifier.class.getName());
    assertThat(pointcut1.getMethodMatcher()).isEqualTo(MethodMatcher.TRUE);
    assertThat(pointcut2.getMethodMatcher()).isEqualTo(MethodMatcher.TRUE);
    assertThat(pointcut3.getMethodMatcher()).isEqualTo(MethodMatcher.TRUE);
    assertThat(pointcut1).isEqualTo(pointcut2);
    assertThat(pointcut1).isNotEqualTo(pointcut3);
    assertThat(pointcut1.hashCode()).isEqualTo(pointcut2.hashCode());
    // #1 and #3 have equivalent hash codes even though equals() returns false.
    assertThat(pointcut1.hashCode()).isEqualTo(pointcut3.hashCode());
    assertThat(pointcut1.toString()).isEqualTo(pointcut2.toString());
}
Also used : Pointcut(cn.taketoday.aop.Pointcut) Qualifier(cn.taketoday.beans.factory.annotation.Qualifier) Test(org.junit.jupiter.api.Test)

Example 15 with Pointcut

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

Aggregations

Pointcut (cn.taketoday.aop.Pointcut)51 Test (org.junit.jupiter.api.Test)42 ITestBean (cn.taketoday.beans.testfixture.beans.ITestBean)13 AnnotationMatchingPointcut (cn.taketoday.aop.support.annotation.AnnotationMatchingPointcut)10 TestBean (cn.taketoday.beans.testfixture.beans.TestBean)10 DefaultPointcutAdvisor (cn.taketoday.aop.support.DefaultPointcutAdvisor)7 ClassFilter (cn.taketoday.aop.ClassFilter)6 MethodMatcher (cn.taketoday.aop.MethodMatcher)6 Qualifier (cn.taketoday.beans.factory.annotation.Qualifier)6 Qualifier (jakarta.inject.Qualifier)6 Method (java.lang.reflect.Method)6 ProxyFactory (cn.taketoday.aop.framework.ProxyFactory)5 NopInterceptor (cn.taketoday.aop.testfixture.interceptor.NopInterceptor)4 Nullable (cn.taketoday.lang.Nullable)4 PointcutExpression (org.aspectj.weaver.tools.PointcutExpression)4 MethodInterceptor (org.aopalliance.intercept.MethodInterceptor)3 DefaultMethodInvocation (cn.taketoday.aop.framework.DefaultMethodInvocation)2 ComposablePointcut (cn.taketoday.aop.support.ComposablePointcut)2 StaticMethodMatcherPointcut (cn.taketoday.aop.support.StaticMethodMatcherPointcut)2 NopInterceptor (cn.taketoday.aop.NopInterceptor)1