01: /**************************************************************************************
02: * Copyright (c) Jonas Bon?r, Alexandre Vasseur. All rights reserved. *
03: * http://aspectwerkz.codehaus.org *
04: * ---------------------------------------------------------------------------------- *
05: * The software in this package is published under the terms of the LGPL license *
06: * a copy of which has been included with this distribution in the license.txt file. *
07: **************************************************************************************/package test.aopc;
08:
09: import junit.framework.TestCase;
10:
11: import java.net.URL;
12: import java.net.URLClassLoader;
13:
14: /**
15: *
16: * TODO rewrite test.aopc.* with ASM or using an already builded jar with the small appp deployed
17: * several time in difft CL to test system defs and namespaces.
18: *
19: * Note: does not work behing WeavingCL. Use a real online mode <p/>
20: * java -Xrunaspectwerkz -Xdebug -Xbootclasspath/a:lib\aspectwerkz-core-1.0.jar ...
21: * <p/>
22: * The CallablePrototype class is renamed and defined as a deployed application class in a child classloader
23: * with its own META-INF/aop.xml file.
24: *
25: * @author <a href="mailto:alex@gnilux.com">Alexandre Vasseur </a>
26: */
27: public class AspectSystemTest extends TestCase {
28: public void testDoubleHierarchyMethodExecution() {
29: // VM system classpath level classes
30: Callable cvm = new CallablePrototype();
31: cvm.methodAround();
32: cvm.debug();
33: assertEquals("methodAround ", cvm.getLogString());
34:
35: // appserver like classloader, with its own aop.xml file
36: // the aop.xml file contains one aspect in the VM system classpath
37: ClassLoader myCL = new URLClassLoader(new URL[] { ClassCreator
38: .getPathFor(Callable.class
39: .getResource("META-INF/aop.xml")) },
40: ClassLoader.getSystemClassLoader());
41: Callable cas = (Callable) ClassCreator.createInstance(
42: "test.aopc.CallableAppServer", CallablePrototype.class,
43: myCL);
44: cas.methodAround();
45: cas.debug();
46: assertEquals("system/asCL/test.aopc.BaseAspect.beforeAround "
47: + "methodAround "
48: + "system/asCL/test.aopc.BaseAspect.afterAround ", cas
49: .getLogString());
50:
51: // deployed app A
52: // the aop.xml file is REusing VM system classpath aspect and is defining one of its own as well, with 2 systems
53: // we are defining the aspect on the fly in an intermediate CL without aop.xml
54: ClassLoader mySubCLAAspect = new URLClassLoader(new URL[] {},
55: myCL);
56: ClassCreator.createClass("test.aopc.a.Aspect",
57: BaseAspect.class, mySubCLAAspect);
58: ClassLoader mySubCLA = new URLClassLoader(
59: new URL[] { ClassCreator.getPathFor(Callable.class
60: .getResource("a/META-INF/aop.xml")) },
61: mySubCLAAspect);
62: //ClassCreator.createClass("test.aopc.a.Aspect", BaseAspect.class, mySubCLA);
63: Callable ca = (Callable) ClassCreator
64: .createInstance("test.aopc.a.Callee",
65: CallablePrototype.class, mySubCLA);
66: ca.methodAround();
67: ca.debug();
68: assertEquals("system/asCL/test.aopc.BaseAspect.beforeAround "
69: + "system/subCL/a1/subCLAspect.beforeAround "
70: + "system/subCL/a2/subCLAspect.beforeAround "
71: + "methodAround "
72: + "system/subCL/a2/subCLAspect.afterAround "
73: + "system/subCL/a1/subCLAspect.afterAround "
74: + "system/asCL/test.aopc.BaseAspect.afterAround ", ca
75: .getLogString());
76:
77: // deployed app B
78: // no aop.xml
79: ClassLoader mySubCLB = new URLClassLoader(new URL[] {}, myCL);
80: Callable cb = (Callable) ClassCreator
81: .createInstance("test.aopc.b.Callee",
82: CallablePrototype.class, mySubCLB);
83: cb.methodAround();
84: cb.debug();
85: assertEquals("system/asCL/test.aopc.BaseAspect.beforeAround "
86: + "methodAround "
87: + "system/asCL/test.aopc.BaseAspect.afterAround ", cb
88: .getLogString());
89: }
90:
91: // ------------------------------------------------
92: public static void main(String[] args) {
93: junit.textui.TestRunner.run(suite());
94: }
95:
96: public static junit.framework.Test suite() {
97: return new junit.framework.TestSuite(AspectSystemTest.class);
98: }
99: }
|