|
|
|
@ -1,5 +1,5 @@ |
|
|
|
/* |
|
|
|
/* |
|
|
|
* Copyright 2002-2017 the original author or authors. |
|
|
|
* Copyright 2002-2018 the original author or authors. |
|
|
|
* |
|
|
|
* |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License"); |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
* you may not use this file except in compliance with the License. |
|
|
|
@ -13,6 +13,7 @@ |
|
|
|
* See the License for the specific language governing permissions and |
|
|
|
* See the License for the specific language governing permissions and |
|
|
|
* limitations under the License. |
|
|
|
* limitations under the License. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.aop.aspectj; |
|
|
|
package org.springframework.aop.aspectj; |
|
|
|
|
|
|
|
|
|
|
|
import java.lang.reflect.Method; |
|
|
|
import java.lang.reflect.Method; |
|
|
|
@ -34,47 +35,6 @@ import static org.junit.Assert.*; |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class AspectJAdviceParameterNameDiscovererTests { |
|
|
|
public class AspectJAdviceParameterNameDiscovererTests { |
|
|
|
|
|
|
|
|
|
|
|
// methods to discover parameter names for
|
|
|
|
|
|
|
|
public void noArgs() { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void tjp(JoinPoint jp) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void tjpsp(JoinPoint.StaticPart tjpsp) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void twoJoinPoints(JoinPoint jp1, JoinPoint jp2) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void oneThrowable(Exception ex) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void jpAndOneThrowable(JoinPoint jp, Exception ex) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void jpAndTwoThrowables(JoinPoint jp, Exception ex, Error err) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void oneObject(Object x) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void twoObjects(Object x, Object y) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void onePrimitive(int x) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void oneObjectOnePrimitive(Object x, int y) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void oneThrowableOnePrimitive(Throwable x, int y) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void theBigOne(JoinPoint jp, Throwable x, int y, Object foo) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testNoArgs() { |
|
|
|
public void testNoArgs() { |
|
|
|
assertParameterNames(getMethod("noArgs"), "execution(* *(..))", new String[0]); |
|
|
|
assertParameterNames(getMethod("noArgs"), "execution(* *(..))", new String[0]); |
|
|
|
@ -221,22 +181,26 @@ public class AspectJAdviceParameterNameDiscovererTests { |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testThisAndPrimitive() { |
|
|
|
public void testThisAndPrimitive() { |
|
|
|
assertParameterNames(getMethod("oneObjectOnePrimitive"), "args(count) && this(obj)", new String[] {"obj", "count"}); |
|
|
|
assertParameterNames(getMethod("oneObjectOnePrimitive"), "args(count) && this(obj)", |
|
|
|
|
|
|
|
new String[] {"obj", "count"}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testTargetAndPrimitive() { |
|
|
|
public void testTargetAndPrimitive() { |
|
|
|
assertParameterNames(getMethod("oneObjectOnePrimitive"), "args(count) && target(obj)", new String[] {"obj", "count"}); |
|
|
|
assertParameterNames(getMethod("oneObjectOnePrimitive"), "args(count) && target(obj)", |
|
|
|
|
|
|
|
new String[] {"obj", "count"}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testThrowingAndPrimitive() { |
|
|
|
public void testThrowingAndPrimitive() { |
|
|
|
assertParameterNames(getMethod("oneThrowableOnePrimitive"), "args(count)", null, "ex", new String[] {"ex", "count"}); |
|
|
|
assertParameterNames(getMethod("oneThrowableOnePrimitive"), "args(count)", null, "ex", |
|
|
|
|
|
|
|
new String[] {"ex", "count"}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
public void testAllTogetherNow() { |
|
|
|
public void testAllTogetherNow() { |
|
|
|
assertParameterNames(getMethod("theBigOne"), "this(foo) && args(x)", null, "ex", new String[] {"thisJoinPoint", "ex", "x", "foo"}); |
|
|
|
assertParameterNames(getMethod("theBigOne"), "this(foo) && args(x)", null, "ex", |
|
|
|
|
|
|
|
new String[] {"thisJoinPoint", "ex", "x", "foo"}); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
@Test |
|
|
|
@ -253,8 +217,8 @@ public class AspectJAdviceParameterNameDiscovererTests { |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected Method getMethod(String name) { |
|
|
|
protected Method getMethod(String name) { |
|
|
|
// assumes no overloading of test methods...
|
|
|
|
// Assumes no overloading of test methods...
|
|
|
|
Method[] candidates = this.getClass().getMethods(); |
|
|
|
Method[] candidates = getClass().getMethods(); |
|
|
|
for (Method candidate : candidates) { |
|
|
|
for (Method candidate : candidates) { |
|
|
|
if (candidate.getName().equals(name)) { |
|
|
|
if (candidate.getName().equals(name)) { |
|
|
|
return candidate; |
|
|
|
return candidate; |
|
|
|
@ -268,8 +232,8 @@ public class AspectJAdviceParameterNameDiscovererTests { |
|
|
|
assertParameterNames(method, pointcut, null, null, parameterNames); |
|
|
|
assertParameterNames(method, pointcut, null, null, parameterNames); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected void assertParameterNames(Method method, String pointcut, String returning, String throwing, |
|
|
|
protected void assertParameterNames( |
|
|
|
String[] parameterNames) { |
|
|
|
Method method, String pointcut, String returning, String throwing, String[] parameterNames) { |
|
|
|
|
|
|
|
|
|
|
|
assertEquals("bad test specification, must have same number of parameter names as method arguments", |
|
|
|
assertEquals("bad test specification, must have same number of parameter names as method arguments", |
|
|
|
method.getParameterCount(), parameterNames.length); |
|
|
|
method.getParameterCount(), parameterNames.length); |
|
|
|
@ -300,8 +264,8 @@ public class AspectJAdviceParameterNameDiscovererTests { |
|
|
|
assertException(method, pointcut, null, null, exceptionType, message); |
|
|
|
assertException(method, pointcut, null, null, exceptionType, message); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
protected void assertException(Method method, String pointcut, String returning, String throwing, |
|
|
|
protected void assertException( |
|
|
|
Class<?> exceptionType, String message) { |
|
|
|
Method method, String pointcut, String returning, String throwing, Class<?> exceptionType, String message) { |
|
|
|
|
|
|
|
|
|
|
|
AspectJAdviceParameterNameDiscoverer discoverer = new AspectJAdviceParameterNameDiscoverer(pointcut); |
|
|
|
AspectJAdviceParameterNameDiscoverer discoverer = new AspectJAdviceParameterNameDiscoverer(pointcut); |
|
|
|
discoverer.setRaiseExceptions(true); |
|
|
|
discoverer.setRaiseExceptions(true); |
|
|
|
@ -333,4 +297,46 @@ public class AspectJAdviceParameterNameDiscovererTests { |
|
|
|
return sb.toString(); |
|
|
|
return sb.toString(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// Methods to discover parameter names for
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void noArgs() { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void tjp(JoinPoint jp) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void tjpsp(JoinPoint.StaticPart tjpsp) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void twoJoinPoints(JoinPoint jp1, JoinPoint jp2) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void oneThrowable(Exception ex) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void jpAndOneThrowable(JoinPoint jp, Exception ex) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void jpAndTwoThrowables(JoinPoint jp, Exception ex, Error err) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void oneObject(Object x) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void twoObjects(Object x, Object y) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void onePrimitive(int x) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void oneObjectOnePrimitive(Object x, int y) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void oneThrowableOnePrimitive(Throwable x, int y) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public void theBigOne(JoinPoint jp, Throwable x, int y, Object foo) { |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|