Search in sources :

Example 1 with ClassFilter

use of org.springframework.aop.ClassFilter in project spring-framework by spring-projects.

the class ClassFiltersTests method testIntersection.

@Test
public void testIntersection() {
    assertTrue(exceptionFilter.matches(RuntimeException.class));
    assertTrue(hasRootCauseFilter.matches(NestedRuntimeException.class));
    ClassFilter intersection = ClassFilters.intersection(exceptionFilter, hasRootCauseFilter);
    assertFalse(intersection.matches(RuntimeException.class));
    assertFalse(intersection.matches(TestBean.class));
    assertTrue(intersection.matches(NestedRuntimeException.class));
}
Also used : NestedRuntimeException(org.springframework.core.NestedRuntimeException) NestedRuntimeException(org.springframework.core.NestedRuntimeException) ITestBean(org.springframework.tests.sample.beans.ITestBean) TestBean(org.springframework.tests.sample.beans.TestBean) ClassFilter(org.springframework.aop.ClassFilter) Test(org.junit.Test)

Example 2 with ClassFilter

use of org.springframework.aop.ClassFilter in project spring-framework by spring-projects.

the class ClassFiltersTests method testUnion.

@Test
public void testUnion() {
    assertTrue(exceptionFilter.matches(RuntimeException.class));
    assertFalse(exceptionFilter.matches(TestBean.class));
    assertFalse(itbFilter.matches(Exception.class));
    assertTrue(itbFilter.matches(TestBean.class));
    ClassFilter union = ClassFilters.union(exceptionFilter, itbFilter);
    assertTrue(union.matches(RuntimeException.class));
    assertTrue(union.matches(TestBean.class));
}
Also used : NestedRuntimeException(org.springframework.core.NestedRuntimeException) ITestBean(org.springframework.tests.sample.beans.ITestBean) TestBean(org.springframework.tests.sample.beans.TestBean) ClassFilter(org.springframework.aop.ClassFilter) NestedRuntimeException(org.springframework.core.NestedRuntimeException) Test(org.junit.Test)

Example 3 with ClassFilter

use of org.springframework.aop.ClassFilter in project spring-framework by spring-projects.

the class ComposablePointcutTests method testFilterByClass.

@Test
public void testFilterByClass() throws NoSuchMethodException {
    ComposablePointcut pc = new ComposablePointcut();
    assertTrue(pc.getClassFilter().matches(Object.class));
    ClassFilter cf = new RootClassFilter(Exception.class);
    pc.intersection(cf);
    assertFalse(pc.getClassFilter().matches(Object.class));
    assertTrue(pc.getClassFilter().matches(Exception.class));
    pc.intersection(new RootClassFilter(NestedRuntimeException.class));
    assertFalse(pc.getClassFilter().matches(Exception.class));
    assertTrue(pc.getClassFilter().matches(NestedRuntimeException.class));
    assertFalse(pc.getClassFilter().matches(String.class));
    pc.union(new RootClassFilter(String.class));
    assertFalse(pc.getClassFilter().matches(Exception.class));
    assertTrue(pc.getClassFilter().matches(String.class));
    assertTrue(pc.getClassFilter().matches(NestedRuntimeException.class));
}
Also used : NestedRuntimeException(org.springframework.core.NestedRuntimeException) ClassFilter(org.springframework.aop.ClassFilter) NestedRuntimeException(org.springframework.core.NestedRuntimeException) Test(org.junit.Test)

Example 4 with ClassFilter

use of org.springframework.aop.ClassFilter in project spring-framework by spring-projects.

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);
    assertFalse("Should not be a runtime match", methodMatcher.isRuntime());
    assertMatchesGetAge(methodMatcher);
    assertTrue("Expression should match setAge(int) method", methodMatcher.matches(setAge, TestBean.class));
}
Also used : Pointcut(org.springframework.aop.Pointcut) ITestBean(org.springframework.tests.sample.beans.ITestBean) TestBean(org.springframework.tests.sample.beans.TestBean) ClassFilter(org.springframework.aop.ClassFilter) MethodMatcher(org.springframework.aop.MethodMatcher) Test(org.junit.Test)

Example 5 with ClassFilter

use of org.springframework.aop.ClassFilter in project spring-framework by spring-projects.

the class CallCountingInterceptor method testMatchExplicit.

@Test
public void testMatchExplicit() {
    String expression = "execution(int org.springframework.tests.sample.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);
    assertFalse("Should not be a runtime match", methodMatcher.isRuntime());
    assertMatchesGetAge(methodMatcher);
    assertFalse("Expression should match setAge() method", methodMatcher.matches(setAge, TestBean.class));
}
Also used : Pointcut(org.springframework.aop.Pointcut) ITestBean(org.springframework.tests.sample.beans.ITestBean) TestBean(org.springframework.tests.sample.beans.TestBean) ClassFilter(org.springframework.aop.ClassFilter) MethodMatcher(org.springframework.aop.MethodMatcher) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)6 ClassFilter (org.springframework.aop.ClassFilter)6 ITestBean (org.springframework.tests.sample.beans.ITestBean)5 TestBean (org.springframework.tests.sample.beans.TestBean)5 MethodMatcher (org.springframework.aop.MethodMatcher)3 Pointcut (org.springframework.aop.Pointcut)3 NestedRuntimeException (org.springframework.core.NestedRuntimeException)3