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