use of cn.taketoday.aop.MethodMatcher 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();
}
use of cn.taketoday.aop.MethodMatcher in project today-framework by TAKETODAY.
the class MethodMatchersTests method testUnionEquals.
@Test
public void testUnionEquals() {
MethodMatcher first = MethodMatchers.union(MethodMatcher.TRUE, MethodMatcher.TRUE);
MethodMatcher second = new ComposablePointcut(MethodMatcher.TRUE).union(new ComposablePointcut(MethodMatcher.TRUE)).getMethodMatcher();
assertThat(first.equals(second)).isTrue();
assertThat(second.equals(first)).isTrue();
}
use of cn.taketoday.aop.MethodMatcher in project today-framework by TAKETODAY.
the class MethodMatchersTests method testDefaultMatchesAll.
@Test
public void testDefaultMatchesAll() throws Exception {
MethodMatcher defaultMm = MethodMatcher.TRUE;
assertThat(defaultMm.matches(EXCEPTION_GETMESSAGE, Exception.class)).isTrue();
assertThat(defaultMm.matches(ITESTBEAN_SETAGE, TestBean.class)).isTrue();
}
use of cn.taketoday.aop.MethodMatcher in project today-framework by TAKETODAY.
the class MethodMatchersTests method testDynamicAndStaticMethodMatcherIntersection.
@Test
public void testDynamicAndStaticMethodMatcherIntersection() throws Exception {
MethodMatcher mm1 = MethodMatcher.TRUE;
MethodMatcher mm2 = new TestDynamicMethodMatcherWhichMatches();
MethodMatcher intersection = MethodMatchers.intersection(mm1, mm2);
assertThat(intersection.isRuntime()).as("Intersection is a dynamic matcher").isTrue();
assertThat(intersection.matches(ITESTBEAN_SETAGE, TestBean.class)).as("2Matched setAge method").isTrue();
DefaultMethodInvocation defaultMethodInvocation = new DefaultMethodInvocation(null, new TestBean(), ITESTBEAN_SETAGE, TestBean.class, new Object[] { 5 }, null);
assertThat(intersection.matches(defaultMethodInvocation)).as("3Matched setAge method").isTrue();
// Knock out dynamic part
intersection = MethodMatchers.intersection(intersection, new TestDynamicMethodMatcherWhichDoesNotMatch());
assertThat(intersection.isRuntime()).as("Intersection is a dynamic matcher").isTrue();
assertThat(intersection.matches(ITESTBEAN_SETAGE, TestBean.class)).as("2Matched setAge method").isTrue();
assertThat(intersection.matches(defaultMethodInvocation)).as("3 - not Matched setAge method").isFalse();
}
use of cn.taketoday.aop.MethodMatcher in project today-framework by TAKETODAY.
the class Pointcuts method matches.
/**
* Perform the least expensive check for a pointcut match.
*
* @param pointcut the pointcut to match
* @param invocation runtime invocation contains the candidate method
* and target class, arguments to the method
* @return whether there's a runtime match
*/
public static boolean matches(Pointcut pointcut, MethodInvocation invocation) {
Assert.notNull(pointcut, "Pointcut must not be null");
if (pointcut == Pointcut.TRUE) {
return true;
}
final Class<?> targetClass = AopUtils.getTargetClass(invocation);
if (pointcut.getClassFilter().matches(targetClass)) {
// Only check if it gets past first hurdle.
MethodMatcher mm = pointcut.getMethodMatcher();
if (mm.matches(invocation.getMethod(), targetClass)) {
// We may need additional runtime (argument) check.
return (!mm.isRuntime() || mm.matches(invocation));
}
}
return false;
}
Aggregations