Search in sources :

Example 1 with ClassFilter

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

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

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

the class ComposablePointcutTests method testFilterByClass.

@Test
public void testFilterByClass() throws NoSuchMethodException {
    ComposablePointcut pc = new ComposablePointcut();
    assertThat(pc.getClassFilter().matches(Object.class)).isTrue();
    ClassFilter cf = new RootClassFilter(Exception.class);
    pc.intersection(cf);
    assertThat(pc.getClassFilter().matches(Object.class)).isFalse();
    assertThat(pc.getClassFilter().matches(Exception.class)).isTrue();
    pc.intersection(new RootClassFilter(NestedRuntimeException.class));
    assertThat(pc.getClassFilter().matches(Exception.class)).isFalse();
    assertThat(pc.getClassFilter().matches(NestedRuntimeException.class)).isTrue();
    assertThat(pc.getClassFilter().matches(String.class)).isFalse();
    pc.union(new RootClassFilter(String.class));
    assertThat(pc.getClassFilter().matches(Exception.class)).isFalse();
    assertThat(pc.getClassFilter().matches(String.class)).isTrue();
    assertThat(pc.getClassFilter().matches(NestedRuntimeException.class)).isTrue();
}
Also used : NestedRuntimeException(cn.taketoday.core.NestedRuntimeException) ClassFilter(cn.taketoday.aop.ClassFilter) Test(org.junit.jupiter.api.Test)

Example 4 with ClassFilter

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

the class ClassFiltersTests method intersection.

@Test
void intersection() {
    assertThat(exceptionFilter.matches(RuntimeException.class)).isTrue();
    assertThat(hasRootCauseFilter.matches(NestedRuntimeException.class)).isTrue();
    ClassFilter intersection = ClassFilters.intersection(exceptionFilter, hasRootCauseFilter);
    assertThat(intersection.matches(RuntimeException.class)).isFalse();
    assertThat(intersection.matches(TestBean.class)).isFalse();
    assertThat(intersection.matches(NestedRuntimeException.class)).isTrue();
    assertThat(intersection.toString()).matches("^.+IntersectionClassFilter: \\[.+RootClassFilter: .+Exception, .+RootClassFilter: .+NestedRuntimeException\\]$");
}
Also used : ClassFilter(cn.taketoday.aop.ClassFilter) Test(org.junit.jupiter.api.Test)

Example 5 with ClassFilter

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

the class ComposablePointcutTests method testFilterByClass.

@Test
public void testFilterByClass() throws NoSuchMethodException {
    ComposablePointcut pc = new ComposablePointcut();
    assertThat(pc.getClassFilter().matches(Object.class)).isTrue();
    ClassFilter cf = new RootClassFilter(Exception.class);
    pc.intersection(cf);
    assertThat(pc.getClassFilter().matches(Object.class)).isFalse();
    assertThat(pc.getClassFilter().matches(Exception.class)).isTrue();
    pc.intersection(new RootClassFilter(NestedRuntimeException.class));
    assertThat(pc.getClassFilter().matches(Exception.class)).isFalse();
    assertThat(pc.getClassFilter().matches(NestedRuntimeException.class)).isTrue();
    assertThat(pc.getClassFilter().matches(String.class)).isFalse();
    pc.union(new RootClassFilter(String.class));
    assertThat(pc.getClassFilter().matches(Exception.class)).isFalse();
    assertThat(pc.getClassFilter().matches(String.class)).isTrue();
    assertThat(pc.getClassFilter().matches(NestedRuntimeException.class)).isTrue();
}
Also used : NestedRuntimeException(cn.taketoday.core.NestedRuntimeException) ClassFilter(cn.taketoday.aop.ClassFilter) Test(org.junit.jupiter.api.Test)

Aggregations

ClassFilter (cn.taketoday.aop.ClassFilter)12 Test (org.junit.jupiter.api.Test)12 MethodMatcher (cn.taketoday.aop.MethodMatcher)6 Pointcut (cn.taketoday.aop.Pointcut)6 ITestBean (cn.taketoday.beans.testfixture.beans.ITestBean)6 TestBean (cn.taketoday.beans.testfixture.beans.TestBean)6 DefaultMethodInvocation (cn.taketoday.aop.framework.DefaultMethodInvocation)2 NestedRuntimeException (cn.taketoday.core.NestedRuntimeException)2