aboutsummaryrefslogtreecommitdiffstats
path: root/weaver/testsrc/org
diff options
context:
space:
mode:
authoracolyer <acolyer>2004-12-08 16:14:20 +0000
committeracolyer <acolyer>2004-12-08 16:14:20 +0000
commitd5bc7f7caac0cde68010baa5c2f73de8b7ccc410 (patch)
tree4ec954ffe6cf398528944957f9b39975a7cd931e /weaver/testsrc/org
parentea0c31e9db096fea037be320f317084d47a786eb (diff)
downloadaspectj-d5bc7f7caac0cde68010baa5c2f73de8b7ccc410.tar.gz
aspectj-d5bc7f7caac0cde68010baa5c2f73de8b7ccc410.zip
lots of pointcut parsing test cases for @xxx pcds
Diffstat (limited to 'weaver/testsrc/org')
-rw-r--r--weaver/testsrc/org/aspectj/weaver/patterns/AnnotationPatternTestCase.java2
-rw-r--r--weaver/testsrc/org/aspectj/weaver/patterns/ParserTestCase.java167
2 files changed, 163 insertions, 6 deletions
diff --git a/weaver/testsrc/org/aspectj/weaver/patterns/AnnotationPatternTestCase.java b/weaver/testsrc/org/aspectj/weaver/patterns/AnnotationPatternTestCase.java
index c3ea08e4d..2a4ce76fd 100644
--- a/weaver/testsrc/org/aspectj/weaver/patterns/AnnotationPatternTestCase.java
+++ b/weaver/testsrc/org/aspectj/weaver/patterns/AnnotationPatternTestCase.java
@@ -98,7 +98,7 @@ public class AnnotationPatternTestCase extends TestCase {
AnnotationTypePattern bad = p.maybeParseAnnotationPattern();
fail("ParserException expected");
} catch(ParserException pEx) {
- assertEquals("expected name pattern",pEx.getMessage());
+ assertEquals("name pattern",pEx.getMessage());
}
}
diff --git a/weaver/testsrc/org/aspectj/weaver/patterns/ParserTestCase.java b/weaver/testsrc/org/aspectj/weaver/patterns/ParserTestCase.java
index 1be581690..f50ebbaea 100644
--- a/weaver/testsrc/org/aspectj/weaver/patterns/ParserTestCase.java
+++ b/weaver/testsrc/org/aspectj/weaver/patterns/ParserTestCase.java
@@ -17,6 +17,7 @@ import junit.framework.TestCase;
import org.aspectj.weaver.BcweaverTests;
import org.aspectj.weaver.ResolvedTypeX;
+import org.aspectj.weaver.Shadow;
import org.aspectj.weaver.World;
import org.aspectj.weaver.bcel.BcelShadow;
import org.aspectj.weaver.bcel.BcelWorld;
@@ -62,15 +63,171 @@ public class ParserTestCase extends TestCase {
}
}
- public void testParseWithAnnotation() {
+ public void testParseExecutionWithAnnotation() {
PatternParser parser = new PatternParser("execution(@SimpleAnnotation void Hello.*(..))");
KindedPointcut p = (KindedPointcut) parser.parsePointcut();
// XXX - needs finishing...
p.resolveBindings(makeSimpleScope(),new Bindings(3));
- System.err.println(p);
-// assertEquals(p.kind, BcelShadow.MethodExecution);
-// assertTrue(p.signature.getName().matches("foobar"));
-// p.signature.resolveBindings(makeSimpleScope(),new Bindings(3));
+ assertEquals("execution(@p.SimpleAnnotation void Hello.*(..))",p.toString());
+ assertEquals(p.kind, Shadow.MethodExecution);
+ assertTrue(p.signature.getName().matches("foobar"));
+ }
+
+ // note... toString on a pointcut is a very quick and easy way to test a successful parse
+ public void testParseExecutionWithMultipleAnnotations() {
+ PatternParser parser = new PatternParser("execution(@SimpleAnnotation (@Foo Integer) (@Goo Hello).*(..))");
+ KindedPointcut p = (KindedPointcut) parser.parsePointcut();
+ assertEquals("execution(@(SimpleAnnotation) (@(Foo) Integer) (@(Goo) Hello).*(..))",p.toString());;
+ }
+
+ public void testParseCallWithMultipleAnnotations() {
+ PatternParser parser = new PatternParser("call(@SimpleAnnotation (@Foo Integer) (@Goo Hello).*(..))");
+ KindedPointcut p = (KindedPointcut) parser.parsePointcut();
+ assertEquals("call(@(SimpleAnnotation) (@(Foo) Integer) (@(Goo) Hello).*(..))",p.toString());;
+ }
+
+ public void testParseGetWithAnnotations() {
+ PatternParser parser = new PatternParser("get(@Foo (@SimpleAnnotation ReturnType) (@Foo @Goo Hello).*)");
+ KindedPointcut p = (KindedPointcut) parser.parsePointcut();
+ assertEquals("get(@(Foo) (@(SimpleAnnotation) ReturnType) (@(Foo) @(Goo) Hello).*)",p.toString());;
+ }
+
+ public void testParseBadGetWithAnnotations() {
+ PatternParser parser = new PatternParser("get(@Foo (@Foo @Goo Hello).*)");
+ try {
+ KindedPointcut p = (KindedPointcut) parser.parsePointcut();
+ fail("Expected parser exception");
+ } catch (ParserException pEx) {
+ assertEquals("name pattern",pEx.getMessage());
+ }
+ }
+
+ public void testParseGetWithAndAggregationAnnotations() {
+ PatternParser parser = new PatternParser("get(@Foo @SimpleAnnotation ReturnType (@Foo @Goo Hello).*)");
+ KindedPointcut p = (KindedPointcut) parser.parsePointcut();
+ assertEquals("get(@(Foo) @(SimpleAnnotation) ReturnType (@(Foo) @(Goo) Hello).*)",p.toString());;
+ }
+
+
+ public void testParseSetWithAnnotations() {
+ PatternParser parser = new PatternParser("set(@Foo (@SimpleAnnotation ReturnType) (@Foo @Goo Hello).*)");
+ KindedPointcut p = (KindedPointcut) parser.parsePointcut();
+ assertEquals("set(@(Foo) (@(SimpleAnnotation) ReturnType) (@(Foo) @(Goo) Hello).*)",p.toString());;
+ }
+
+ public void testParseHandlerWithAnnotations() {
+ PatternParser parser = new PatternParser("handler(@Critical Exception+)");
+ Pointcut p = parser.parsePointcut();
+ assertEquals("handler((@(Critical) Exception+))",p.toString());;
+ }
+
+ public void testParseInitializationWithAnnotations() {
+ PatternParser parser = new PatternParser("initialization(@Foo (@Goo Hello).new(@Foo Integer))");
+ Pointcut p = parser.parsePointcut();
+ assertEquals("initialization(@(Foo) (@(Goo) Hello).new((@(Foo) Integer)))",p.toString());
+
+ }
+
+ public void testParsePreInitializationWithAnnotations() {
+ PatternParser parser = new PatternParser("preinitialization(@Foo (@Goo Hello).new(@Foo Integer))");
+ Pointcut p = parser.parsePointcut();
+ assertEquals("preinitialization(@(Foo) (@(Goo) Hello).new((@(Foo) Integer)))",p.toString());
+ }
+
+ public void testStaticInitializationWithAnnotations() {
+ PatternParser parser = new PatternParser("staticinitialization(@Foo @Boo @Goo Moo)");
+ Pointcut p = parser.parsePointcut();
+ assertEquals("staticinitialization((@(Foo) @(Boo) @(Goo) Moo).<clinit>())",p.toString());
+ }
+
+ public void testWithinWithAnnotations() {
+ PatternParser parser = new PatternParser("within(@Foo *)");
+ Pointcut p = parser.parsePointcut();
+ assertEquals("within((@(Foo) *))",p.toString());
+ }
+
+ public void testWithinCodeWithAnnotations() {
+ PatternParser parser = new PatternParser("withincode(@Foo * *.*(..))");
+ Pointcut p = parser.parsePointcut();
+ assertEquals("withincode(@(Foo) * *.*(..))",p.toString());
+ }
+
+ public void testAtAnnotation() {
+ PatternParser parser = new PatternParser("@annotation(@Foo)");
+ AnnotationPointcut p = (AnnotationPointcut) parser.parsePointcut();
+ assertEquals("@annotation(@Foo)",p.toString());
+ }
+
+ public void testBadAtAnnotation() {
+ PatternParser parser = new PatternParser("@annotation(!@Foo)");
+ try {
+ Pointcut p = parser.parsePointcut();
+ fail("Expected parser exception");
+ } catch (ParserException pEx) {
+ assertEquals("identifier",pEx.getMessage());
+ }
+ }
+
+ public void testAtAnnotationWithBinding() {
+ PatternParser parser = new PatternParser("@annotation(foo)");
+ AnnotationPointcut p = (AnnotationPointcut) parser.parsePointcut();
+ assertEquals("@annotation(foo)",p.toString());
+ }
+
+ public void testDoubleAtAnnotation() {
+ PatternParser parser = new PatternParser("@annotation(@Foo @Goo)");
+ try {
+ Pointcut p = parser.parsePointcut();
+ fail("Expected parser exception");
+ } catch (ParserException pEx) {
+ assertEquals(")",pEx.getMessage());
+ }
+ }
+
+ public void testAtWithin() {
+ PatternParser parser = new PatternParser("@within(foo)");
+ WithinAnnotationPointcut p = (WithinAnnotationPointcut) parser.parsePointcut();
+ assertEquals("@within(foo)",p.toString());
+ parser = new PatternParser("@within(@Foo))");
+ p = (WithinAnnotationPointcut) parser.parsePointcut();
+ assertEquals("@within(@Foo)",p.toString());
+ }
+
+ public void testAtWithinCode() {
+ PatternParser parser = new PatternParser("@withincode(foo)");
+ WithinCodeAnnotationPointcut p = (WithinCodeAnnotationPointcut) parser.parsePointcut();
+ assertEquals("@withincode(foo)",p.toString());
+ parser = new PatternParser("@withincode(@Foo))");
+ p = (WithinCodeAnnotationPointcut) parser.parsePointcut();
+ assertEquals("@withincode(@Foo)",p.toString());
+ }
+
+ public void testAtThis() {
+ PatternParser parser = new PatternParser("@this(foo)");
+ ThisOrTargetAnnotationPointcut p = (ThisOrTargetAnnotationPointcut) parser.parsePointcut();
+ assertEquals("@this(foo)",p.toString());
+ assertTrue("isThis",p.isThis());
+ parser = new PatternParser("@this(@Foo))");
+ p = (ThisOrTargetAnnotationPointcut) parser.parsePointcut();
+ assertTrue("isThis",p.isThis());
+ assertEquals("@this(@Foo)",p.toString());
+ }
+
+ public void testAtTarget() {
+ PatternParser parser = new PatternParser("@target(foo)");
+ ThisOrTargetAnnotationPointcut p = (ThisOrTargetAnnotationPointcut) parser.parsePointcut();
+ assertEquals("@target(foo)",p.toString());
+ assertTrue("isTarget",!p.isThis());
+ parser = new PatternParser("@target(@Foo))");
+ p = (ThisOrTargetAnnotationPointcut) parser.parsePointcut();
+ assertTrue("isTarget",!p.isThis());
+ assertEquals("@target(@Foo)",p.toString());
+ }
+
+ public void testAtArgs() {
+ PatternParser parser = new PatternParser("@args(@Foo,@Goo,*,..,@Moo)");
+ Pointcut p = parser.parsePointcut();
+ assertEquals("@args(@Foo, @Goo, @ANY, .., @Moo)",p.toString());
}
public TestScope makeSimpleScope() {