Search in sources :

Example 26 with Pointcut

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

the class CallCountingInterceptor method testMatchExplicit.

@Test
public void testMatchExplicit() {
    String expression = "execution(int cn.taketoday.beans.testfixture.beans.TestBean.getAge())";
    Pointcut pointcut = getPointcut(expression);
    ClassFilter classFilter = pointcut.getClassFilter();
    MethodMatcher methodMatcher = pointcut.getMethodMatcher();
    assertMatchesTestBeanClass(classFilter);
    // not currently testable in a reliable fashion
    // assertDoesNotMatchStringClass(classFilter);
    assertThat(methodMatcher.isRuntime()).as("Should not be a runtime match").isFalse();
    assertMatchesGetAge(methodMatcher);
    assertThat(methodMatcher.matches(setAge, TestBean.class)).as("Expression should match setAge() method").isFalse();
}
Also used : Pointcut(cn.taketoday.aop.Pointcut) TestBean(cn.taketoday.beans.testfixture.beans.TestBean) ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) ClassFilter(cn.taketoday.aop.ClassFilter) MethodMatcher(cn.taketoday.aop.MethodMatcher) Test(org.junit.jupiter.api.Test)

Example 27 with Pointcut

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

the class CallCountingInterceptor method testAndSubstitution.

@Test
public void testAndSubstitution() {
    Pointcut pc = getPointcut("execution(* *(..)) and args(String)");
    PointcutExpression expr = ((AspectJExpressionPointcut) pc).getPointcutExpression();
    assertThat(expr.getPointcutExpression()).isEqualTo("execution(* *(..)) && args(String)");
}
Also used : Pointcut(cn.taketoday.aop.Pointcut) PointcutExpression(org.aspectj.weaver.tools.PointcutExpression) Test(org.junit.jupiter.api.Test)

Example 28 with Pointcut

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

the class CallCountingInterceptor method testMatchWithArgs.

@Test
public void testMatchWithArgs() throws Exception {
    String expression = "execution(void cn.taketoday.beans.testfixture.beans.TestBean.setSomeNumber(Number)) && args(Double)";
    Pointcut pointcut = getPointcut(expression);
    ClassFilter classFilter = pointcut.getClassFilter();
    MethodMatcher methodMatcher = pointcut.getMethodMatcher();
    assertMatchesTestBeanClass(classFilter);
    // not currently testable in a reliable fashion
    // assertDoesNotMatchStringClass(classFilter);
    DefaultMethodInvocation invocation = new DefaultMethodInvocation(null, new TestBean(), setSomeNumber, TestBean.class, new Object[] { 12D }, null);
    DefaultMethodInvocation invocation1 = new DefaultMethodInvocation(null, new TestBean(), setSomeNumber, TestBean.class, new Object[] { 11 }, null);
    assertThat(methodMatcher.matches(invocation)).as("Should match with setSomeNumber with Double input").isTrue();
    assertThat(methodMatcher.matches(invocation1)).as("Should not match setSomeNumber with Integer input").isFalse();
    assertThat(methodMatcher.matches(getAge, TestBean.class)).as("Should not match getAge").isFalse();
    assertThat(methodMatcher.isRuntime()).as("Should be a runtime match").isTrue();
}
Also used : Pointcut(cn.taketoday.aop.Pointcut) DefaultMethodInvocation(cn.taketoday.aop.framework.DefaultMethodInvocation) TestBean(cn.taketoday.beans.testfixture.beans.TestBean) ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) ClassFilter(cn.taketoday.aop.ClassFilter) MethodMatcher(cn.taketoday.aop.MethodMatcher) Test(org.junit.jupiter.api.Test)

Example 29 with Pointcut

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

the class CallCountingInterceptor method testMatchWithTypePattern.

@Test
public void testMatchWithTypePattern() throws Exception {
    String expression = "execution(* *..TestBean.*Age(..))";
    Pointcut pointcut = getPointcut(expression);
    ClassFilter classFilter = pointcut.getClassFilter();
    MethodMatcher methodMatcher = pointcut.getMethodMatcher();
    assertMatchesTestBeanClass(classFilter);
    // not currently testable in a reliable fashion
    // assertDoesNotMatchStringClass(classFilter);
    assertThat(methodMatcher.isRuntime()).as("Should not be a runtime match").isFalse();
    assertMatchesGetAge(methodMatcher);
    assertThat(methodMatcher.matches(setAge, TestBean.class)).as("Expression should match setAge(int) method").isTrue();
}
Also used : Pointcut(cn.taketoday.aop.Pointcut) TestBean(cn.taketoday.beans.testfixture.beans.TestBean) ITestBean(cn.taketoday.beans.testfixture.beans.ITestBean) ClassFilter(cn.taketoday.aop.ClassFilter) MethodMatcher(cn.taketoday.aop.MethodMatcher) Test(org.junit.jupiter.api.Test)

Example 30 with Pointcut

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

the class CallCountingInterceptor method testMultipleAndSubstitutions.

@Test
public void testMultipleAndSubstitutions() {
    Pointcut pc = getPointcut("execution(* *(..)) and args(String) and this(Object)");
    PointcutExpression expr = ((AspectJExpressionPointcut) pc).getPointcutExpression();
    assertThat(expr.getPointcutExpression()).isEqualTo("execution(* *(..)) && args(String) && this(Object)");
}
Also used : Pointcut(cn.taketoday.aop.Pointcut) PointcutExpression(org.aspectj.weaver.tools.PointcutExpression) Test(org.junit.jupiter.api.Test)

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