1   package test.polymorphic;
2   
3   import org.codehaus.aspectwerkz.joinpoint.JoinPoint;
4   import org.codehaus.aspectwerkz.joinpoint.MethodRtti;
5   import org.codehaus.aspectwerkz.joinpoint.ConstructorRtti;
6   import junit.framework.TestCase;
7   
8   public class PolymorphicTest extends TestCase {
9   
10      public static StringBuffer LOG = new StringBuffer("");
11  
12      public void testPolymorphicCallJoinPoint() {
13          // see AW-228
14          LOG = new StringBuffer("");
15          SubClass child = new SubClass();
16          child.methodTest();
17          assertEquals("call child parent ", LOG.toString());
18  
19          LOG = new StringBuffer("");
20          SuperClass parent = new SuperClass();
21          parent.methodTest();
22          assertEquals("call parent ", LOG.toString());
23      }
24  
25      public void testCtorCall() {
26          LOG = new StringBuffer("");
27          SubClass child = new SubClass("s");
28          assertEquals("callctor parent s child s ", LOG.toString());
29  
30          LOG = new StringBuffer("");
31          SuperClass parent = new SuperClass("ss");
32          assertEquals("callctor parent ss ", LOG.toString());
33      }
34  
35      public void testCtorExecution() {
36          LOG = new StringBuffer("");
37          SubClass child = new SubClass(0);
38          assertEquals("exector exector parent 0 child 0 ", LOG.toString());
39  
40          LOG = new StringBuffer("");
41          SuperClass parent = new SuperClass(1);
42          assertEquals("exector parent 1 ", LOG.toString());
43      }
44  
45      public static void main(String[] args) {
46          junit.textui.TestRunner.run(suite());
47      }
48  
49      public static junit.framework.Test suite() {
50          return new junit.framework.TestSuite(PolymorphicTest.class);
51      }
52  
53  
54      //---- Aspect
55  
56  	public static class TestAspect {
57  	
58  		public void method1Advise(JoinPoint joinPoint) {
59  			MethodRtti rtti = (MethodRtti)joinPoint.getRtti();
60  			LOG.append("call ");
61  		}
62  
63          public void ctor1Advise(JoinPoint joinPoint) {
64              ConstructorRtti rtti = (ConstructorRtti)joinPoint.getRtti();
65              LOG.append("exector ");
66          }
67  
68          public void ctor2Advise(JoinPoint joinPoint) {
69              ConstructorRtti rtti = (ConstructorRtti)joinPoint.getRtti();
70              LOG.append("callctor ");
71          }
72  	}
73  }