|
|
|
@ -51,7 +51,7 @@ import static org.assertj.core.api.Assertions.assertThatIllegalStateException; |
|
|
|
* @author Chris Beams |
|
|
|
* @author Chris Beams |
|
|
|
* @author Yanming Zhou |
|
|
|
* @author Yanming Zhou |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class AspectJExpressionPointcutTests { |
|
|
|
class AspectJExpressionPointcutTests { |
|
|
|
|
|
|
|
|
|
|
|
public static final String MATCH_ALL_METHODS = "execution(* *(..))"; |
|
|
|
public static final String MATCH_ALL_METHODS = "execution(* *(..))"; |
|
|
|
|
|
|
|
|
|
|
|
@ -78,7 +78,7 @@ public class AspectJExpressionPointcutTests { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testMatchExplicit() { |
|
|
|
void testMatchExplicit() { |
|
|
|
String expression = "execution(int org.springframework.beans.testfixture.beans.TestBean.getAge())"; |
|
|
|
String expression = "execution(int org.springframework.beans.testfixture.beans.TestBean.getAge())"; |
|
|
|
|
|
|
|
|
|
|
|
Pointcut pointcut = getPointcut(expression); |
|
|
|
Pointcut pointcut = getPointcut(expression); |
|
|
|
@ -96,7 +96,7 @@ public class AspectJExpressionPointcutTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testMatchWithTypePattern() throws Exception { |
|
|
|
void testMatchWithTypePattern() { |
|
|
|
String expression = "execution(* *..TestBean.*Age(..))"; |
|
|
|
String expression = "execution(* *..TestBean.*Age(..))"; |
|
|
|
|
|
|
|
|
|
|
|
Pointcut pointcut = getPointcut(expression); |
|
|
|
Pointcut pointcut = getPointcut(expression); |
|
|
|
@ -115,12 +115,12 @@ public class AspectJExpressionPointcutTests { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testThis() throws SecurityException, NoSuchMethodException{ |
|
|
|
void testThis() throws SecurityException, NoSuchMethodException{ |
|
|
|
testThisOrTarget("this"); |
|
|
|
testThisOrTarget("this"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testTarget() throws SecurityException, NoSuchMethodException { |
|
|
|
void testTarget() throws SecurityException, NoSuchMethodException { |
|
|
|
testThisOrTarget("target"); |
|
|
|
testThisOrTarget("target"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -144,12 +144,12 @@ public class AspectJExpressionPointcutTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testWithinRootPackage() throws SecurityException, NoSuchMethodException { |
|
|
|
void testWithinRootPackage() throws SecurityException, NoSuchMethodException { |
|
|
|
testWithinPackage(false); |
|
|
|
testWithinPackage(false); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testWithinRootAndSubpackages() throws SecurityException, NoSuchMethodException { |
|
|
|
void testWithinRootAndSubpackages() throws SecurityException, NoSuchMethodException { |
|
|
|
testWithinPackage(true); |
|
|
|
testWithinPackage(true); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@ -173,7 +173,7 @@ public class AspectJExpressionPointcutTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testFriendlyErrorOnNoLocationClassMatching() { |
|
|
|
void testFriendlyErrorOnNoLocationClassMatching() { |
|
|
|
AspectJExpressionPointcut pc = new AspectJExpressionPointcut(); |
|
|
|
AspectJExpressionPointcut pc = new AspectJExpressionPointcut(); |
|
|
|
assertThatIllegalStateException().isThrownBy(() -> |
|
|
|
assertThatIllegalStateException().isThrownBy(() -> |
|
|
|
pc.matches(ITestBean.class)) |
|
|
|
pc.matches(ITestBean.class)) |
|
|
|
@ -181,7 +181,7 @@ public class AspectJExpressionPointcutTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testFriendlyErrorOnNoLocation2ArgMatching() { |
|
|
|
void testFriendlyErrorOnNoLocation2ArgMatching() { |
|
|
|
AspectJExpressionPointcut pc = new AspectJExpressionPointcut(); |
|
|
|
AspectJExpressionPointcut pc = new AspectJExpressionPointcut(); |
|
|
|
assertThatIllegalStateException().isThrownBy(() -> |
|
|
|
assertThatIllegalStateException().isThrownBy(() -> |
|
|
|
pc.matches(getAge, ITestBean.class)) |
|
|
|
pc.matches(getAge, ITestBean.class)) |
|
|
|
@ -189,7 +189,7 @@ public class AspectJExpressionPointcutTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testFriendlyErrorOnNoLocation3ArgMatching() { |
|
|
|
void testFriendlyErrorOnNoLocation3ArgMatching() { |
|
|
|
AspectJExpressionPointcut pc = new AspectJExpressionPointcut(); |
|
|
|
AspectJExpressionPointcut pc = new AspectJExpressionPointcut(); |
|
|
|
assertThatIllegalStateException().isThrownBy(() -> |
|
|
|
assertThatIllegalStateException().isThrownBy(() -> |
|
|
|
pc.matches(getAge, ITestBean.class, (Object[]) null)) |
|
|
|
pc.matches(getAge, ITestBean.class, (Object[]) null)) |
|
|
|
@ -198,7 +198,7 @@ public class AspectJExpressionPointcutTests { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testMatchWithArgs() throws Exception { |
|
|
|
void testMatchWithArgs() throws Exception { |
|
|
|
String expression = "execution(void org.springframework.beans.testfixture.beans.TestBean.setSomeNumber(Number)) && args(Double)"; |
|
|
|
String expression = "execution(void org.springframework.beans.testfixture.beans.TestBean.setSomeNumber(Number)) && args(Double)"; |
|
|
|
|
|
|
|
|
|
|
|
Pointcut pointcut = getPointcut(expression); |
|
|
|
Pointcut pointcut = getPointcut(expression); |
|
|
|
@ -217,7 +217,7 @@ public class AspectJExpressionPointcutTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testSimpleAdvice() { |
|
|
|
void testSimpleAdvice() { |
|
|
|
String expression = "execution(int org.springframework.beans.testfixture.beans.TestBean.getAge())"; |
|
|
|
String expression = "execution(int org.springframework.beans.testfixture.beans.TestBean.getAge())"; |
|
|
|
CallCountingInterceptor interceptor = new CallCountingInterceptor(); |
|
|
|
CallCountingInterceptor interceptor = new CallCountingInterceptor(); |
|
|
|
TestBean testBean = getAdvisedProxy(expression, interceptor); |
|
|
|
TestBean testBean = getAdvisedProxy(expression, interceptor); |
|
|
|
@ -230,7 +230,7 @@ public class AspectJExpressionPointcutTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testDynamicMatchingProxy() { |
|
|
|
void testDynamicMatchingProxy() { |
|
|
|
String expression = "execution(void org.springframework.beans.testfixture.beans.TestBean.setSomeNumber(Number)) && args(Double)"; |
|
|
|
String expression = "execution(void org.springframework.beans.testfixture.beans.TestBean.setSomeNumber(Number)) && args(Double)"; |
|
|
|
CallCountingInterceptor interceptor = new CallCountingInterceptor(); |
|
|
|
CallCountingInterceptor interceptor = new CallCountingInterceptor(); |
|
|
|
TestBean testBean = getAdvisedProxy(expression, interceptor); |
|
|
|
TestBean testBean = getAdvisedProxy(expression, interceptor); |
|
|
|
@ -244,7 +244,7 @@ public class AspectJExpressionPointcutTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testInvalidExpression() { |
|
|
|
void testInvalidExpression() { |
|
|
|
String expression = "execution(void org.springframework.beans.testfixture.beans.TestBean.setSomeNumber(Number) && args(Double)"; |
|
|
|
String expression = "execution(void org.springframework.beans.testfixture.beans.TestBean.setSomeNumber(Number) && args(Double)"; |
|
|
|
assertThatIllegalArgumentException().isThrownBy(getPointcut(expression)::getClassFilter); // call to getClassFilter forces resolution
|
|
|
|
assertThatIllegalArgumentException().isThrownBy(getPointcut(expression)::getClassFilter); // call to getClassFilter forces resolution
|
|
|
|
} |
|
|
|
} |
|
|
|
@ -274,7 +274,7 @@ public class AspectJExpressionPointcutTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testWithUnsupportedPointcutPrimitive() { |
|
|
|
void testWithUnsupportedPointcutPrimitive() { |
|
|
|
String expression = "call(int org.springframework.beans.testfixture.beans.TestBean.getAge())"; |
|
|
|
String expression = "call(int org.springframework.beans.testfixture.beans.TestBean.getAge())"; |
|
|
|
assertThatExceptionOfType(UnsupportedPointcutPrimitiveException.class) |
|
|
|
assertThatExceptionOfType(UnsupportedPointcutPrimitiveException.class) |
|
|
|
.isThrownBy(() -> getPointcut(expression).getClassFilter()) // call to getClassFilter forces resolution...
|
|
|
|
.isThrownBy(() -> getPointcut(expression).getClassFilter()) // call to getClassFilter forces resolution...
|
|
|
|
@ -282,14 +282,14 @@ public class AspectJExpressionPointcutTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testAndSubstitution() { |
|
|
|
void testAndSubstitution() { |
|
|
|
AspectJExpressionPointcut pc = getPointcut("execution(* *(..)) and args(String)"); |
|
|
|
AspectJExpressionPointcut pc = getPointcut("execution(* *(..)) and args(String)"); |
|
|
|
String expr = pc.getPointcutExpression().getPointcutExpression(); |
|
|
|
String expr = pc.getPointcutExpression().getPointcutExpression(); |
|
|
|
assertThat(expr).isEqualTo("execution(* *(..)) && args(String)"); |
|
|
|
assertThat(expr).isEqualTo("execution(* *(..)) && args(String)"); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testMultipleAndSubstitutions() { |
|
|
|
void testMultipleAndSubstitutions() { |
|
|
|
AspectJExpressionPointcut pc = getPointcut("execution(* *(..)) and args(String) and this(Object)"); |
|
|
|
AspectJExpressionPointcut pc = getPointcut("execution(* *(..)) and args(String) and this(Object)"); |
|
|
|
String expr = pc.getPointcutExpression().getPointcutExpression(); |
|
|
|
String expr = pc.getPointcutExpression().getPointcutExpression(); |
|
|
|
assertThat(expr).isEqualTo("execution(* *(..)) && args(String) && this(Object)"); |
|
|
|
assertThat(expr).isEqualTo("execution(* *(..)) && args(String) && this(Object)"); |
|
|
|
@ -302,7 +302,7 @@ public class AspectJExpressionPointcutTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testMatchGenericArgument() { |
|
|
|
void testMatchGenericArgument() { |
|
|
|
String expression = "execution(* set*(java.util.List<org.springframework.beans.testfixture.beans.TestBean>) )"; |
|
|
|
String expression = "execution(* set*(java.util.List<org.springframework.beans.testfixture.beans.TestBean>) )"; |
|
|
|
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut(); |
|
|
|
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut(); |
|
|
|
ajexp.setExpression(expression); |
|
|
|
ajexp.setExpression(expression); |
|
|
|
@ -321,7 +321,7 @@ public class AspectJExpressionPointcutTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testMatchVarargs() throws Exception { |
|
|
|
void testMatchVarargs() throws Exception { |
|
|
|
|
|
|
|
|
|
|
|
@SuppressWarnings("unused") |
|
|
|
@SuppressWarnings("unused") |
|
|
|
class MyTemplate { |
|
|
|
class MyTemplate { |
|
|
|
@ -347,19 +347,19 @@ public class AspectJExpressionPointcutTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testMatchAnnotationOnClassWithAtWithin() throws Exception { |
|
|
|
void testMatchAnnotationOnClassWithAtWithin() throws Exception { |
|
|
|
String expression = "@within(test.annotation.transaction.Tx)"; |
|
|
|
String expression = "@within(test.annotation.transaction.Tx)"; |
|
|
|
testMatchAnnotationOnClass(expression); |
|
|
|
testMatchAnnotationOnClass(expression); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testMatchAnnotationOnClassWithoutBinding() throws Exception { |
|
|
|
void testMatchAnnotationOnClassWithoutBinding() throws Exception { |
|
|
|
String expression = "within(@test.annotation.transaction.Tx *)"; |
|
|
|
String expression = "within(@test.annotation.transaction.Tx *)"; |
|
|
|
testMatchAnnotationOnClass(expression); |
|
|
|
testMatchAnnotationOnClass(expression); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testMatchAnnotationOnClassWithSubpackageWildcard() throws Exception { |
|
|
|
void testMatchAnnotationOnClassWithSubpackageWildcard() throws Exception { |
|
|
|
String expression = "within(@(test.annotation..*) *)"; |
|
|
|
String expression = "within(@(test.annotation..*) *)"; |
|
|
|
AspectJExpressionPointcut springAnnotatedPc = testMatchAnnotationOnClass(expression); |
|
|
|
AspectJExpressionPointcut springAnnotatedPc = testMatchAnnotationOnClass(expression); |
|
|
|
assertThat(springAnnotatedPc.matches(TestBean.class.getMethod("setName", String.class), TestBean.class)).isFalse(); |
|
|
|
assertThat(springAnnotatedPc.matches(TestBean.class.getMethod("setName", String.class), TestBean.class)).isFalse(); |
|
|
|
@ -371,7 +371,7 @@ public class AspectJExpressionPointcutTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testMatchAnnotationOnClassWithExactPackageWildcard() throws Exception { |
|
|
|
void testMatchAnnotationOnClassWithExactPackageWildcard() throws Exception { |
|
|
|
String expression = "within(@(test.annotation.transaction.*) *)"; |
|
|
|
String expression = "within(@(test.annotation.transaction.*) *)"; |
|
|
|
testMatchAnnotationOnClass(expression); |
|
|
|
testMatchAnnotationOnClass(expression); |
|
|
|
} |
|
|
|
} |
|
|
|
@ -389,7 +389,7 @@ public class AspectJExpressionPointcutTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testAnnotationOnMethodWithFQN() throws Exception { |
|
|
|
void testAnnotationOnMethodWithFQN() throws Exception { |
|
|
|
String expression = "@annotation(test.annotation.transaction.Tx)"; |
|
|
|
String expression = "@annotation(test.annotation.transaction.Tx)"; |
|
|
|
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut(); |
|
|
|
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut(); |
|
|
|
ajexp.setExpression(expression); |
|
|
|
ajexp.setExpression(expression); |
|
|
|
@ -403,7 +403,7 @@ public class AspectJExpressionPointcutTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testAnnotationOnCglibProxyMethod() throws Exception { |
|
|
|
void testAnnotationOnCglibProxyMethod() throws Exception { |
|
|
|
String expression = "@annotation(test.annotation.transaction.Tx)"; |
|
|
|
String expression = "@annotation(test.annotation.transaction.Tx)"; |
|
|
|
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut(); |
|
|
|
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut(); |
|
|
|
ajexp.setExpression(expression); |
|
|
|
ajexp.setExpression(expression); |
|
|
|
@ -416,7 +416,7 @@ public class AspectJExpressionPointcutTests { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testNotAnnotationOnCglibProxyMethod() throws Exception { |
|
|
|
void testNotAnnotationOnCglibProxyMethod() throws Exception { |
|
|
|
String expression = "!@annotation(test.annotation.transaction.Tx)"; |
|
|
|
String expression = "!@annotation(test.annotation.transaction.Tx)"; |
|
|
|
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut(); |
|
|
|
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut(); |
|
|
|
ajexp.setExpression(expression); |
|
|
|
ajexp.setExpression(expression); |
|
|
|
@ -428,7 +428,7 @@ public class AspectJExpressionPointcutTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testAnnotationOnDynamicProxyMethod() throws Exception { |
|
|
|
void testAnnotationOnDynamicProxyMethod() throws Exception { |
|
|
|
String expression = "@annotation(test.annotation.transaction.Tx)"; |
|
|
|
String expression = "@annotation(test.annotation.transaction.Tx)"; |
|
|
|
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut(); |
|
|
|
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut(); |
|
|
|
ajexp.setExpression(expression); |
|
|
|
ajexp.setExpression(expression); |
|
|
|
@ -440,7 +440,7 @@ public class AspectJExpressionPointcutTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testNotAnnotationOnDynamicProxyMethod() throws Exception { |
|
|
|
void testNotAnnotationOnDynamicProxyMethod() throws Exception { |
|
|
|
String expression = "!@annotation(test.annotation.transaction.Tx)"; |
|
|
|
String expression = "!@annotation(test.annotation.transaction.Tx)"; |
|
|
|
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut(); |
|
|
|
AspectJExpressionPointcut ajexp = new AspectJExpressionPointcut(); |
|
|
|
ajexp.setExpression(expression); |
|
|
|
ajexp.setExpression(expression); |
|
|
|
@ -452,7 +452,7 @@ public class AspectJExpressionPointcutTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testAnnotationOnMethodWithWildcard() throws Exception { |
|
|
|
void testAnnotationOnMethodWithWildcard() throws Exception { |
|
|
|
String expression = "execution(@(test.annotation..*) * *(..))"; |
|
|
|
String expression = "execution(@(test.annotation..*) * *(..))"; |
|
|
|
AspectJExpressionPointcut anySpringMethodAnnotation = new AspectJExpressionPointcut(); |
|
|
|
AspectJExpressionPointcut anySpringMethodAnnotation = new AspectJExpressionPointcut(); |
|
|
|
anySpringMethodAnnotation.setExpression(expression); |
|
|
|
anySpringMethodAnnotation.setExpression(expression); |
|
|
|
@ -468,7 +468,7 @@ public class AspectJExpressionPointcutTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testAnnotationOnMethodArgumentsWithFQN() throws Exception { |
|
|
|
void testAnnotationOnMethodArgumentsWithFQN() throws Exception { |
|
|
|
String expression = "@args(*, test.annotation.EmptySpringAnnotation))"; |
|
|
|
String expression = "@args(*, test.annotation.EmptySpringAnnotation))"; |
|
|
|
AspectJExpressionPointcut takesSpringAnnotatedArgument2 = new AspectJExpressionPointcut(); |
|
|
|
AspectJExpressionPointcut takesSpringAnnotatedArgument2 = new AspectJExpressionPointcut(); |
|
|
|
takesSpringAnnotatedArgument2.setExpression(expression); |
|
|
|
takesSpringAnnotatedArgument2.setExpression(expression); |
|
|
|
@ -497,7 +497,7 @@ public class AspectJExpressionPointcutTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testAnnotationOnMethodArgumentsWithWildcards() throws Exception { |
|
|
|
void testAnnotationOnMethodArgumentsWithWildcards() throws Exception { |
|
|
|
String expression = "execution(* *(*, @(test..*) *))"; |
|
|
|
String expression = "execution(* *(*, @(test..*) *))"; |
|
|
|
AspectJExpressionPointcut takesSpringAnnotatedArgument2 = new AspectJExpressionPointcut(); |
|
|
|
AspectJExpressionPointcut takesSpringAnnotatedArgument2 = new AspectJExpressionPointcut(); |
|
|
|
takesSpringAnnotatedArgument2.setExpression(expression); |
|
|
|
takesSpringAnnotatedArgument2.setExpression(expression); |
|
|
|
|