moving unit tests from .testsuite -> .aop
This commit is contained in:
parent
4b2a5a2383
commit
08f1be7f85
|
|
@ -13,11 +13,12 @@
|
||||||
* 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 junit.framework.TestCase;
|
import static org.junit.Assert.*;
|
||||||
|
|
||||||
import org.aspectj.lang.JoinPoint;
|
import org.aspectj.lang.JoinPoint;
|
||||||
|
import org.junit.Test;
|
||||||
import org.springframework.aop.aspectj.AspectJAdviceParameterNameDiscoverer.AmbiguousBindingException;
|
import org.springframework.aop.aspectj.AspectJAdviceParameterNameDiscoverer.AmbiguousBindingException;
|
||||||
|
|
||||||
import java.lang.reflect.Method;
|
import java.lang.reflect.Method;
|
||||||
|
|
@ -30,7 +31,7 @@ import java.lang.reflect.Method;
|
||||||
*
|
*
|
||||||
* @author Adrian Colyer
|
* @author Adrian Colyer
|
||||||
*/
|
*/
|
||||||
public class AspectJAdviceParameterNameDiscovererTests extends TestCase {
|
public class AspectJAdviceParameterNameDiscovererTests {
|
||||||
|
|
||||||
// methods to discover parameter names for
|
// methods to discover parameter names for
|
||||||
public void noArgs() {
|
public void noArgs() {
|
||||||
|
|
@ -73,58 +74,71 @@ public class AspectJAdviceParameterNameDiscovererTests extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testNoArgs() {
|
public void testNoArgs() {
|
||||||
assertParameterNames(getMethod("noArgs"), "execution(* *(..))", new String[0]);
|
assertParameterNames(getMethod("noArgs"), "execution(* *(..))", new String[0]);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testJoinPointOnly() {
|
public void testJoinPointOnly() {
|
||||||
assertParameterNames(getMethod("tjp"), "execution(* *(..))", new String[]{"thisJoinPoint"});
|
assertParameterNames(getMethod("tjp"), "execution(* *(..))", new String[]{"thisJoinPoint"});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testJoinPointStaticPartOnly() {
|
public void testJoinPointStaticPartOnly() {
|
||||||
assertParameterNames(getMethod("tjpsp"), "execution(* *(..))", new String[]{"thisJoinPointStaticPart"});
|
assertParameterNames(getMethod("tjpsp"), "execution(* *(..))", new String[]{"thisJoinPointStaticPart"});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testTwoJoinPoints() {
|
public void testTwoJoinPoints() {
|
||||||
assertException(getMethod("twoJoinPoints"), "foo()", IllegalStateException.class, "Failed to bind all argument names: 1 argument(s) could not be bound");
|
assertException(getMethod("twoJoinPoints"), "foo()", IllegalStateException.class, "Failed to bind all argument names: 1 argument(s) could not be bound");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testOneThrowable() {
|
public void testOneThrowable() {
|
||||||
assertParameterNames(getMethod("oneThrowable"), "foo()", null, "ex", new String[]{"ex"});
|
assertParameterNames(getMethod("oneThrowable"), "foo()", null, "ex", new String[]{"ex"});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testOneJPAndOneThrowable() {
|
public void testOneJPAndOneThrowable() {
|
||||||
assertParameterNames(getMethod("jpAndOneThrowable"), "foo()", null, "ex", new String[]{"thisJoinPoint", "ex"});
|
assertParameterNames(getMethod("jpAndOneThrowable"), "foo()", null, "ex", new String[]{"thisJoinPoint", "ex"});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testOneJPAndTwoThrowables() {
|
public void testOneJPAndTwoThrowables() {
|
||||||
assertException(getMethod("jpAndTwoThrowables"), "foo()", null, "ex", AmbiguousBindingException.class,
|
assertException(getMethod("jpAndTwoThrowables"), "foo()", null, "ex", AmbiguousBindingException.class,
|
||||||
"Binding of throwing parameter 'ex' is ambiguous: could be bound to argument 1 or argument 2");
|
"Binding of throwing parameter 'ex' is ambiguous: could be bound to argument 1 or argument 2");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testThrowableNoCandidates() {
|
public void testThrowableNoCandidates() {
|
||||||
assertException(getMethod("noArgs"), "foo()", null, "ex", IllegalStateException.class,
|
assertException(getMethod("noArgs"), "foo()", null, "ex", IllegalStateException.class,
|
||||||
"Not enough arguments in method to satisfy binding of returning and throwing variables");
|
"Not enough arguments in method to satisfy binding of returning and throwing variables");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testReturning() {
|
public void testReturning() {
|
||||||
assertParameterNames(getMethod("oneObject"), "foo()", "obj", null, new String[]{"obj"});
|
assertParameterNames(getMethod("oneObject"), "foo()", "obj", null, new String[]{"obj"});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAmbiguousReturning() {
|
public void testAmbiguousReturning() {
|
||||||
assertException(getMethod("twoObjects"), "foo()", "obj", null, AmbiguousBindingException.class,
|
assertException(getMethod("twoObjects"), "foo()", "obj", null, AmbiguousBindingException.class,
|
||||||
"Binding of returning parameter 'obj' is ambiguous, there are 2 candidates.");
|
"Binding of returning parameter 'obj' is ambiguous, there are 2 candidates.");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testReturningNoCandidates() {
|
public void testReturningNoCandidates() {
|
||||||
assertException(getMethod("noArgs"), "foo()", "obj", null, IllegalStateException.class,
|
assertException(getMethod("noArgs"), "foo()", "obj", null, IllegalStateException.class,
|
||||||
"Not enough arguments in method to satisfy binding of returning and throwing variables");
|
"Not enough arguments in method to satisfy binding of returning and throwing variables");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testThisBindingOneCandidate() {
|
public void testThisBindingOneCandidate() {
|
||||||
assertParameterNames(getMethod("oneObject"), "this(x)", new String[]{"x"});
|
assertParameterNames(getMethod("oneObject"), "this(x)", new String[]{"x"});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testThisBindingWithAlternateTokenizations() {
|
public void testThisBindingWithAlternateTokenizations() {
|
||||||
assertParameterNames(getMethod("oneObject"), "this( x )", new String[]{"x"});
|
assertParameterNames(getMethod("oneObject"), "this( x )", new String[]{"x"});
|
||||||
assertParameterNames(getMethod("oneObject"), "this( x)", new String[]{"x"});
|
assertParameterNames(getMethod("oneObject"), "this( x)", new String[]{"x"});
|
||||||
|
|
@ -133,11 +147,13 @@ public class AspectJAdviceParameterNameDiscovererTests extends TestCase {
|
||||||
assertParameterNames(getMethod("oneObject"), "foo() && this(x)", new String[]{"x"});
|
assertParameterNames(getMethod("oneObject"), "foo() && this(x)", new String[]{"x"});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testThisBindingTwoCandidates() {
|
public void testThisBindingTwoCandidates() {
|
||||||
assertException(getMethod("oneObject"), "this(x) || this(y)", AmbiguousBindingException.class,
|
assertException(getMethod("oneObject"), "this(x) || this(y)", AmbiguousBindingException.class,
|
||||||
"Found 2 candidate this(), target() or args() variables but only one unbound argument slot");
|
"Found 2 candidate this(), target() or args() variables but only one unbound argument slot");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testThisBindingWithBadPointcutExpressions() {
|
public void testThisBindingWithBadPointcutExpressions() {
|
||||||
assertException(getMethod("oneObject"), "this(", IllegalStateException.class,
|
assertException(getMethod("oneObject"), "this(", IllegalStateException.class,
|
||||||
"Failed to bind all argument names: 1 argument(s) could not be bound");
|
"Failed to bind all argument names: 1 argument(s) could not be bound");
|
||||||
|
|
@ -145,10 +161,12 @@ public class AspectJAdviceParameterNameDiscovererTests extends TestCase {
|
||||||
"Failed to bind all argument names: 1 argument(s) could not be bound");
|
"Failed to bind all argument names: 1 argument(s) could not be bound");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testTargetBindingOneCandidate() {
|
public void testTargetBindingOneCandidate() {
|
||||||
assertParameterNames(getMethod("oneObject"), "target(x)", new String[]{"x"});
|
assertParameterNames(getMethod("oneObject"), "target(x)", new String[]{"x"});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testTargetBindingWithAlternateTokenizations() {
|
public void testTargetBindingWithAlternateTokenizations() {
|
||||||
assertParameterNames(getMethod("oneObject"), "target( x )", new String[]{"x"});
|
assertParameterNames(getMethod("oneObject"), "target( x )", new String[]{"x"});
|
||||||
assertParameterNames(getMethod("oneObject"), "target( x)", new String[]{"x"});
|
assertParameterNames(getMethod("oneObject"), "target( x)", new String[]{"x"});
|
||||||
|
|
@ -157,11 +175,13 @@ public class AspectJAdviceParameterNameDiscovererTests extends TestCase {
|
||||||
assertParameterNames(getMethod("oneObject"), "foo() && target(x)", new String[]{"x"});
|
assertParameterNames(getMethod("oneObject"), "foo() && target(x)", new String[]{"x"});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testTargetBindingTwoCandidates() {
|
public void testTargetBindingTwoCandidates() {
|
||||||
assertException(getMethod("oneObject"), "target(x) || target(y)", AmbiguousBindingException.class,
|
assertException(getMethod("oneObject"), "target(x) || target(y)", AmbiguousBindingException.class,
|
||||||
"Found 2 candidate this(), target() or args() variables but only one unbound argument slot");
|
"Found 2 candidate this(), target() or args() variables but only one unbound argument slot");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testTargetBindingWithBadPointcutExpressions() {
|
public void testTargetBindingWithBadPointcutExpressions() {
|
||||||
assertException(getMethod("oneObject"), "target(", IllegalStateException.class,
|
assertException(getMethod("oneObject"), "target(", IllegalStateException.class,
|
||||||
"Failed to bind all argument names: 1 argument(s) could not be bound");
|
"Failed to bind all argument names: 1 argument(s) could not be bound");
|
||||||
|
|
@ -169,49 +189,60 @@ public class AspectJAdviceParameterNameDiscovererTests extends TestCase {
|
||||||
"Failed to bind all argument names: 1 argument(s) could not be bound");
|
"Failed to bind all argument names: 1 argument(s) could not be bound");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testArgsBindingOneObject() {
|
public void testArgsBindingOneObject() {
|
||||||
assertParameterNames(getMethod("oneObject"), "args(x)", new String[]{"x"});
|
assertParameterNames(getMethod("oneObject"), "args(x)", new String[]{"x"});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testArgsBindingOneObjectTwoCandidates() {
|
public void testArgsBindingOneObjectTwoCandidates() {
|
||||||
assertException(getMethod("oneObject"), "args(x,y)", AmbiguousBindingException.class,
|
assertException(getMethod("oneObject"), "args(x,y)", AmbiguousBindingException.class,
|
||||||
"Found 2 candidate this(), target() or args() variables but only one unbound argument slot");
|
"Found 2 candidate this(), target() or args() variables but only one unbound argument slot");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testAmbiguousArgsBinding() {
|
public void testAmbiguousArgsBinding() {
|
||||||
assertException(getMethod("twoObjects"), "args(x,y)", AmbiguousBindingException.class,
|
assertException(getMethod("twoObjects"), "args(x,y)", AmbiguousBindingException.class,
|
||||||
"Still 2 unbound args at this(),target(),args() binding stage, with no way to determine between them");
|
"Still 2 unbound args at this(),target(),args() binding stage, with no way to determine between them");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testArgsOnePrimitive() {
|
public void testArgsOnePrimitive() {
|
||||||
assertParameterNames(getMethod("onePrimitive"), "args(count)", new String[]{"count"});
|
assertParameterNames(getMethod("onePrimitive"), "args(count)", new String[]{"count"});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testArgsOnePrimitiveOneObject() {
|
public void testArgsOnePrimitiveOneObject() {
|
||||||
assertException(getMethod("oneObjectOnePrimitive"), "args(count,obj)", AmbiguousBindingException.class,
|
assertException(getMethod("oneObjectOnePrimitive"), "args(count,obj)", AmbiguousBindingException.class,
|
||||||
"Found 2 candidate variable names but only one candidate binding slot when matching primitive args");
|
"Found 2 candidate variable names but only one candidate binding slot when matching primitive args");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@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
|
||||||
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
|
||||||
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
|
||||||
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
|
||||||
public void testReferenceBinding() {
|
public void testReferenceBinding() {
|
||||||
assertParameterNames(getMethod("onePrimitive"),"somepc(foo)",new String[] {"foo"});
|
assertParameterNames(getMethod("onePrimitive"),"somepc(foo)",new String[] {"foo"});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
public void testReferenceBindingWithAlternateTokenizations() {
|
public void testReferenceBindingWithAlternateTokenizations() {
|
||||||
assertParameterNames(getMethod("onePrimitive"),"call(bar *) && somepc(foo)",new String[] {"foo"});
|
assertParameterNames(getMethod("onePrimitive"),"call(bar *) && somepc(foo)",new String[] {"foo"});
|
||||||
assertParameterNames(getMethod("onePrimitive"),"somepc ( foo )",new String[] {"foo"});
|
assertParameterNames(getMethod("onePrimitive"),"somepc ( foo )",new String[] {"foo"});
|
||||||
|
|
@ -261,11 +292,11 @@ public class AspectJAdviceParameterNameDiscovererTests extends TestCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void assertException(Method m, String pointcut, Class exceptionType, String message) {
|
protected void assertException(Method m, String pointcut, Class<?> exceptionType, String message) {
|
||||||
assertException(m, pointcut, null, null, exceptionType, message);
|
assertException(m, pointcut, null, null, exceptionType, message);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void assertException(Method m, String pointcut, String returning, String throwing, Class exceptionType, String message) {
|
protected void assertException(Method m, 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);
|
||||||
discoverer.setReturningName(returning);
|
discoverer.setReturningName(returning);
|
||||||
Loading…
Reference in New Issue