1 8 package test.aopc; 9 10 import junit.framework.TestCase; 11 12 import java.net.URL ; 13 import java.net.URLClassLoader ; 14 15 28 public class AspectSystemTest extends TestCase { 29 public void testDoubleHierarchyMethodExecution() { 30 Callable cvm = new CallablePrototype(); 32 cvm.methodAround(); 33 cvm.debug(); 34 assertEquals("methodAround ", cvm.getLogString()); 35 36 ClassLoader myCL = new URLClassLoader ( 39 new URL []{ClassCreator.getPathFor(Callable.class.getResource("META-INF/aop.xml"))}, 40 ClassLoader.getSystemClassLoader() 41 ); 42 Callable cas = (Callable) ClassCreator.createInstance( 43 "test.aopc.CallableAppServer", 44 CallablePrototype.class, 45 myCL 46 ); 47 cas.methodAround(); 48 cas.debug(); 49 assertEquals( 50 "system/asCL/test.aopc.BaseAspect.beforeAround " 51 + "methodAround " 52 + "system/asCL/test.aopc.BaseAspect.afterAround ", 53 cas.getLogString() 54 ); 55 56 ClassLoader mySubCLAAspect = new URLClassLoader (new URL []{}, myCL); 60 ClassCreator.createClass("test.aopc.a.Aspect", BaseAspect.class, mySubCLAAspect); 61 ClassLoader mySubCLA = new URLClassLoader ( 62 new URL []{ClassCreator.getPathFor(Callable.class.getResource("a/META-INF/aop.xml"))}, mySubCLAAspect 63 ); 64 Callable ca = (Callable) ClassCreator.createInstance("test.aopc.a.Callee", CallablePrototype.class, mySubCLA); 66 ca.methodAround(); 67 ca.debug(); 68 assertEquals( 69 "system/asCL/test.aopc.BaseAspect.beforeAround " 70 + "system/subCL/a1/subCLAspect.beforeAround " 71 + "system/subCL/a2/subCLAspect.beforeAround " 72 + "methodAround " 73 + "system/subCL/a2/subCLAspect.afterAround " 74 + "system/subCL/a1/subCLAspect.afterAround " 75 + "system/asCL/test.aopc.BaseAspect.afterAround ", ca.getLogString() 76 ); 77 78 ClassLoader mySubCLB = new URLClassLoader (new URL []{}, myCL); 81 Callable cb = (Callable) ClassCreator.createInstance("test.aopc.b.Callee", CallablePrototype.class, mySubCLB); 82 cb.methodAround(); 83 cb.debug(); 84 assertEquals( 85 "system/asCL/test.aopc.BaseAspect.beforeAround " 86 + "methodAround " 87 + "system/asCL/test.aopc.BaseAspect.afterAround ", 88 cb.getLogString() 89 ); 90 } 91 92 public static void main(String [] args) { 94 junit.textui.TestRunner.run(suite()); 95 } 96 97 public static junit.framework.Test suite() { 98 return new junit.framework.TestSuite(AspectSystemTest.class); 99 } 100 } | Popular Tags |