|
|
|
@ -31,10 +31,10 @@ import org.springframework.aop.MethodMatcher; |
|
|
|
import org.springframework.aop.Pointcut; |
|
|
|
import org.springframework.aop.Pointcut; |
|
|
|
import org.springframework.aop.framework.ProxyFactory; |
|
|
|
import org.springframework.aop.framework.ProxyFactory; |
|
|
|
import org.springframework.aop.support.DefaultPointcutAdvisor; |
|
|
|
import org.springframework.aop.support.DefaultPointcutAdvisor; |
|
|
|
import org.springframework.beans.test.fixtures.beans.IOther; |
|
|
|
import org.springframework.beans.testfixture.beans.IOther; |
|
|
|
import org.springframework.beans.test.fixtures.beans.ITestBean; |
|
|
|
import org.springframework.beans.testfixture.beans.ITestBean; |
|
|
|
import org.springframework.beans.test.fixtures.beans.TestBean; |
|
|
|
import org.springframework.beans.testfixture.beans.TestBean; |
|
|
|
import org.springframework.beans.test.fixtures.beans.subpkg.DeepBean; |
|
|
|
import org.springframework.beans.testfixture.beans.subpkg.DeepBean; |
|
|
|
|
|
|
|
|
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
import static org.assertj.core.api.Assertions.assertThat; |
|
|
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType; |
|
|
|
import static org.assertj.core.api.Assertions.assertThatExceptionOfType; |
|
|
|
@ -67,7 +67,7 @@ public class AspectJExpressionPointcutTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testMatchExplicit() { |
|
|
|
public void testMatchExplicit() { |
|
|
|
String expression = "execution(int org.springframework.beans.test.fixtures.beans.TestBean.getAge())"; |
|
|
|
String expression = "execution(int org.springframework.beans.testfixture.beans.TestBean.getAge())"; |
|
|
|
|
|
|
|
|
|
|
|
Pointcut pointcut = getPointcut(expression); |
|
|
|
Pointcut pointcut = getPointcut(expression); |
|
|
|
ClassFilter classFilter = pointcut.getClassFilter(); |
|
|
|
ClassFilter classFilter = pointcut.getClassFilter(); |
|
|
|
@ -117,8 +117,8 @@ public class AspectJExpressionPointcutTests { |
|
|
|
* @param which this or target |
|
|
|
* @param which this or target |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
private void testThisOrTarget(String which) throws SecurityException, NoSuchMethodException { |
|
|
|
private void testThisOrTarget(String which) throws SecurityException, NoSuchMethodException { |
|
|
|
String matchesTestBean = which + "(org.springframework.beans.test.fixtures.beans.TestBean)"; |
|
|
|
String matchesTestBean = which + "(org.springframework.beans.testfixture.beans.TestBean)"; |
|
|
|
String matchesIOther = which + "(org.springframework.beans.test.fixtures.beans.IOther)"; |
|
|
|
String matchesIOther = which + "(org.springframework.beans.testfixture.beans.IOther)"; |
|
|
|
AspectJExpressionPointcut testBeanPc = new AspectJExpressionPointcut(); |
|
|
|
AspectJExpressionPointcut testBeanPc = new AspectJExpressionPointcut(); |
|
|
|
testBeanPc.setExpression(matchesTestBean); |
|
|
|
testBeanPc.setExpression(matchesTestBean); |
|
|
|
|
|
|
|
|
|
|
|
@ -142,7 +142,7 @@ public class AspectJExpressionPointcutTests { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void testWithinPackage(boolean matchSubpackages) throws SecurityException, NoSuchMethodException { |
|
|
|
private void testWithinPackage(boolean matchSubpackages) throws SecurityException, NoSuchMethodException { |
|
|
|
String withinBeansPackage = "within(org.springframework.beans.test.fixtures.beans."; |
|
|
|
String withinBeansPackage = "within(org.springframework.beans.testfixture.beans."; |
|
|
|
// Subpackages are matched by **
|
|
|
|
// Subpackages are matched by **
|
|
|
|
if (matchSubpackages) { |
|
|
|
if (matchSubpackages) { |
|
|
|
withinBeansPackage += "."; |
|
|
|
withinBeansPackage += "."; |
|
|
|
@ -187,7 +187,7 @@ public class AspectJExpressionPointcutTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testMatchWithArgs() throws Exception { |
|
|
|
public void testMatchWithArgs() throws Exception { |
|
|
|
String expression = "execution(void org.springframework.beans.test.fixtures.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); |
|
|
|
ClassFilter classFilter = pointcut.getClassFilter(); |
|
|
|
ClassFilter classFilter = pointcut.getClassFilter(); |
|
|
|
@ -206,7 +206,7 @@ public class AspectJExpressionPointcutTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testSimpleAdvice() { |
|
|
|
public void testSimpleAdvice() { |
|
|
|
String expression = "execution(int org.springframework.beans.test.fixtures.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); |
|
|
|
|
|
|
|
|
|
|
|
@ -219,7 +219,7 @@ public class AspectJExpressionPointcutTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testDynamicMatchingProxy() { |
|
|
|
public void testDynamicMatchingProxy() { |
|
|
|
String expression = "execution(void org.springframework.beans.test.fixtures.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); |
|
|
|
|
|
|
|
|
|
|
|
@ -233,7 +233,7 @@ public class AspectJExpressionPointcutTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testInvalidExpression() { |
|
|
|
public void testInvalidExpression() { |
|
|
|
String expression = "execution(void org.springframework.beans.test.fixtures.beans.TestBean.setSomeNumber(Number) && args(Double)"; |
|
|
|
String expression = "execution(void org.springframework.beans.testfixture.beans.TestBean.setSomeNumber(Number) && args(Double)"; |
|
|
|
assertThatIllegalArgumentException().isThrownBy( |
|
|
|
assertThatIllegalArgumentException().isThrownBy( |
|
|
|
getPointcut(expression)::getClassFilter); // call to getClassFilter forces resolution
|
|
|
|
getPointcut(expression)::getClassFilter); // call to getClassFilter forces resolution
|
|
|
|
} |
|
|
|
} |
|
|
|
@ -264,7 +264,7 @@ public class AspectJExpressionPointcutTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testWithUnsupportedPointcutPrimitive() { |
|
|
|
public void testWithUnsupportedPointcutPrimitive() { |
|
|
|
String expression = "call(int org.springframework.beans.test.fixtures.beans.TestBean.getAge())"; |
|
|
|
String expression = "call(int org.springframework.beans.testfixture.beans.TestBean.getAge())"; |
|
|
|
assertThatExceptionOfType(UnsupportedPointcutPrimitiveException.class).isThrownBy(() -> |
|
|
|
assertThatExceptionOfType(UnsupportedPointcutPrimitiveException.class).isThrownBy(() -> |
|
|
|
getPointcut(expression).getClassFilter()) // call to getClassFilter forces resolution...
|
|
|
|
getPointcut(expression).getClassFilter()) // call to getClassFilter forces resolution...
|
|
|
|
.satisfies(ex -> assertThat(ex.getUnsupportedPrimitive()).isEqualTo(PointcutPrimitive.CALL)); |
|
|
|
.satisfies(ex -> assertThat(ex.getUnsupportedPrimitive()).isEqualTo(PointcutPrimitive.CALL)); |
|
|
|
|