From 90e41018152ca4f04e4442e5fae02ee2b97c2a61 Mon Sep 17 00:00:00 2001 From: acolyer Date: Mon, 25 Apr 2005 16:14:07 +0000 Subject: test cases for @AspectJ visitors --- tests/java5/ataspectj/SimpleBefore.java | 2 +- tests/java5/ataspectj/annotationGen/APointcut.java | 13 ++ .../ataspectj/annotationGen/AdviceInAClass.java | 8 ++ .../annotationGen/AfterReturningWithBadPCut.java | 9 ++ .../annotationGen/BadParameterBinding.java | 18 +++ tests/java5/ataspectj/annotationGen/BasicAdvice.aj | 122 ++++++++++++++++ .../annotationGen/BeforeWithBadReturn.java | 9 ++ .../ataspectj/annotationGen/InnerAspectAspect.aj | 15 ++ .../ataspectj/annotationGen/InnerAspectClass.aj | 15 ++ .../ataspectj/annotationGen/PerCflowAspect.aj | 20 +++ .../ataspectj/annotationGen/PerCflowbelowAspect.aj | 19 +++ .../ataspectj/annotationGen/PerTargetAspect.aj | 21 +++ .../java5/ataspectj/annotationGen/PerThisAspect.aj | 19 +++ .../ataspectj/annotationGen/PerTypeWithinAspect.aj | 13 ++ .../annotationGen/PointcutAssortment.java | 42 ++++++ .../ataspectj/annotationGen/PointcutModifiers.aj | 45 ++++++ .../ataspectj/annotationGen/PointcutsWithParams.aj | 23 +++ .../ataspectj/annotationGen/PrivilegedAspect.aj | 16 +++ .../ataspectj/annotationGen/ReferencePointcuts.aj | 20 +++ .../ataspectj/annotationGen/Simple14Aspect.aj | 1 + .../annotationGen/Simple14AspectTest.java | 11 ++ .../annotationGen/SimpleAnnotatedAspect.aj | 13 ++ .../java5/ataspectj/annotationGen/SimpleAspect.aj | 13 ++ .../ataspectj/annotationGen/SimplePointcut.aj | 29 ++++ .../annotationGen/TwoForThePriceOfOne.java | 10 ++ .../java5/ataspectj/ataspectj/PrecedenceTest.java | 6 +- .../java5/ataspectj/ataspectj/XXJoinPointTest.java | 14 +- tests/java5/ataspectj/coverage/Test040.java | 1 + tests/java5/ataspectj/coverage/Test041.java | 1 + tests/src/org/aspectj/systemtest/AllTests.java | 1 - tests/src/org/aspectj/systemtest/AllTests15.java | 2 + .../ajc150/ataspectj/AtAjAnnotationGenTests.java | 126 +++++++++++++++++ .../systemtest/ajc150/ataspectj/atajc150-tests.xml | 157 ++++++++++++++++++++- .../ajc150/ataspectj/coverage/coverage.xml | 51 ++++--- 34 files changed, 850 insertions(+), 35 deletions(-) create mode 100644 tests/java5/ataspectj/annotationGen/APointcut.java create mode 100644 tests/java5/ataspectj/annotationGen/AdviceInAClass.java create mode 100644 tests/java5/ataspectj/annotationGen/AfterReturningWithBadPCut.java create mode 100644 tests/java5/ataspectj/annotationGen/BadParameterBinding.java create mode 100644 tests/java5/ataspectj/annotationGen/BasicAdvice.aj create mode 100644 tests/java5/ataspectj/annotationGen/BeforeWithBadReturn.java create mode 100644 tests/java5/ataspectj/annotationGen/InnerAspectAspect.aj create mode 100644 tests/java5/ataspectj/annotationGen/InnerAspectClass.aj create mode 100644 tests/java5/ataspectj/annotationGen/PerCflowAspect.aj create mode 100644 tests/java5/ataspectj/annotationGen/PerCflowbelowAspect.aj create mode 100644 tests/java5/ataspectj/annotationGen/PerTargetAspect.aj create mode 100644 tests/java5/ataspectj/annotationGen/PerThisAspect.aj create mode 100644 tests/java5/ataspectj/annotationGen/PerTypeWithinAspect.aj create mode 100644 tests/java5/ataspectj/annotationGen/PointcutAssortment.java create mode 100644 tests/java5/ataspectj/annotationGen/PointcutModifiers.aj create mode 100644 tests/java5/ataspectj/annotationGen/PointcutsWithParams.aj create mode 100644 tests/java5/ataspectj/annotationGen/PrivilegedAspect.aj create mode 100644 tests/java5/ataspectj/annotationGen/ReferencePointcuts.aj create mode 100644 tests/java5/ataspectj/annotationGen/Simple14Aspect.aj create mode 100644 tests/java5/ataspectj/annotationGen/Simple14AspectTest.java create mode 100644 tests/java5/ataspectj/annotationGen/SimpleAnnotatedAspect.aj create mode 100644 tests/java5/ataspectj/annotationGen/SimpleAspect.aj create mode 100644 tests/java5/ataspectj/annotationGen/SimplePointcut.aj create mode 100644 tests/java5/ataspectj/annotationGen/TwoForThePriceOfOne.java create mode 100644 tests/src/org/aspectj/systemtest/ajc150/ataspectj/AtAjAnnotationGenTests.java diff --git a/tests/java5/ataspectj/SimpleBefore.java b/tests/java5/ataspectj/SimpleBefore.java index 2327881b4..8b5019f94 100644 --- a/tests/java5/ataspectj/SimpleBefore.java +++ b/tests/java5/ataspectj/SimpleBefore.java @@ -14,7 +14,7 @@ public class SimpleBefore { X.s.append("2"); } - @Aspect("issingleton") + @Aspect("issingleton()") public static class X { public static StringBuffer s = new StringBuffer(""); diff --git a/tests/java5/ataspectj/annotationGen/APointcut.java b/tests/java5/ataspectj/annotationGen/APointcut.java new file mode 100644 index 000000000..32d504dfd --- /dev/null +++ b/tests/java5/ataspectj/annotationGen/APointcut.java @@ -0,0 +1,13 @@ +import org.aspectj.lang.reflect.*; + +public class APointcut { + + @org.aspectj.lang.annotation.Pointcut("execution(* *.*(..))") + void myPointcut() {}; + + public static void main(String[] args) throws Exception { + AjType myType = AjTypeSystem.getAjType(APointcut.class); + Pointcut pc = myType.getDeclaredPointcut("myPointcut"); + } + +} \ No newline at end of file diff --git a/tests/java5/ataspectj/annotationGen/AdviceInAClass.java b/tests/java5/ataspectj/annotationGen/AdviceInAClass.java new file mode 100644 index 000000000..9929781cd --- /dev/null +++ b/tests/java5/ataspectj/annotationGen/AdviceInAClass.java @@ -0,0 +1,8 @@ +import org.aspectj.lang.annotation.Before; + +public class AdviceInAClass { + + @Before("execution(* *(..))") + public void doSomething() {} + +} \ No newline at end of file diff --git a/tests/java5/ataspectj/annotationGen/AfterReturningWithBadPCut.java b/tests/java5/ataspectj/annotationGen/AfterReturningWithBadPCut.java new file mode 100644 index 000000000..6c36178bf --- /dev/null +++ b/tests/java5/ataspectj/annotationGen/AfterReturningWithBadPCut.java @@ -0,0 +1,9 @@ +import org.aspectj.lang.annotation.*; + +@Aspect +public class AfterReturningWithBadPCut { + + @AfterReturning("excution(* *.*(..))") + public void logExit() {} + +} \ No newline at end of file diff --git a/tests/java5/ataspectj/annotationGen/BadParameterBinding.java b/tests/java5/ataspectj/annotationGen/BadParameterBinding.java new file mode 100644 index 000000000..8e4c2e58f --- /dev/null +++ b/tests/java5/ataspectj/annotationGen/BadParameterBinding.java @@ -0,0 +1,18 @@ +import org.aspectj.lang.annotation.*; + +@Aspect +public class BadParameterBinding { + + @SuppressAjWarnings + @Before("execution(* *(..)) && this(bpb)") + public void logEntry(BadParameterBinding bpb) {} + + @SuppressAjWarnings + @AfterReturning("execution(* *(..)) && this(bpb)") + public void logExit() {} + + @SuppressAjWarnings + @AfterThrowing("call(* TheUnknownType.*(..))") + public void logException() {} + +} \ No newline at end of file diff --git a/tests/java5/ataspectj/annotationGen/BasicAdvice.aj b/tests/java5/ataspectj/annotationGen/BasicAdvice.aj new file mode 100644 index 000000000..04fb00be7 --- /dev/null +++ b/tests/java5/ataspectj/annotationGen/BasicAdvice.aj @@ -0,0 +1,122 @@ + +import java.lang.reflect.Method; +import org.aspectj.lang.annotation.*; + +public aspect BasicAdvice { + + @SuppressAjWarnings + before() : execution(* *.*(..)) { + // + } + + @SuppressAjWarnings + after() : call(* Integer.*(..)) { + + } + + @SuppressAjWarnings + after() returning : get(String *) { + + } + + @SuppressAjWarnings + after() returning(String strVal) : get(String *) { + + } + + @SuppressAjWarnings + after() throwing : execution(* *.*(..)) { + + } + + @SuppressAjWarnings + after() throwing(RuntimeException ex) : execution(* *.*(..)) { + + } + + @SuppressAjWarnings + void around() : set(* foo) { + proceed(); + } + + private static int adviceCount = 0; + + public static void main(String[] args) { + Method[] methods = BasicAdvice.class.getDeclaredMethods(); + for (Method method : methods) { + adviceCount++; + if (method.getName().startsWith("ajc$before$")) { + checkBefore(method); + } else if (method.getName().startsWith("ajc$after$")) { + checkAfter(method); + } else if (method.getName().startsWith("ajc$afterReturning$")) { + checkAfterReturning(method); + } else if (method.getName().startsWith("ajc$afterThrowing$")) { + checkAfterThrowing(method); + } else if (method.getName().startsWith("ajc$around$")) { + if (!method.getName().endsWith("proceed")) { + checkAround(method); + } else { + adviceCount--; + } + } else { + adviceCount--; + } + } + if (adviceCount != 7) throw new RuntimeException("Expected 7 advice methods, found " + adviceCount); + } + + private static void checkBefore(Method method) { + assertTrue("expecting 2 annotations",method.getAnnotations().length == 2); + Before beforeAnnotation = method.getAnnotation(Before.class); + assertTrue("expecting execution(* *.*(..))",beforeAnnotation.value().equals("execution(* *.*(..))")); + } + + private static void checkAfter(Method method) { + assertTrue("expecting 2 annotations",method.getAnnotations().length == 2); + After afterAnnotation = method.getAnnotation(After.class); + assertTrue("expecting call(* Integer.*(..))",afterAnnotation.value().equals("call(* Integer.*(..))")); + } + + private static void checkAfterReturning(Method method) { + assertTrue("expecting 2 annotations",method.getAnnotations().length == 2); + AfterReturning afterAnnotation = method.getAnnotation(AfterReturning.class); + if (method.getParameterTypes().length == 1) { + // form with returning arg + assertTrue("expecting get(String *)",afterAnnotation.pointcut().equals("get(String *)")); + assertTrue("expecting empty",afterAnnotation.value().equals("")); + assertTrue("expecting strVal",afterAnnotation.returning().equals("strVal")); + } else { + // form without returning arg + assertTrue("expecting get(String *)",afterAnnotation.pointcut().equals("get(String *)")); + assertTrue("expecting empty",afterAnnotation.value().equals("")); + assertTrue("expecting empty returning",afterAnnotation.returning().equals("")); + } + } + + private static void checkAfterThrowing(Method method) { + assertTrue("expecting 2 annotations",method.getAnnotations().length == 2); + AfterThrowing afterAnnotation = method.getAnnotation(AfterThrowing.class); + if (method.getParameterTypes().length == 1) { + // form with returning arg + assertTrue("expecting execution(* *.*(..))",afterAnnotation.pointcut().equals("execution(* *.*(..))")); + assertTrue("expecting empty",afterAnnotation.value().equals("")); + assertTrue("expecting ex",afterAnnotation.throwing().equals("ex")); + } else { + // form without returning arg + assertTrue("expecting execution(* *.*(..))",afterAnnotation.pointcut().equals("execution(* *.*(..))")); + assertTrue("expecting empty",afterAnnotation.value().equals("")); + assertTrue("expecting empty throwing",afterAnnotation.throwing().equals("")); + } + } + + private static void checkAround(Method method) { + assertTrue("expecting 2 annotations",method.getAnnotations().length == 2); + Around aroundAnnotation = method.getAnnotation(Around.class); + assertTrue("expecting set(* foo)",aroundAnnotation.value().equals("set(* foo)")); + } + + private static void assertTrue(String msg, boolean expr) { + if (!expr) throw new RuntimeException(msg); + } +} \ No newline at end of file diff --git a/tests/java5/ataspectj/annotationGen/BeforeWithBadReturn.java b/tests/java5/ataspectj/annotationGen/BeforeWithBadReturn.java new file mode 100644 index 000000000..e219e9181 --- /dev/null +++ b/tests/java5/ataspectj/annotationGen/BeforeWithBadReturn.java @@ -0,0 +1,9 @@ +import org.aspectj.lang.annotation.*; + +@Aspect +public class BeforeWithBadReturn { + + @Before("execution(* *(..))") + public String logEntry() {} + +} \ No newline at end of file diff --git a/tests/java5/ataspectj/annotationGen/InnerAspectAspect.aj b/tests/java5/ataspectj/annotationGen/InnerAspectAspect.aj new file mode 100644 index 000000000..324c9bb3a --- /dev/null +++ b/tests/java5/ataspectj/annotationGen/InnerAspectAspect.aj @@ -0,0 +1,15 @@ +import org.aspectj.lang.annotation.Aspect; +import java.lang.annotation.*; + +public aspect InnerAspectAspect { + + public static void main(String[] args) { + Annotation[] annotations = InnerAspect.class.getAnnotations(); + if (annotations.length != 1) throw new RuntimeException("Should have one annotation"); + Aspect aspectAnnotation = (Aspect) annotations[0]; + if (!aspectAnnotation.value().equals("")) throw new RuntimeException("value should be empty"); + } + + private static aspect InnerAspect {} + +} \ No newline at end of file diff --git a/tests/java5/ataspectj/annotationGen/InnerAspectClass.aj b/tests/java5/ataspectj/annotationGen/InnerAspectClass.aj new file mode 100644 index 000000000..91842f521 --- /dev/null +++ b/tests/java5/ataspectj/annotationGen/InnerAspectClass.aj @@ -0,0 +1,15 @@ +import org.aspectj.lang.annotation.Aspect; +import java.lang.annotation.*; + +public class InnerAspectClass { + + public static void main(String[] args) { + Annotation[] annotations = InnerAspect.class.getAnnotations(); + if (annotations.length != 1) throw new RuntimeException("Should have one annotation"); + Aspect aspectAnnotation = (Aspect) annotations[0]; + if (!aspectAnnotation.value().equals("")) throw new RuntimeException("value should be empty"); + } + + private static aspect InnerAspect {} + +} \ No newline at end of file diff --git a/tests/java5/ataspectj/annotationGen/PerCflowAspect.aj b/tests/java5/ataspectj/annotationGen/PerCflowAspect.aj new file mode 100644 index 000000000..e0190caf7 --- /dev/null +++ b/tests/java5/ataspectj/annotationGen/PerCflowAspect.aj @@ -0,0 +1,20 @@ +import org.aspectj.lang.annotation.Aspect; +import java.lang.annotation.*; + +public aspect PerCflowAspect percflow(execution(* Foo.foo(..))) { + + public static void main(String[] args) { + Annotation[] annotations = PerCflowAspect.class.getAnnotations(); + if (annotations.length != 1) throw new RuntimeException("Should have one annotation"); + Aspect aspectAnnotation = (Aspect) annotations[0]; + if (!aspectAnnotation.value().equals("percflow(execution(* Foo.foo(..)))")) + throw new RuntimeException("value should be equal to perclause but was: " + aspectAnnotation.value()); + } + +} + +class Foo { + + void foo() {} + +} \ No newline at end of file diff --git a/tests/java5/ataspectj/annotationGen/PerCflowbelowAspect.aj b/tests/java5/ataspectj/annotationGen/PerCflowbelowAspect.aj new file mode 100644 index 000000000..4018bafed --- /dev/null +++ b/tests/java5/ataspectj/annotationGen/PerCflowbelowAspect.aj @@ -0,0 +1,19 @@ +import org.aspectj.lang.annotation.Aspect; +import java.lang.annotation.*; + +public aspect PerCflowbelowAspect percflowbelow(execution(* Foo.foo(..))) { + + public static void main(String[] args) { + Annotation[] annotations = PerCflowbelowAspect.class.getAnnotations(); + if (annotations.length != 1) throw new RuntimeException("Should have one annotation"); + Aspect aspectAnnotation = (Aspect) annotations[0]; + if (!aspectAnnotation.value().equals("percflowbelow(execution(* Foo.foo(..)))")) throw new RuntimeException("value should be equal to perclause"); + } + +} + +class Foo { + + void foo() {} + +} \ No newline at end of file diff --git a/tests/java5/ataspectj/annotationGen/PerTargetAspect.aj b/tests/java5/ataspectj/annotationGen/PerTargetAspect.aj new file mode 100644 index 000000000..c436b8fca --- /dev/null +++ b/tests/java5/ataspectj/annotationGen/PerTargetAspect.aj @@ -0,0 +1,21 @@ +import org.aspectj.lang.annotation.Aspect; +import java.lang.annotation.*; + +public aspect PerTargetAspect pertarget(fooCall()) { + + pointcut fooCall() : call(* Foo.foo(..)); + + public static void main(String[] args) { + Annotation[] annotations = PerTargetAspect.class.getAnnotations(); + if (annotations.length != 1) throw new RuntimeException("Should have one annotation"); + Aspect aspectAnnotation = (Aspect) annotations[0]; + if (!aspectAnnotation.value().equals("pertarget(fooCall())")) throw new RuntimeException("value should be equal to perclause"); + } + +} + +class Foo { + + void foo() {} + +} \ No newline at end of file diff --git a/tests/java5/ataspectj/annotationGen/PerThisAspect.aj b/tests/java5/ataspectj/annotationGen/PerThisAspect.aj new file mode 100644 index 000000000..1521b4b4c --- /dev/null +++ b/tests/java5/ataspectj/annotationGen/PerThisAspect.aj @@ -0,0 +1,19 @@ +import org.aspectj.lang.annotation.Aspect; +import java.lang.annotation.*; + +public aspect PerThisAspect perthis(execution(* Foo.foo(..))) { + + public static void main(String[] args) { + Annotation[] annotations = PerThisAspect.class.getAnnotations(); + if (annotations.length != 1) throw new RuntimeException("Should have one annotation"); + Aspect aspectAnnotation = (Aspect) annotations[0]; + if (!aspectAnnotation.value().equals("perthis(execution(* Foo.foo(..)))")) throw new RuntimeException("value should be equal to perclause"); + } + +} + +class Foo { + + void foo() {} + +} \ No newline at end of file diff --git a/tests/java5/ataspectj/annotationGen/PerTypeWithinAspect.aj b/tests/java5/ataspectj/annotationGen/PerTypeWithinAspect.aj new file mode 100644 index 000000000..3b435604d --- /dev/null +++ b/tests/java5/ataspectj/annotationGen/PerTypeWithinAspect.aj @@ -0,0 +1,13 @@ +import org.aspectj.lang.annotation.Aspect; +import java.lang.annotation.*; + +public aspect PerTypeWithinAspect pertypewithin(javax.ejb..*) { + + public static void main(String[] args) { + Annotation[] annotations = PerTypeWithinAspect.class.getAnnotations(); + if (annotations.length != 1) throw new RuntimeException("Should have one annotation"); + Aspect aspectAnnotation = (Aspect) annotations[0]; + if (!aspectAnnotation.value().equals("pertypewithin(javax.ejb..*)")) throw new RuntimeException("value should be equal to perclause"); + } + +} diff --git a/tests/java5/ataspectj/annotationGen/PointcutAssortment.java b/tests/java5/ataspectj/annotationGen/PointcutAssortment.java new file mode 100644 index 000000000..1237b28cd --- /dev/null +++ b/tests/java5/ataspectj/annotationGen/PointcutAssortment.java @@ -0,0 +1,42 @@ +import org.aspectj.lang.annotation.*; + +public class PointcutAssortment { + + @Pointcut("execution(* PointcutAssortment.*(..))") + void pc1() {} + + @Pointcut("call(* PointcutAssortment.*(..))") + String pc2() {} + + @Pointcut("foo()") + void pc3() {} + + @Pointcut("pc1() || pc2()") + void pc4() { + System.out.println("hi there!"); + } + + @Pointcut("this(Integer)") + void pc5() {} + + @Pointcut("this(i)") + void pc6(Integer i) {} + + @Pointcut("OtherClass.intSet() && pc6(myInt)") + void pc7(Integer myInt) {} + + @Pointcut("get(* *)") + @Pointcut("set(* *)") + void pc8() {} + + @Pointcut("target(foo)") + void pc9() {} + +} + +class OtherClass { + + @Pointcut("set(Integer *)") + void intSet() {}; + +} \ No newline at end of file diff --git a/tests/java5/ataspectj/annotationGen/PointcutModifiers.aj b/tests/java5/ataspectj/annotationGen/PointcutModifiers.aj new file mode 100644 index 000000000..88e1769cf --- /dev/null +++ b/tests/java5/ataspectj/annotationGen/PointcutModifiers.aj @@ -0,0 +1,45 @@ +import org.aspectj.lang.reflect.*; +import java.lang.reflect.*; + +public abstract aspect PointcutModifiers { + + protected abstract pointcut p1(); + + pointcut p2(); + + public pointcut p3(): get(String s); + + protected pointcut p4() : set(String s); + + private pointcut p5() : call(* String.*(..)); + + public static void main(String[] args) throws NoSuchPointcutException { + AjType myType = AjTypeSystem.getAjType(PointcutModifiers.class); + assertTrue(myType != null, "found my type"); + Pointcut[] pointcuts = myType.getDeclaredPointcuts(); + assertTrue(pointcuts != null, "found some pointcuts"); + if (pointcuts.length != 5) throw new RuntimeException("Expecting 5 pointcuts"); + Pointcut pc1 = myType.getDeclaredPointcut("p1"); + assertTrue(pc1 != null, "found pc1"); + Pointcut pc2 = myType.getDeclaredPointcut("p2"); + assertTrue(pc2 != null, "found pc2"); + Pointcut pc3 = myType.getDeclaredPointcut("p3"); + assertTrue(pc3 != null, "found pc3"); + Pointcut pc4 = myType.getDeclaredPointcut("p4"); + assertTrue(pc4 != null, "found pc4"); + Pointcut pc5 = myType.getDeclaredPointcut("p5"); + assertTrue(pc5 != null, "found pc5"); + assertTrue(Modifier.isAbstract(pc1.getModifiers()),"pc1 is abstract" ); + assertTrue(Modifier.isProtected(pc1.getModifiers()),"pc1 is protected"); + assertTrue(!Modifier.isPrivate(pc2.getModifiers()),"pc2 not private"); + assertTrue(!Modifier.isPublic(pc2.getModifiers()),"pc2 not public"); + assertTrue(!Modifier.isProtected(pc2.getModifiers()),"pc2 not protected"); + assertTrue(Modifier.isPublic(pc3.getModifiers()),"pc3 is public"); + assertTrue(Modifier.isProtected(pc4.getModifiers()),"pc1 is protected"); + assertTrue(Modifier.isPrivate(pc5.getModifiers()),"pc5 is private"); + } + + private static void assertTrue(boolean expr, String msg) { + if (!expr) throw new RuntimeException(msg); + } +} \ No newline at end of file diff --git a/tests/java5/ataspectj/annotationGen/PointcutsWithParams.aj b/tests/java5/ataspectj/annotationGen/PointcutsWithParams.aj new file mode 100644 index 000000000..d6902c9ea --- /dev/null +++ b/tests/java5/ataspectj/annotationGen/PointcutsWithParams.aj @@ -0,0 +1,23 @@ +import org.aspectj.lang.reflect.*; + +public aspect PointcutsWithParams { + + pointcut pc1(String s) : args(s); + + pointcut pc2(Integer i, Double d, String s) : args(i,d,s); + + public static void main(String[] args) throws NoSuchPointcutException { + AjType myType = AjTypeSystem.getAjType(PointcutsWithParams.class); + Pointcut p1 = myType.getPointcut("pc1"); + Class[] params = p1.getParameterTypes(); + if (params.length != 1) throw new RuntimeException("expecting one param"); + if (!params[0].equals(String.class)) throw new RuntimeException("expecting a String"); + Pointcut p2 = myType.getPointcut("pc2"); + params = p2.getParameterTypes(); + if (params.length != 3) throw new RuntimeException("expecting three params"); + if (!params[0].equals(Integer.class)) throw new RuntimeException("expecting an Integer"); + if (!params[1].equals(Double.class)) throw new RuntimeException("expecting a Double"); + if (!params[2].equals(String.class)) throw new RuntimeException("expecting a String"); + } + +} \ No newline at end of file diff --git a/tests/java5/ataspectj/annotationGen/PrivilegedAspect.aj b/tests/java5/ataspectj/annotationGen/PrivilegedAspect.aj new file mode 100644 index 000000000..50c850430 --- /dev/null +++ b/tests/java5/ataspectj/annotationGen/PrivilegedAspect.aj @@ -0,0 +1,16 @@ +import org.aspectj.lang.annotation.Aspect; +import org.aspectj.internal.lang.annotation.ajcPrivileged; +import java.lang.annotation.*; + +public privileged aspect PrivilegedAspect { + + public static void main(String[] args) { + Annotation[] annotations = PrivilegedAspect.class.getAnnotations(); + if (annotations.length != 2) throw new RuntimeException("Should have two annotations"); + Aspect aspectAnnotation = PrivilegedAspect.class.getAnnotation(Aspect.class); + if (!aspectAnnotation.value().equals("")) throw new RuntimeException("value should be empty"); + ajcPrivileged pAnnotation = PrivilegedAspect.class.getAnnotation(ajcPrivileged.class); + if (pAnnotation == null) throw new RuntimeException("Should be @ajcPrivileged"); + } + +} \ No newline at end of file diff --git a/tests/java5/ataspectj/annotationGen/ReferencePointcuts.aj b/tests/java5/ataspectj/annotationGen/ReferencePointcuts.aj new file mode 100644 index 000000000..782021b24 --- /dev/null +++ b/tests/java5/ataspectj/annotationGen/ReferencePointcuts.aj @@ -0,0 +1,20 @@ +import org.aspectj.lang.reflect.*; + +public aspect ReferencePointcuts { + + pointcut pc1() : call(* *.*(..)); + + pointcut pc2() : pc1() || execution(* *.*(..)); + + public static void main(String[] args) throws NoSuchPointcutException { + AjType myType = AjTypeSystem.getAjType(ReferencePointcuts.class); + Pointcut p1 = myType.getPointcut("pc1"); + if (!p1.getPointcutExpression().equals("call(* *(..))")) + throw new RuntimeException("unexpected pc expression: " + p1.getPointcutExpression()); + Pointcut p2 = myType.getPointcut("pc2"); + if (!p2.getPointcutExpression().equals("(pc1() || execution(* *(..)))")) + throw new RuntimeException("unexpected pc expression: " + p2.getPointcutExpression()); + + } + +} \ No newline at end of file diff --git a/tests/java5/ataspectj/annotationGen/Simple14Aspect.aj b/tests/java5/ataspectj/annotationGen/Simple14Aspect.aj new file mode 100644 index 000000000..912d16de0 --- /dev/null +++ b/tests/java5/ataspectj/annotationGen/Simple14Aspect.aj @@ -0,0 +1 @@ +public aspect Simple14Aspect {} \ No newline at end of file diff --git a/tests/java5/ataspectj/annotationGen/Simple14AspectTest.java b/tests/java5/ataspectj/annotationGen/Simple14AspectTest.java new file mode 100644 index 000000000..d92eb6198 --- /dev/null +++ b/tests/java5/ataspectj/annotationGen/Simple14AspectTest.java @@ -0,0 +1,11 @@ +import org.aspectj.lang.annotation.Aspect; +import java.lang.annotation.*; + +public class Simple14AspectTest { + + public static void main(String[] args) { + Annotation[] annotations = Simple14Aspect.class.getAnnotations(); + if (annotations.length != 0) throw new RuntimeException("Should have no annotations"); + } + +} \ No newline at end of file diff --git a/tests/java5/ataspectj/annotationGen/SimpleAnnotatedAspect.aj b/tests/java5/ataspectj/annotationGen/SimpleAnnotatedAspect.aj new file mode 100644 index 000000000..376dee77d --- /dev/null +++ b/tests/java5/ataspectj/annotationGen/SimpleAnnotatedAspect.aj @@ -0,0 +1,13 @@ +import org.aspectj.lang.annotation.Aspect; +import java.lang.annotation.*; +@Aspect +public class SimpleAnnotatedAspect { + + public static void main(String[] args) { + Annotation[] annotations = SimpleAnnotatedAspect.class.getAnnotations(); + if (annotations.length != 1) throw new RuntimeException("Should have one annotation"); + Aspect aspectAnnotation = (Aspect) annotations[0]; + if (!aspectAnnotation.value().equals("")) throw new RuntimeException("value should be empty"); + } + +} \ No newline at end of file diff --git a/tests/java5/ataspectj/annotationGen/SimpleAspect.aj b/tests/java5/ataspectj/annotationGen/SimpleAspect.aj new file mode 100644 index 000000000..34f6954dc --- /dev/null +++ b/tests/java5/ataspectj/annotationGen/SimpleAspect.aj @@ -0,0 +1,13 @@ +import org.aspectj.lang.annotation.Aspect; +import java.lang.annotation.*; + +public aspect SimpleAspect { + + public static void main(String[] args) { + Annotation[] annotations = SimpleAspect.class.getAnnotations(); + if (annotations.length != 1) throw new RuntimeException("Should have one annotation"); + Aspect aspectAnnotation = (Aspect) annotations[0]; + if (!aspectAnnotation.value().equals("")) throw new RuntimeException("value should be empty"); + } + +} \ No newline at end of file diff --git a/tests/java5/ataspectj/annotationGen/SimplePointcut.aj b/tests/java5/ataspectj/annotationGen/SimplePointcut.aj new file mode 100644 index 000000000..e022f2b53 --- /dev/null +++ b/tests/java5/ataspectj/annotationGen/SimplePointcut.aj @@ -0,0 +1,29 @@ +import java.lang.annotation.*; +import org.aspectj.lang.annotation.*; +import java.lang.reflect.*; + +public aspect SimplePointcut { + + pointcut myPointcut() : call(* String.*(..)); + + public static void main(String[] args) { + Method[] methods = SimplePointcut.class.getDeclaredMethods(); + boolean foundit = false; + for (Method method : methods) { + if (method.getName().startsWith("ajc$pointcut$")) { + if (foundit) throw new RuntimeException("Only expecting one pointcut method"); + foundit = true; + if (method.getName().indexOf("$myPointcut$") == -1) { + throw new RuntimeException("Pointcut name not captured"); + } + if (method.getAnnotations().length != 1) { + throw new RuntimeException("Expecting one annotation, found " + method.getAnnotations().length); + } + Pointcut pcAnn = method.getAnnotation(Pointcut.class); + if (!pcAnn.value().equals("call(* java.lang.String.*(..))")) + throw new RuntimeException("Pointcut expression not set correctly in annotation: " + pcAnn.value()); + } + } + } + +} \ No newline at end of file diff --git a/tests/java5/ataspectj/annotationGen/TwoForThePriceOfOne.java b/tests/java5/ataspectj/annotationGen/TwoForThePriceOfOne.java new file mode 100644 index 000000000..842f07ab1 --- /dev/null +++ b/tests/java5/ataspectj/annotationGen/TwoForThePriceOfOne.java @@ -0,0 +1,10 @@ +import org.aspectj.lang.annotation.*; + +@Aspect +public class TwoForThePriceOfOne { + + @Before("execution(* *(..))") + @Pointcut("get(* *)") + public void logEntry() {} + +} \ No newline at end of file diff --git a/tests/java5/ataspectj/ataspectj/PrecedenceTest.java b/tests/java5/ataspectj/ataspectj/PrecedenceTest.java index e488aa3c6..c5959fc4b 100644 --- a/tests/java5/ataspectj/ataspectj/PrecedenceTest.java +++ b/tests/java5/ataspectj/ataspectj/PrecedenceTest.java @@ -50,7 +50,7 @@ public class PrecedenceTest extends TestCase { @Aspect() public static class TestAspect_1 { @Before("execution(* ataspectj.PrecedenceTest.hello())") - void before() { + public void before() { log("TestAspect_1"); } } @@ -59,7 +59,7 @@ public class PrecedenceTest extends TestCase { @DeclarePrecedence("ataspectj.PrecedenceTest.TestAspect_3, ataspectj.PrecedenceTest.TestAspect_1") public static class TestAspect_2 { @Before("execution(* ataspectj.PrecedenceTest.hello())") - void before() { + public void before() { log("TestAspect_2"); } } @@ -67,7 +67,7 @@ public class PrecedenceTest extends TestCase { @Aspect() public static class TestAspect_3 { @Before("execution(* ataspectj.PrecedenceTest.hello())") - void before() { + public void before() { log("TestAspect_3"); } } diff --git a/tests/java5/ataspectj/ataspectj/XXJoinPointTest.java b/tests/java5/ataspectj/ataspectj/XXJoinPointTest.java index 168e2fbe6..d14eb8a03 100644 --- a/tests/java5/ataspectj/ataspectj/XXJoinPointTest.java +++ b/tests/java5/ataspectj/ataspectj/XXJoinPointTest.java @@ -57,33 +57,33 @@ public class XXJoinPointTest extends TestCase { void pc() {} @Before("pc()") - void before(JoinPoint jp) { + public void before(JoinPoint jp) { assertEquals("hello", jp.getSignature().getName()); log("jp"); } @Before("pc()") - void before(JoinPoint.StaticPart sjp) { + public void before(JoinPoint.StaticPart sjp) { assertEquals("hello", sjp.getSignature().getName()); log("sjp"); } @Before("pc()") - void beforeEnclosing(JoinPoint.EnclosingStaticPart esjp) { + public void beforeEnclosing(JoinPoint.EnclosingStaticPart esjp) { assertEquals("testJoinPointsInAdviceSignature", esjp.getSignature().getName()); log("esjp"); } //weird order @Before("pc()") - void beforeWEIRD1(JoinPoint jp, JoinPoint.StaticPart sjp) { + public void beforeWEIRD1(JoinPoint jp, JoinPoint.StaticPart sjp) { assertEquals("hello", jp.getSignature().getName()); assertEquals("hello", sjp.getSignature().getName()); log("jp-sjp"); } @Before("pc()") - void before(JoinPoint.StaticPart sjp, JoinPoint.EnclosingStaticPart esjp) { + public void before(JoinPoint.StaticPart sjp, JoinPoint.EnclosingStaticPart esjp) { assertEquals("hello", sjp.getSignature().getName()); assertEquals("testJoinPointsInAdviceSignature", esjp.getSignature().getName()); log("sjp-esjp"); @@ -91,7 +91,7 @@ public class XXJoinPointTest extends TestCase { // conventional order @Before("pc()") - void before(JoinPoint.StaticPart sjp, JoinPoint jp, JoinPoint.EnclosingStaticPart esjp) { + public void before(JoinPoint.StaticPart sjp, JoinPoint jp, JoinPoint.EnclosingStaticPart esjp) { assertEquals("hello", sjp.getSignature().getName()); assertEquals("hello", jp.getSignature().getName()); assertEquals("testJoinPointsInAdviceSignature", esjp.getSignature().getName()); @@ -100,7 +100,7 @@ public class XXJoinPointTest extends TestCase { // weird order @Before("pc()") - void beforeWEIRD2(JoinPoint.EnclosingStaticPart esjp, JoinPoint jp, JoinPoint.StaticPart sjp) { + public void beforeWEIRD2(JoinPoint.EnclosingStaticPart esjp, JoinPoint jp, JoinPoint.StaticPart sjp) { assertEquals("testJoinPointsInAdviceSignature", esjp.getSignature().getName()); assertEquals("hello", jp.getSignature().getName()); assertEquals("hello", sjp.getSignature().getName()); diff --git a/tests/java5/ataspectj/coverage/Test040.java b/tests/java5/ataspectj/coverage/Test040.java index 038ebff1e..b4ba98086 100644 --- a/tests/java5/ataspectj/coverage/Test040.java +++ b/tests/java5/ataspectj/coverage/Test040.java @@ -5,6 +5,7 @@ import org.aspectj.lang.annotation.*; class Foo{ } aspect A{ + @SuppressAjWarnings @Before("call(* org.aspectprogrammer..*(..)) && this(Foo)") public void callFromFoo() { System.out.println("Call from Foo"); diff --git a/tests/java5/ataspectj/coverage/Test041.java b/tests/java5/ataspectj/coverage/Test041.java index 28b1562d4..d444561a9 100644 --- a/tests/java5/ataspectj/coverage/Test041.java +++ b/tests/java5/ataspectj/coverage/Test041.java @@ -3,6 +3,7 @@ import org.aspectj.lang.annotation.*; aspect A{ + @SuppressAjWarnings @AdviceName("") before() : call(* org.aspectprogrammer..*(..)) { System.out.println("Call from Foo"); diff --git a/tests/src/org/aspectj/systemtest/AllTests.java b/tests/src/org/aspectj/systemtest/AllTests.java index 22d673892..d8b88d0d7 100644 --- a/tests/src/org/aspectj/systemtest/AllTests.java +++ b/tests/src/org/aspectj/systemtest/AllTests.java @@ -36,7 +36,6 @@ public class AllTests { public static Test suite() { TestSuite suite = new TestSuite("AspectJ System Test Suite - JDK 1.3"); //$JUnit-BEGIN$ - suite.addTest(AllTestsAspectJ150.suite()); suite.addTest(Ajc121Tests.suite()); suite.addTest(Ajc120Tests.suite()); suite.addTest(Ajc11Tests.suite()); diff --git a/tests/src/org/aspectj/systemtest/AllTests15.java b/tests/src/org/aspectj/systemtest/AllTests15.java index badf030b5..6390e42a9 100644 --- a/tests/src/org/aspectj/systemtest/AllTests15.java +++ b/tests/src/org/aspectj/systemtest/AllTests15.java @@ -7,6 +7,7 @@ import junit.framework.Test; import junit.framework.TestSuite; import org.aspectj.systemtest.ajc150.AllTestsAspectJ150; +import org.aspectj.systemtest.ajc150.ataspectj.AtAjAnnotationGenTests; public class AllTests15 { @@ -15,6 +16,7 @@ public class AllTests15 { //$JUnit-BEGIN$ suite.addTest(AllTests14.suite()); suite.addTest(AllTestsAspectJ150.suite()); + suite.addTest(AtAjAnnotationGenTests.suite()); //$JUnit-END$ return suite; } diff --git a/tests/src/org/aspectj/systemtest/ajc150/ataspectj/AtAjAnnotationGenTests.java b/tests/src/org/aspectj/systemtest/ajc150/ataspectj/AtAjAnnotationGenTests.java new file mode 100644 index 000000000..0a2edb2ca --- /dev/null +++ b/tests/src/org/aspectj/systemtest/ajc150/ataspectj/AtAjAnnotationGenTests.java @@ -0,0 +1,126 @@ +/******************************************************************************* + * Copyright (c) 2005 Contributors + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Common Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/cpl-v10.html + * + * Contributors: + * initial development Jonas Bonér, Alexandre Vasseur + *******************************************************************************/ +package org.aspectj.systemtest.ajc150.ataspectj; + +import java.io.File; + +import junit.framework.Test; + +import org.aspectj.testing.XMLBasedAjcTestCase; + +/** + * A suite for @AspectJ aspects located in java5/ataspectj + * + * @author Alexandre Vasseur + */ +public class AtAjAnnotationGenTests extends XMLBasedAjcTestCase { + + public static Test suite() { + return XMLBasedAjcTestCase.loadSuite(AtAjAnnotationGenTests.class); + } + + protected File getSpecFile() { + return new File("../tests/src/org/aspectj/systemtest/ajc150/ataspectj/atajc150.xml"); + } + + public void testSimpleAspect() { + runTest("annotation gen for simple aspect"); + } + + public void testSimpleAspectIn14Mode() { + runTest("annotation gen for simple aspect pre 1.5"); + } + + public void testAspectAlreadyAnnotated() { + runTest("annotation gen for simple annotated aspect"); + } + + public void testPrivilegedAspect() { + runTest("annotation gen for privileged aspect"); + } + + public void testPerThisAspect() { + runTest("annotation gen for perthis aspect"); + } + + public void testPerTargetAspect() { + runTest("annotation gen for pertarget aspect"); + } + + public void testPerCflowAspect() { + runTest("annotation gen for percflow aspect"); + } + + public void testPerCflowbelowAspect() { + runTest("annotation gen for percflowbelow aspect"); + } + + public void testPertypewithinAspect() { + runTest("annotation gen for pertypewithin aspect"); + } + + public void testInnerAspectOfClass() { + runTest("annotation gen for inner aspect of aspect"); + } + + public void testInnerAspectOfAspect() { + runTest("annotation gen for inner aspect of class"); + } + + public void testAdvice() { + runTest("annotation gen for advice declarations"); + } + + public void testSimplePointcut() { + runTest("annotation gen for simple pointcut"); + } + + public void testPointcutModifiers() { + runTest("annotation gen for pointcut modifiers"); + } + + public void testPointcutParams() { + runTest("annotation gen for pointcut params"); + } + + public void testPointcutRefs() { + runTest("annotation gen for pointcut refs"); + } + + public void testBeforeWithBadReturn() { + runTest("before ann with non-void return"); + } + + public void testTwoAnnotationsOnSameElement() { + runTest("two anns on same element"); + } + + public void testBadPcutInAdvice() { + runTest("bad pcut in after advice"); + } + + public void testBadParameterBinding() { + runTest("bad parameter binding in advice"); + } + + public void testSimpleAtPointcut() { + runTest("simple pointcut no params"); + } + + public void testPointcutMedley() { + runTest("pointcut medley"); + } + + public void testAdviceDeclaredInClass() { + runTest("advice in a class"); + } +} + diff --git a/tests/src/org/aspectj/systemtest/ajc150/ataspectj/atajc150-tests.xml b/tests/src/org/aspectj/systemtest/ajc150/ataspectj/atajc150-tests.xml index 3a89a1290..0c436854b 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/ataspectj/atajc150-tests.xml +++ b/tests/src/org/aspectj/systemtest/ajc150/ataspectj/atajc150-tests.xml @@ -5,6 +5,10 @@ + + + + @@ -12,31 +16,45 @@ + + + + - + + + + + + + + + + + @@ -52,4 +70,139 @@ - \ No newline at end of file + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/tests/src/org/aspectj/systemtest/ajc150/ataspectj/coverage/coverage.xml b/tests/src/org/aspectj/systemtest/ajc150/ataspectj/coverage/coverage.xml index abea29b4b..f0ad3f4d3 100644 --- a/tests/src/org/aspectj/systemtest/ajc150/ataspectj/coverage/coverage.xml +++ b/tests/src/org/aspectj/systemtest/ajc150/ataspectj/coverage/coverage.xml @@ -25,35 +25,39 @@ - + + - + + - + + - - + + + - + - - + + - + @@ -102,14 +106,14 @@ - + - + @@ -130,28 +134,28 @@ - + - + - + - + @@ -214,7 +218,7 @@ - + @@ -228,7 +232,8 @@ - + + @@ -242,33 +247,37 @@ - + - + + + + - + + @@ -287,7 +296,7 @@ - + -- cgit v1.2.3