aboutsummaryrefslogtreecommitdiffstats
path: root/tests/java5/ataspectj
diff options
context:
space:
mode:
authoravasseur <avasseur>2005-05-02 08:17:36 +0000
committeravasseur <avasseur>2005-05-02 08:17:36 +0000
commitcdddd38d261f0ae75bf95f0859e7a440be1bb3d5 (patch)
treefa61448ab8b0d848cd65930fc5e9a44a71433ea8 /tests/java5/ataspectj
parent0b7744f560fb4ff70b70884a4932c8ebeb603fd2 (diff)
downloadaspectj-cdddd38d261f0ae75bf95f0859e7a440be1bb3d5.tar.gz
aspectj-cdddd38d261f0ae75bf95f0859e7a440be1bb3d5.zip
PTW perClause for @AJ + perClause test
Diffstat (limited to 'tests/java5/ataspectj')
-rw-r--r--tests/java5/ataspectj/ataspectj/BindingTest.java14
-rw-r--r--tests/java5/ataspectj/ataspectj/PerClauseTest.java162
2 files changed, 169 insertions, 7 deletions
diff --git a/tests/java5/ataspectj/ataspectj/BindingTest.java b/tests/java5/ataspectj/ataspectj/BindingTest.java
index c4114f020..342b8ebf0 100644
--- a/tests/java5/ataspectj/ataspectj/BindingTest.java
+++ b/tests/java5/ataspectj/ataspectj/BindingTest.java
@@ -90,6 +90,10 @@ public class BindingTest extends TestCase {
//assertEquals(2, aspect.m_count);
}
+ public void testTryCatch() {
+ assertEquals(6, echo(3));
+ }
+
private static void callWithinStatic() {
int res = dup((3+1));
assertEquals(6, res);
@@ -177,10 +181,18 @@ public class BindingTest extends TestCase {
@Around("call(int echo(int)) && withincode(void ataspectj.BindingTest.testAccessAspectState()) && args(i)")
public Object aaround7(int i, final ProceedingJoinPoint jp) throws Throwable {
- //m_count++;// what if inlined ?
+ //m_count++;// what if inlined ?//FIXME
return jp.proceed();
}
+ @Around("call(int echo(int)) && withincode(void ataspectj.BindingTest.testTryCatch()) && args(i)")
+ public Object aaround8(int i, final ProceedingJoinPoint jp) throws Throwable {
+ try {
+ return 2*((Integer)jp.proceed()).intValue();
+ } catch (Throwable t) {
+ throw t;
+ }
+ }
}
}
diff --git a/tests/java5/ataspectj/ataspectj/PerClauseTest.java b/tests/java5/ataspectj/ataspectj/PerClauseTest.java
index 0773f627f..ff8a354d2 100644
--- a/tests/java5/ataspectj/ataspectj/PerClauseTest.java
+++ b/tests/java5/ataspectj/ataspectj/PerClauseTest.java
@@ -33,9 +33,46 @@ public class PerClauseTest extends TestCase {
}
public static junit.framework.Test suite() {
- return new junit.framework.TestSuite(AfterXTest.class);
+ return new junit.framework.TestSuite(PerClauseTest.class);
}
+ public void perSingleton() {
+ log("perSingleton");
+ }
+
+ public void testPerSingleton() {
+ s_log = new StringBuffer();
+
+ // singleton is bound as soon as clinit
+ try {
+ assertTrue(Aspects.hasAspect(TestAspectPerSingleton.class));
+ Aspects.aspectOf(TestAspectPerSingleton.class);
+ } catch (NoAspectBoundException e) {
+ fail(e.toString());
+ }
+
+ perSingleton();
+ assertEquals("AOP.perSingleton perSingleton ", s_log.toString());
+
+ perSingleton();
+ assertEquals(1, TestAspectPerSingleton.s_count);
+ }
+
+ @Aspect()
+ public static class TestAspectPerSingleton {
+ static int s_count = 0;
+ public TestAspectPerSingleton() {
+ s_count++;
+ }
+
+ @Before("execution(* ataspectj.PerClauseTest.perSingleton()) && target(t)")
+ public void before(JoinPoint jp, Object t) {
+ log("AOP."+jp.getSignature().getName());
+ assertTrue("perX match", this.equals(Aspects.aspectOf(getClass())));
+ }
+ }
+
+
public void perTarget() {
log("perTarget");
}
@@ -45,8 +82,9 @@ public class PerClauseTest extends TestCase {
perTarget();
assertEquals("AOP.perTarget perTarget ", s_log.toString());
- // singleton
+ // calling singleton API will fail
try {
+ assertFalse(Aspects.hasAspect(TestAspectPerTarget.class));
Aspects.aspectOf(TestAspectPerTarget.class);
fail("should fail with NOABE");
} catch (NoAspectBoundException e) {
@@ -55,6 +93,7 @@ public class PerClauseTest extends TestCase {
// this per
try {
+ assertTrue(Aspects.hasAspect(TestAspectPerTarget.class, this));
TestAspectPerTarget aspect = (TestAspectPerTarget) Aspects.aspectOf(TestAspectPerTarget.class, this);
assertNotNull(aspect);
} catch (NoAspectBoundException e) {
@@ -64,6 +103,7 @@ public class PerClauseTest extends TestCase {
// another per
PerClauseTest me = new PerClauseTest();
try {
+ assertFalse(Aspects.hasAspect(TestAspectPerTarget.class, me));
Aspects.aspectOf(TestAspectPerTarget.class, me);
fail("should fail");
} catch (NoAspectBoundException e) {
@@ -71,18 +111,22 @@ public class PerClauseTest extends TestCase {
}
me.perTarget();
try {
+ assertTrue(Aspects.hasAspect(TestAspectPerTarget.class, me));
TestAspectPerTarget aspect = (TestAspectPerTarget) Aspects.aspectOf(TestAspectPerTarget.class, me);
assertNotNull(aspect);
} catch (NoAspectBoundException e) {
fail(e.toString());
}
+
+ assertEquals(2, TestAspectPerTarget.s_count);
}
@Aspect("pertarget(execution(* ataspectj.PerClauseTest.perTarget()))")
public static class TestAspectPerTarget {
+ static int s_count;
public TestAspectPerTarget() {
- ;
+ s_count++;
}
@Before("execution(* ataspectj.PerClauseTest.perTarget()) && target(t)")
@@ -93,6 +137,13 @@ public class PerClauseTest extends TestCase {
}
public void perCflowEntry() {
+ // the aspect is bound to the executing thread
+ try {
+ assertTrue(Aspects.hasAspect(TestAspectPerCflow.class));
+ Aspects.aspectOf(TestAspectPerCflow.class);
+ } catch (NoAspectBoundException e) {
+ fail(e.toString());
+ }
perCflow();
}
@@ -100,27 +151,126 @@ public class PerClauseTest extends TestCase {
log("perCflow");
}
- public void testPerCflow() {
+ public void testPerCflow() throws Throwable {
s_log = new StringBuffer();
+
+ // no aspect bound yet
+ try {
+ assertFalse(Aspects.hasAspect(TestAspectPerCflow.class));
+ Aspects.aspectOf(TestAspectPerCflow.class);
+ fail("No perCflow should be bound yet");
+ } catch (NoAspectBoundException e) {
+ ;//ok
+ }
+
perCflow();
assertEquals("perCflow ", s_log.toString());
+ // still no aspect bound yet
+ try {
+ assertFalse(Aspects.hasAspect(TestAspectPerCflow.class));
+ Aspects.aspectOf(TestAspectPerCflow.class);
+ fail("No perCflow should be bound yet");
+ } catch (NoAspectBoundException e) {
+ ;//ok
+ }
s_log = new StringBuffer();
perCflowEntry();
assertEquals("AOP.perCflow perCflow ", s_log.toString());
+ // no aspect bound anymore since went OUT of the per clause
+ try {
+ assertFalse(Aspects.hasAspect(TestAspectPerCflow.class));
+ Aspects.aspectOf(TestAspectPerCflow.class);
+ fail("No perCflow should be bound anymore");
+ } catch (NoAspectBoundException e) {
+ ;//ok
+ }
+
+ Runnable rok = new Runnable() {
+ public void run() {
+ perCflowEntry();
+ }
+ };
+ Thread trok = new Thread(rok);
+ trok.start();
+ trok.join();
+
+ Runnable rko = new Runnable() {
+ public void run() {
+ perCflow();
+ }
+ };
+ Thread trko = new Thread(rko);
+ trko.start();
+ trko.join();
+
+ assertEquals(2, TestAspectPerCflow.s_count);
}
@Aspect("percflow(execution(* ataspectj.PerClauseTest.perCflowEntry()))")
public static class TestAspectPerCflow {
+ static int s_count;
public TestAspectPerCflow() {
- ;
+ s_count++;
}
@Before("execution(* ataspectj.PerClauseTest.perCflow())")
public void before(JoinPoint jp) {
log("AOP."+jp.getSignature().getName());
- assertTrue("perX match", this.equals(Aspects.aspectOf(getClass(), Thread.currentThread())));
+ assertTrue("perX match", this.equals(Aspects.aspectOf(getClass())));
+ }
+ }
+
+ public void testPerTypeWithin() {
+ assertTrue(Aspects.hasAspect(TestAspectPTW.class, PTW1.class));
+ assertTrue(Aspects.hasAspect(TestAspectPTW.class, PTW2.class));
+ assertFalse(Aspects.hasAspect(TestAspectPTW.class, PTWNoMatch.class));
+
+ PTW1.foo();
+ PTW2.foo();
+ PTWNoMatch.foo();
+
+ assertEquals(2, TestAspectPTW.s_count);
+ try {
+ assertTrue(Aspects.hasAspect(TestAspectPTW.class, PTW1.class));
+ assertTrue(Aspects.hasAspect(TestAspectPTW.class, PTW2.class));
+ Aspects.aspectOf(TestAspectPTW.class, PTW1.class);
+ Aspects.aspectOf(TestAspectPTW.class, PTW2.class);
+ } catch (NoAspectBoundException e) {
+ fail(e.toString());
+ }
+ try {
+ assertFalse(Aspects.hasAspect(TestAspectPTW.class, PTWNoMatch.class));
+ Aspects.aspectOf(TestAspectPTW.class, PTWNoMatch.class);
+ fail("should not have PTW aspect");
+ } catch (NoAspectBoundException e) {
+ ;//ok
}
}
+
+ static class PTW1 {
+ static void foo() {};
+ }
+ static class PTW2 {
+ static void foo() {};
+ }
+ static class PTWNoMatch {
+ static void foo() {};
+ }
+
+ @Aspect("pertypewithin(ataspectj.PerClauseTest.PTW* && !ataspectj.PerClauseTest.PTWNoMatch)")
+ public static class TestAspectPTW {
+ static int s_count;
+
+ public TestAspectPTW() {
+ s_count++;
+ }
+
+ @Before("execution(* ataspectj.PerClauseTest.PTW*.foo())")
+ public void before(JoinPoint jp) {
+ ;
+ }
+
+ }
}