Lines 16-21
Link Here
|
16 |
import java.lang.reflect.InvocationTargetException; |
16 |
import java.lang.reflect.InvocationTargetException; |
17 |
import java.lang.reflect.Method; |
17 |
import java.lang.reflect.Method; |
18 |
import java.net.URL; |
18 |
import java.net.URL; |
|
|
19 |
import java.util.Enumeration; |
20 |
import java.util.Properties; |
19 |
|
21 |
|
20 |
import junit.framework.TestCase; |
22 |
import junit.framework.TestCase; |
21 |
|
23 |
|
Lines 41-55
Link Here
|
41 |
private final static String ITD_ASPECTS = BcweaverTests.TESTDATA_PATH + "/ltw-itdaspects.jar"; |
43 |
private final static String ITD_ASPECTS = BcweaverTests.TESTDATA_PATH + "/ltw-itdaspects.jar"; |
42 |
private final static String PER_ASPECTS = BcweaverTests.TESTDATA_PATH + "/ltw-peraspects.jar"; |
44 |
private final static String PER_ASPECTS = BcweaverTests.TESTDATA_PATH + "/ltw-peraspects.jar"; |
43 |
|
45 |
|
|
|
46 |
private final static String NULL = "null"; |
47 |
|
48 |
private Properties savedProperties; |
44 |
|
49 |
|
45 |
public WeavingURLClassLoaderTest(String name) { |
50 |
public WeavingURLClassLoaderTest(String name) { |
46 |
super(name); |
51 |
super(name); |
47 |
System.setProperty(WeavingAdaptor.WEAVING_ADAPTOR_VERBOSE,"true"); |
|
|
48 |
} |
52 |
} |
49 |
|
53 |
|
50 |
public void testLoadClass () { |
54 |
public void testLoadClass () { |
51 |
System.setProperty(WeavingURLClassLoader.WEAVING_ASPECT_PATH,""); |
55 |
setSystemProperty(WeavingURLClassLoader.WEAVING_ASPECT_PATH,""); |
52 |
System.setProperty(WeavingURLClassLoader.WEAVING_CLASS_PATH,CLASSES_JAR); |
56 |
setSystemProperty(WeavingURLClassLoader.WEAVING_CLASS_PATH,CLASSES_JAR); |
53 |
WeavingURLClassLoader loader = new WeavingURLClassLoader(getClass().getClassLoader()); |
57 |
WeavingURLClassLoader loader = new WeavingURLClassLoader(getClass().getClassLoader()); |
54 |
|
58 |
|
55 |
try { |
59 |
try { |
Lines 62-69
Link Here
|
62 |
} |
66 |
} |
63 |
|
67 |
|
64 |
public void testLoadWovenClass () { |
68 |
public void testLoadWovenClass () { |
65 |
System.setProperty(WeavingURLClassLoader.WEAVING_ASPECT_PATH,""); |
69 |
setSystemProperty(WeavingURLClassLoader.WEAVING_ASPECT_PATH,""); |
66 |
System.setProperty(WeavingURLClassLoader.WEAVING_CLASS_PATH,WOVEN_JAR); |
70 |
setSystemProperty(WeavingURLClassLoader.WEAVING_CLASS_PATH,WOVEN_JAR); |
67 |
WeavingURLClassLoader loader = new WeavingURLClassLoader(getClass().getClassLoader()); |
71 |
WeavingURLClassLoader loader = new WeavingURLClassLoader(getClass().getClassLoader()); |
68 |
|
72 |
|
69 |
try { |
73 |
try { |
Lines 76-83
Link Here
|
76 |
} |
80 |
} |
77 |
|
81 |
|
78 |
public void testWeaveWovenClass () { |
82 |
public void testWeaveWovenClass () { |
79 |
System.setProperty(WeavingURLClassLoader.WEAVING_ASPECT_PATH,ADVICE_ASPECTS); |
83 |
setSystemProperty(WeavingURLClassLoader.WEAVING_ASPECT_PATH,ADVICE_ASPECTS); |
80 |
System.setProperty(WeavingURLClassLoader.WEAVING_CLASS_PATH,ADVICE_ASPECTS + File.pathSeparator + WOVEN_JAR); |
84 |
setSystemProperty(WeavingURLClassLoader.WEAVING_CLASS_PATH,ADVICE_ASPECTS + File.pathSeparator + WOVEN_JAR); |
81 |
WeavingURLClassLoader loader = new WeavingURLClassLoader(getClass().getClassLoader()); |
85 |
WeavingURLClassLoader loader = new WeavingURLClassLoader(getClass().getClassLoader()); |
82 |
|
86 |
|
83 |
try { |
87 |
try { |
Lines 106-113
Link Here
|
106 |
} |
110 |
} |
107 |
|
111 |
|
108 |
public void testWeaveAdvice () { |
112 |
public void testWeaveAdvice () { |
109 |
System.setProperty(WeavingURLClassLoader.WEAVING_ASPECT_PATH,ADVICE_ASPECTS); |
113 |
setSystemProperty(WeavingURLClassLoader.WEAVING_ASPECT_PATH,ADVICE_ASPECTS); |
110 |
System.setProperty(WeavingURLClassLoader.WEAVING_CLASS_PATH,ADVICE_ASPECTS + File.pathSeparator + CLASSES_JAR); |
114 |
setSystemProperty(WeavingURLClassLoader.WEAVING_CLASS_PATH,ADVICE_ASPECTS + File.pathSeparator + CLASSES_JAR); |
|
|
115 |
WeavingURLClassLoader loader = new WeavingURLClassLoader(getClass().getClassLoader()); |
116 |
|
117 |
try { |
118 |
Class clazz = loader.loadClass("LTWHelloWorld"); |
119 |
invokeMain(clazz,new String[] { "LTWAspect" }); |
120 |
} |
121 |
catch (Exception ex) { |
122 |
fail(ex.toString()); |
123 |
} |
124 |
} |
125 |
|
126 |
public void testWeaveAdviceWithVerbose () { |
127 |
setSystemProperty(WeavingURLClassLoader.WEAVING_ASPECT_PATH,ADVICE_ASPECTS); |
128 |
setSystemProperty(WeavingURLClassLoader.WEAVING_CLASS_PATH,ADVICE_ASPECTS + File.pathSeparator + CLASSES_JAR); |
129 |
setSystemProperty(WeavingAdaptor.WEAVING_ADAPTOR_VERBOSE,"true"); |
130 |
WeavingURLClassLoader loader = new WeavingURLClassLoader(getClass().getClassLoader()); |
131 |
|
132 |
try { |
133 |
Class clazz = loader.loadClass("LTWHelloWorld"); |
134 |
invokeMain(clazz,new String[] { "LTWAspect" }); |
135 |
} |
136 |
catch (Exception ex) { |
137 |
fail(ex.toString()); |
138 |
} |
139 |
} |
140 |
|
141 |
public void testWeaveAdviceWithWeaveInfo () { |
142 |
setSystemProperty(WeavingURLClassLoader.WEAVING_ASPECT_PATH,ADVICE_ASPECTS); |
143 |
setSystemProperty(WeavingURLClassLoader.WEAVING_CLASS_PATH,ADVICE_ASPECTS + File.pathSeparator + CLASSES_JAR); |
144 |
setSystemProperty(WeavingAdaptor.SHOW_WEAVE_INFO_PROPERTY,"true"); |
111 |
WeavingURLClassLoader loader = new WeavingURLClassLoader(getClass().getClassLoader()); |
145 |
WeavingURLClassLoader loader = new WeavingURLClassLoader(getClass().getClassLoader()); |
112 |
|
146 |
|
113 |
try { |
147 |
try { |
Lines 120-127
Link Here
|
120 |
} |
154 |
} |
121 |
|
155 |
|
122 |
public void testWeaveDeclareWarningAdvice () { |
156 |
public void testWeaveDeclareWarningAdvice () { |
123 |
System.setProperty(WeavingURLClassLoader.WEAVING_ASPECT_PATH,DW_ADVICE_ASPECTS); |
157 |
setSystemProperty(WeavingURLClassLoader.WEAVING_ASPECT_PATH,DW_ADVICE_ASPECTS); |
124 |
System.setProperty(WeavingURLClassLoader.WEAVING_CLASS_PATH,DW_ADVICE_ASPECTS + File.pathSeparator + CLASSES_JAR); |
158 |
setSystemProperty(WeavingURLClassLoader.WEAVING_CLASS_PATH,DW_ADVICE_ASPECTS + File.pathSeparator + CLASSES_JAR); |
125 |
WeavingURLClassLoader loader = new WeavingURLClassLoader(getClass().getClassLoader()); |
159 |
WeavingURLClassLoader loader = new WeavingURLClassLoader(getClass().getClassLoader()); |
126 |
|
160 |
|
127 |
try { |
161 |
try { |
Lines 134-141
Link Here
|
134 |
} |
168 |
} |
135 |
|
169 |
|
136 |
public void testWeaveDeclareErrorAdvice () { |
170 |
public void testWeaveDeclareErrorAdvice () { |
137 |
System.setProperty(WeavingURLClassLoader.WEAVING_ASPECT_PATH,DE_ADVICE_ASPECTS); |
171 |
setSystemProperty(WeavingURLClassLoader.WEAVING_ASPECT_PATH,DE_ADVICE_ASPECTS); |
138 |
System.setProperty(WeavingURLClassLoader.WEAVING_CLASS_PATH,DE_ADVICE_ASPECTS + File.pathSeparator + CLASSES_JAR); |
172 |
setSystemProperty(WeavingURLClassLoader.WEAVING_CLASS_PATH,DE_ADVICE_ASPECTS + File.pathSeparator + CLASSES_JAR); |
139 |
WeavingURLClassLoader loader = new WeavingURLClassLoader(getClass().getClassLoader()); |
173 |
WeavingURLClassLoader loader = new WeavingURLClassLoader(getClass().getClassLoader()); |
140 |
|
174 |
|
141 |
try { |
175 |
try { |
Lines 149-156
Link Here
|
149 |
} |
183 |
} |
150 |
|
184 |
|
151 |
public void testWeaveAroundClosure () { |
185 |
public void testWeaveAroundClosure () { |
152 |
System.setProperty(WeavingURLClassLoader.WEAVING_ASPECT_PATH,AROUNDCLOSURE_ASPECTS); |
186 |
setSystemProperty(WeavingURLClassLoader.WEAVING_ASPECT_PATH,AROUNDCLOSURE_ASPECTS); |
153 |
System.setProperty(WeavingURLClassLoader.WEAVING_CLASS_PATH,AROUNDCLOSURE_ASPECTS + File.pathSeparator + CLASSES_JAR); |
187 |
setSystemProperty(WeavingURLClassLoader.WEAVING_CLASS_PATH,AROUNDCLOSURE_ASPECTS + File.pathSeparator + CLASSES_JAR); |
154 |
WeavingURLClassLoader loader = new WeavingURLClassLoader(getClass().getClassLoader()); |
188 |
WeavingURLClassLoader loader = new WeavingURLClassLoader(getClass().getClassLoader()); |
155 |
|
189 |
|
156 |
try { |
190 |
try { |
Lines 231-236
Link Here
|
231 |
} |
265 |
} |
232 |
} |
266 |
} |
233 |
|
267 |
|
|
|
268 |
public void testJunkAspectJar () { |
269 |
File junkJar = new File(JUNK_JAR); |
270 |
assertFalse(junkJar + " should not exist",junkJar.exists()); |
271 |
|
272 |
URL aspects = FileUtil.getFileURL(junkJar); |
273 |
URL[] classURLs = new URL[] { aspects }; |
274 |
URL[] aspectURLs = new URL[] { aspects }; |
275 |
|
276 |
try { |
277 |
WeavingURLClassLoader loader = new WeavingURLClassLoader(classURLs,aspectURLs,getClass().getClassLoader()); |
278 |
fail("Expecting org.aspectj.bridge.AbortException"); |
279 |
} |
280 |
catch (Exception ex) { |
281 |
assertTrue("Expecting org.aspectj.bridge.AbortException caught " + ex,(ex instanceof org.aspectj.bridge.AbortException)); |
282 |
} |
283 |
} |
284 |
|
234 |
public void testAddURL () { |
285 |
public void testAddURL () { |
235 |
URL classes = FileUtil.getFileURL(new File(CLASSES_JAR)); |
286 |
URL classes = FileUtil.getFileURL(new File(CLASSES_JAR)); |
236 |
URL aspects = FileUtil.getFileURL(new File(ADVICE_ASPECTS)); |
287 |
URL aspects = FileUtil.getFileURL(new File(ADVICE_ASPECTS)); |
Lines 274-281
Link Here
|
274 |
* Aspects on ASPECTPATH but missing from CLASSPATH |
325 |
* Aspects on ASPECTPATH but missing from CLASSPATH |
275 |
*/ |
326 |
*/ |
276 |
public void testIncompletePath () { |
327 |
public void testIncompletePath () { |
277 |
System.setProperty(WeavingURLClassLoader.WEAVING_ASPECT_PATH,ADVICE_ASPECTS); |
328 |
setSystemProperty(WeavingURLClassLoader.WEAVING_ASPECT_PATH,ADVICE_ASPECTS); |
278 |
System.setProperty(WeavingURLClassLoader.WEAVING_CLASS_PATH,CLASSES_JAR); |
329 |
setSystemProperty(WeavingURLClassLoader.WEAVING_CLASS_PATH,CLASSES_JAR); |
279 |
WeavingURLClassLoader loader = new WeavingURLClassLoader(getClass().getClassLoader()); |
330 |
WeavingURLClassLoader loader = new WeavingURLClassLoader(getClass().getClassLoader()); |
280 |
|
331 |
|
281 |
try { |
332 |
try { |
Lines 291-298
Link Here
|
291 |
* Ensure package object is correct |
342 |
* Ensure package object is correct |
292 |
*/ |
343 |
*/ |
293 |
public void testPackage () { |
344 |
public void testPackage () { |
294 |
System.setProperty(WeavingURLClassLoader.WEAVING_ASPECT_PATH,""); |
345 |
setSystemProperty(WeavingURLClassLoader.WEAVING_ASPECT_PATH,""); |
295 |
System.setProperty(WeavingURLClassLoader.WEAVING_CLASS_PATH,CLASSES_JAR); |
346 |
setSystemProperty(WeavingURLClassLoader.WEAVING_CLASS_PATH,CLASSES_JAR); |
296 |
WeavingURLClassLoader loader = new WeavingURLClassLoader(getClass().getClassLoader()); |
347 |
WeavingURLClassLoader loader = new WeavingURLClassLoader(getClass().getClassLoader()); |
297 |
|
348 |
|
298 |
try { |
349 |
try { |
Lines 322-327
Link Here
|
322 |
} |
373 |
} |
323 |
catch (Exception ex) { |
374 |
catch (Exception ex) { |
324 |
throw new RuntimeException(ex.toString()); |
375 |
throw new RuntimeException(ex.toString()); |
|
|
376 |
} |
377 |
} |
378 |
|
379 |
private void setSystemProperty (String key, String value) { |
380 |
Properties systemProperties = System.getProperties(); |
381 |
copyProperty(key,systemProperties,savedProperties); |
382 |
systemProperties.setProperty(key,value); |
383 |
} |
384 |
|
385 |
private static void copyProperty (String key, Properties from, Properties to) { |
386 |
String value = from.getProperty(key,NULL); |
387 |
to.setProperty(key,value); |
388 |
} |
389 |
|
390 |
protected void setUp() throws Exception { |
391 |
super.setUp(); |
392 |
savedProperties = new Properties(); |
393 |
} |
394 |
|
395 |
protected void tearDown() throws Exception { |
396 |
super.tearDown(); |
397 |
|
398 |
/* Restore system properties */ |
399 |
Properties systemProperties = System.getProperties(); |
400 |
for (Enumeration enum = savedProperties.keys(); enum.hasMoreElements(); ) { |
401 |
String key = (String)enum.nextElement(); |
402 |
String value = savedProperties.getProperty(key); |
403 |
if (value == NULL) systemProperties.remove(key); |
404 |
else systemProperties.setProperty(key,value); |
325 |
} |
405 |
} |
326 |
} |
406 |
} |
327 |
|
407 |
|