use of cn.taketoday.aop.framework.DefaultMethodInvocation in project today-infrastructure by TAKETODAY.
the class TigerAspectJExpressionPointcutTests method testAnnotationOnMethodArgumentsWithFQN.
@Test
public void testAnnotationOnMethodArgumentsWithFQN() throws Exception {
String expression = "@args(*, test.annotation.EmptySpringAnnotation))";
AspectJExpressionPointcut takesSpringAnnotatedArgument2 = new AspectJExpressionPointcut();
takesSpringAnnotatedArgument2.setExpression(expression);
assertThat(takesSpringAnnotatedArgument2.matches(getAge, TestBean.class)).isFalse();
assertThat(takesSpringAnnotatedArgument2.matches(HasTransactionalAnnotation.class.getMethod("foo"), HasTransactionalAnnotation.class)).isFalse();
assertThat(takesSpringAnnotatedArgument2.matches(HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class)).isFalse();
assertThat(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("setName", String.class), BeanA.class)).isFalse();
assertThat(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("getAge"), BeanA.class)).isFalse();
assertThat(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("setName", String.class), BeanA.class)).isFalse();
assertThat(takesSpringAnnotatedArgument2.matches(ProcessesSpringAnnotatedParameters.class.getMethod("takesAnnotatedParameters", TestBean.class, SpringAnnotated.class), ProcessesSpringAnnotatedParameters.class)).isTrue();
// True because it maybeMatches with potential argument subtypes
assertThat(takesSpringAnnotatedArgument2.matches(ProcessesSpringAnnotatedParameters.class.getMethod("takesNoAnnotatedParameters", TestBean.class, BeanA.class), ProcessesSpringAnnotatedParameters.class)).isTrue();
Method takesNoAnnotatedParameters = ProcessesSpringAnnotatedParameters.class.getMethod("takesNoAnnotatedParameters", TestBean.class, BeanA.class);
DefaultMethodInvocation invocation = new DefaultMethodInvocation(null, new ProcessesSpringAnnotatedParameters(), takesNoAnnotatedParameters, ProcessesSpringAnnotatedParameters.class, new Object[] { new TestBean(), new BeanA() }, null);
assertThat(takesSpringAnnotatedArgument2.matches(invocation)).isFalse();
}
use of cn.taketoday.aop.framework.DefaultMethodInvocation 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();
}
use of cn.taketoday.aop.framework.DefaultMethodInvocation in project today-infrastructure 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.framework.DefaultMethodInvocation in project today-framework by TAKETODAY.
the class CallCountingInterceptor method testFriendlyErrorOnNoLocation3ArgMatching.
@Test
public void testFriendlyErrorOnNoLocation3ArgMatching() {
AspectJExpressionPointcut pc = new AspectJExpressionPointcut();
DefaultMethodInvocation invocation = new DefaultMethodInvocation(null, getAge, ITestBean.class, new Object[] {});
assertThatIllegalStateException().isThrownBy(() -> pc.matches(invocation)).withMessageContaining("expression");
}
use of cn.taketoday.aop.framework.DefaultMethodInvocation in project today-framework by TAKETODAY.
the class TigerAspectJExpressionPointcutTests method testAnnotationOnMethodArgumentsWithFQN.
@Test
public void testAnnotationOnMethodArgumentsWithFQN() throws Exception {
String expression = "@args(*, test.annotation.EmptySpringAnnotation))";
AspectJExpressionPointcut takesSpringAnnotatedArgument2 = new AspectJExpressionPointcut();
takesSpringAnnotatedArgument2.setExpression(expression);
assertThat(takesSpringAnnotatedArgument2.matches(getAge, TestBean.class)).isFalse();
assertThat(takesSpringAnnotatedArgument2.matches(HasTransactionalAnnotation.class.getMethod("foo"), HasTransactionalAnnotation.class)).isFalse();
assertThat(takesSpringAnnotatedArgument2.matches(HasTransactionalAnnotation.class.getMethod("bar", String.class), HasTransactionalAnnotation.class)).isFalse();
assertThat(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("setName", String.class), BeanA.class)).isFalse();
assertThat(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("getAge"), BeanA.class)).isFalse();
assertThat(takesSpringAnnotatedArgument2.matches(BeanA.class.getMethod("setName", String.class), BeanA.class)).isFalse();
assertThat(takesSpringAnnotatedArgument2.matches(ProcessesSpringAnnotatedParameters.class.getMethod("takesAnnotatedParameters", TestBean.class, SpringAnnotated.class), ProcessesSpringAnnotatedParameters.class)).isTrue();
// True because it maybeMatches with potential argument subtypes
assertThat(takesSpringAnnotatedArgument2.matches(ProcessesSpringAnnotatedParameters.class.getMethod("takesNoAnnotatedParameters", TestBean.class, BeanA.class), ProcessesSpringAnnotatedParameters.class)).isTrue();
Method takesNoAnnotatedParameters = ProcessesSpringAnnotatedParameters.class.getMethod("takesNoAnnotatedParameters", TestBean.class, BeanA.class);
DefaultMethodInvocation invocation = new DefaultMethodInvocation(null, new ProcessesSpringAnnotatedParameters(), takesNoAnnotatedParameters, ProcessesSpringAnnotatedParameters.class, new Object[] { new TestBean(), new BeanA() }, null);
assertThat(takesSpringAnnotatedArgument2.matches(invocation)).isFalse();
}
Aggregations