KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ch > ethz > prose > JVMInfoInterfaceTest


1 // $Id: JVMInfoInterfaceTest.java,v 1.3 2004/05/12 17:26:51 anicoara Exp $
2
// =====================================================================
3
//
4
// (history at end)
5
//
6

7 package ch.ethz.prose;
8
9 // used packages
10
import java.lang.reflect.Field JavaDoc;
11 import java.lang.reflect.Method JavaDoc;
12 import java.util.Date JavaDoc;
13 import java.util.List JavaDoc;
14
15 import junit.framework.*;
16 import ch.ethz.jvmai.*;
17 /**
18  * JUnit testcase for class JVMInfoInterface.
19  *
20  * @version $Revision: 1.3 $
21  * @author Stephan Markwalder
22  * @author Angela Nicoara
23  */

24 public
25 class JVMInfoInterfaceTest extends TestCase {
26
27   JVMAspectInterface aspectInterface = null;
28
29   Method JavaDoc method = null;
30   Field JavaDoc field = null;
31
32   /**
33    * Construct test with given name.
34    * @param name test name
35    */

36   public JVMInfoInterfaceTest(String JavaDoc name)
37   {
38     super(name);
39   }
40
41   static class TestClass1 {
42     public int field;
43     public String JavaDoc parameterInput = "";
44     public int method(boolean a, byte b, short c, int d, long e, float f, double g, char h, Object JavaDoc i, String JavaDoc j)
45     {
46       parameterInput = "a=" + a + "/b=" + b + "/c=" + c + "/d=" + d + "/e=" + e + "/f=" + f + "/g=" + g + "/h=" + h;
47       a=true;
48       b = (byte)-b;
49       c = (short)-c;
50       d = -d;
51       e = -e;
52       f = -f;
53       g = -g;
54       h = 'z';
55       i = new Date JavaDoc();
56       j = "moon";
57       return d*2;
58     }
59   }
60
61     static class TestException extends RuntimeException JavaDoc
62     {}
63
64     static class TestClass2 {
65     }
66
67
68   protected void setUp() throws Exception JavaDoc
69   {
70     String JavaDoc providerClassName = System.getProperty("ch.ethz.prose.JVMAIProvider","ch.ethz.inf.iks.jvmai.jvmdi.DebuggerProvider");
71     Class JavaDoc providerClass = Class.forName(providerClassName);
72     Provider provider = (Provider)providerClass.newInstance();
73     aspectInterface = provider.getAspectInterface();
74
75     aspectInterface.startup(new String JavaDoc[0],true); // has no effect if JVMAspectInterfaceTest has already run.
76

77     method = TestClass1.class.getDeclaredMethods()[0];
78     field = TestClass1.class.getDeclaredFields()[0];
79   }
80
81
82   protected void tearDown()
83   {
84     try
85     {
86       try { aspectInterface.clearMethodEntryWatch (method); } catch (RuntimeException JavaDoc e) { }
87       try { aspectInterface.clearMethodExitWatch (method); } catch (RuntimeException JavaDoc e) { }
88       try { aspectInterface.clearFieldAccessWatch (field); } catch (RuntimeException JavaDoc e) { }
89       try { aspectInterface.clearFieldModificationWatch(field ); } catch (RuntimeException JavaDoc e) { }
90       try { aspectInterface.clearExceptionThrowWatch (TestException.class); } catch (RuntimeException JavaDoc e) { }
91       try { aspectInterface.clearExceptionCatchWatch (TestException.class); } catch (RuntimeException JavaDoc e) { }
92       try { aspectInterface.setJoinPointHook(null); } catch (RuntimeException JavaDoc e) { }
93       aspectInterface.teardown();
94     }
95     catch (RuntimeException JavaDoc e)
96     {
97     }
98   }
99
100
101     public void test_0010_GetLoadedClasses()
102     {
103
104     List JavaDoc classes = aspectInterface.getLoadedClasses();
105     assertTrue("class TestClass1 is loaded",classes.contains(TestClass1.class));
106     }
107
108     class TestKindHook extends JoinPointHook
109     {
110     String JavaDoc ofaKind = null;
111     String JavaDoc ofmKind = null;
112     String JavaDoc omenKind = null;
113     String JavaDoc omexKind = null;
114     String JavaDoc oexKind = null;
115     String JavaDoc oexcKind = null;
116     public void onFieldAccess(FieldAccessJoinPoint joinPoint) { ofaKind = joinPoint.getKind(); }
117     public void onFieldModification(FieldModificationJoinPoint joinPoint) { ofmKind = joinPoint.getKind(); }
118     public void onMethodEntry(MethodEntryJoinPoint joinPoint) { omenKind = joinPoint.getKind(); }
119     public void onMethodExit(MethodExitJoinPoint joinPoint) { omexKind = joinPoint.getKind(); }
120     public void onExceptionThrow(ExceptionJoinPoint joinPoint) { oexKind = joinPoint.getKind(); }
121     public void onExceptionCatch(ExceptionCatchJoinPoint joinPoint) { oexcKind = joinPoint.getKind(); }
122     public void onClassLoad(Class JavaDoc cls) { }
123     };
124
125
126     public void test_0030_GetJoinPointKinds()
127     {
128     TestKindHook hook=new TestKindHook();
129     TestClass1 test = new TestClass1();
130
131     aspectInterface.setFieldAccessWatch (field ,"hi");
132     aspectInterface.setFieldModificationWatch(field ,"there");
133     aspectInterface.setMethodEntryWatch (method,"how are");
134     aspectInterface.setMethodExitWatch (method,"you");
135     aspectInterface.setExceptionThrowWatch (TestException.class,"you");
136     aspectInterface.setExceptionCatchWatch (TestException.class,"you");
137     aspectInterface.resumeNotification(Thread.currentThread());
138
139     aspectInterface.setJoinPointHook(hook);
140     enclosingLevel1(test);
141     aspectInterface.setJoinPointHook(null);
142
143     assertEquals("Field modif",FieldModificationJoinPoint.KIND,hook.ofmKind);
144     assertEquals("Method entry",MethodEntryJoinPoint.KIND,hook.omenKind);
145     assertEquals("Method exit",MethodExitJoinPoint.KIND,hook.omexKind);
146     assertEquals("Exception throw",ExceptionJoinPoint.KIND,hook.oexKind);
147     assertEquals("Exception catch",ExceptionCatchJoinPoint.KIND,hook.oexcKind);
148     assertEquals("Field access",FieldAccessJoinPoint.KIND,hook.ofaKind);
149     aspectInterface.clearFieldAccessWatch (field );
150     aspectInterface.clearFieldModificationWatch(field );
151     aspectInterface.clearMethodEntryWatch (method);
152     aspectInterface.clearMethodExitWatch (method);
153     aspectInterface.clearExceptionThrowWatch (TestException.class);
154     aspectInterface.clearExceptionCatchWatch (TestException.class);
155
156     }
157
158     private void enclosingLevel1(TestClass1 test)
159     {
160     int t = test.method(false,(byte)1,(short)2,3,4l,5.0f,6.0,'a',"hello","world");
161     test.field = test.field + 1;
162     try { throw new TestException(); } catch (Exception JavaDoc e) {}
163     }
164
165     private void enclosingLevel2(int i)
166     {
167     TestClass1 test = new TestClass1();
168     enclosingLevel1(test);
169     }
170
171     private void enclosingLevel3()
172     {
173     enclosingLevel2(1);
174     }
175
176     class TestEnclosingHook extends JoinPointHook
177     {
178     Method JavaDoc[] caller = new Method JavaDoc[6];
179     Method JavaDoc[] callerCaller = new Method JavaDoc[6];
180     Object JavaDoc[] thisCaller = new Object JavaDoc[6];
181     Object JavaDoc[] thisCallerCaller = new Object JavaDoc[6];
182     public void onFieldAccess(FieldAccessJoinPoint joinPoint)
183     {
184         CodeJoinPoint callerJp = joinPoint.getEnclosingJoinPoint();
185         caller[0] = callerJp.getMethod();
186         thisCaller[0] = callerJp.getThis();
187         CodeJoinPoint callerCallerJp = callerJp.getEnclosingJoinPoint();
188         callerCaller[0] = callerCallerJp.getMethod();
189         thisCallerCaller[0] = callerCallerJp.getThis();
190     }
191     public void onFieldModification(FieldModificationJoinPoint joinPoint)
192     {
193         CodeJoinPoint callerJp = joinPoint.getEnclosingJoinPoint();
194         caller[1] = callerJp.getMethod();
195         thisCaller[1] = callerJp.getThis();
196         CodeJoinPoint callerCallerJp = callerJp.getEnclosingJoinPoint();
197         callerCaller[1] = callerCallerJp.getMethod();
198         thisCallerCaller[1] = callerCallerJp.getThis();
199     }
200     public void onMethodEntry(MethodEntryJoinPoint joinPoint)
201     {
202
203         CodeJoinPoint callerJp = joinPoint.getEnclosingJoinPoint();
204         caller[2] = callerJp.getMethod();
205         thisCaller[2] = callerJp.getThis();
206         CodeJoinPoint callerCallerJp = callerJp.getEnclosingJoinPoint();
207         callerCaller[2] = callerCallerJp.getMethod();
208         thisCallerCaller[2] = callerCallerJp.getThis();
209     }
210     public void onMethodExit(MethodExitJoinPoint joinPoint)
211     {
212         CodeJoinPoint callerJp = joinPoint.getEnclosingJoinPoint();
213         caller[3] = callerJp.getMethod();
214         thisCaller[3] = callerJp.getThis();
215         CodeJoinPoint callerCallerJp = callerJp.getEnclosingJoinPoint();
216         callerCaller[3] = callerCallerJp.getMethod();
217         thisCallerCaller[3] = callerCallerJp.getThis();
218     }
219     public void onExceptionThrow(ExceptionJoinPoint joinPoint)
220     {
221         CodeJoinPoint callerJp = joinPoint.getEnclosingJoinPoint();
222         caller[4] = callerJp.getMethod();
223         thisCaller[4] = callerJp.getThis();
224         CodeJoinPoint callerCallerJp = callerJp.getEnclosingJoinPoint();
225         callerCaller[4] = callerCallerJp.getMethod();
226         thisCallerCaller[4] = callerCallerJp.getThis();
227     }
228
229     public void onExceptionCatch(ExceptionCatchJoinPoint joinPoint)
230     {
231         CodeJoinPoint callerJp = joinPoint.getEnclosingJoinPoint();
232         caller[5] = callerJp.getMethod();
233         thisCaller[5] = callerJp.getThis();
234         CodeJoinPoint callerCallerJp = callerJp.getEnclosingJoinPoint();
235         callerCaller[5] = callerCallerJp.getMethod();
236         thisCallerCaller[5] = callerCallerJp.getThis();
237     }
238
239     public void onClassLoad(Class JavaDoc cls) {}
240     };
241
242
243     public void test_0025_GetEnclosingJoinPoint()
244     {
245     aspectInterface.setFieldAccessWatch (field ,"hi");
246     aspectInterface.setFieldModificationWatch(field ,"there");
247     aspectInterface.setMethodEntryWatch (method,"how are");
248     aspectInterface.setMethodExitWatch (method,"you");
249     aspectInterface.setExceptionThrowWatch (TestException.class,"you");
250     aspectInterface.setExceptionCatchWatch (TestException.class,"you");
251     TestEnclosingHook hook = new TestEnclosingHook();
252     aspectInterface.setJoinPointHook(hook);
253     enclosingLevel3();
254     aspectInterface.setJoinPointHook(null);
255
256     assertEquals("Caller " + 0 + " is enclosingLevel1","enclosingLevel2",hook.caller[0].getName());
257     assertEquals("Caller " + 1 + " is enclosingLevel1","enclosingLevel2",hook.caller[1].getName());
258     assertEquals("Caller " + 2 + " is enclosingLevel1","enclosingLevel1",hook.caller[2].getName());
259     assertEquals("Caller " + 3 + " is enclosingLevel1","enclosingLevel1",hook.caller[3].getName());
260     assertEquals("Caller " + 4 + " is enclosingLevel1","enclosingLevel2",hook.caller[4].getName());
261     assertEquals("Caller " + 5 + " is enclosingLevel1","enclosingLevel2",hook.caller[5].getName());
262
263     assertEquals("This " + 0 + " is enclosingLevel1",this,hook.thisCaller[0]);
264     assertEquals("This " + 1 + " is enclosingLevel1",this,hook.thisCaller[1]);
265     assertEquals("This " + 2 + " is enclosingLevel1",this,hook.thisCaller[2]);
266     assertEquals("This " + 3 + " is enclosingLevel1",this,hook.thisCaller[3]);
267     assertEquals("This " + 4 + " is enclosingLevel1",this,hook.thisCaller[4]);
268     assertEquals("This " + 5 + " is enclosingLevel1",this,hook.thisCaller[5]);
269
270     assertEquals("CCaller " + 0 + " is enclosingLevel1","enclosingLevel3",hook.callerCaller[0].getName());
271     assertEquals("CCaller " + 1 + " is enclosingLevel1","enclosingLevel3",hook.callerCaller[1].getName());
272     assertEquals("CCaller " + 2 + " is enclosingLevel1","enclosingLevel2",hook.callerCaller[2].getName());
273     assertEquals("CCaller " + 3 + " is enclosingLevel1","enclosingLevel2",hook.callerCaller[3].getName());
274     assertEquals("CCaller " + 4 + " is enclosingLevel1","enclosingLevel3",hook.callerCaller[4].getName());
275     assertEquals("CCaller " + 5 + " is enclosingLevel1","enclosingLevel3",hook.callerCaller[5].getName());
276     }
277
278     public void test_0030_GetLocalVariableInfo()
279     {
280     // FIXME: must be replaced with a test that checks
281
// whether the names of the parameters in a hook
282
// method are ok.
283

284     }
285
286
287
288   public void test_0040_GetFieldJoinPointInfo()
289   {
290
291     Object JavaDoc aopTag = new Object JavaDoc();
292     JoinPointHook hook = null;
293     TestClass1 test = new TestClass1();
294
295     hook = new JoinPointHook() {
296       public void onFieldAccess(FieldAccessJoinPoint joinPoint) {
297
298         assertEquals("fieldClass and fieldId denote field",field,joinPoint.getField());
299         assertTrue("getFieldOwner returns an instance of TestClass1",joinPoint.getTarget() instanceof TestClass1);
300         Integer JavaDoc value = (Integer JavaDoc)joinPoint.getValue();
301     // FIXME!! infoInterface.setFieldValue(joinPoint,new Integer(value.intValue()+1));
302
}
303       public void onFieldModification(FieldModificationJoinPoint joinPoint) {
304         assertEquals("fieldClass and fieldId denote field",field,joinPoint.getField());
305         assertTrue("getFieldOwner returns an instance of TestClass1",joinPoint.getTarget() instanceof TestClass1);
306         Integer JavaDoc value1 = (Integer JavaDoc)joinPoint.getValue();
307         Integer JavaDoc value2 = (Integer JavaDoc)joinPoint.getNewValue();
308     // FIXME!! infoInterface.setNewFieldValue(joinPoint,new Integer(value2.intValue()+value1.intValue()));
309
}
310       public void onMethodEntry(MethodEntryJoinPoint joinPoint) { }
311       public void onMethodExit(MethodExitJoinPoint joinPoint) { }
312       public void onExceptionThrow(ExceptionJoinPoint joinPoint) { }
313       public void onExceptionCatch(ExceptionCatchJoinPoint joinPoint) { }
314       public void onClassLoad(Class JavaDoc cls) { }
315     };
316
317     aspectInterface.setJoinPointHook(hook);
318
319     test.field = 1;
320
321     aspectInterface.setFieldAccessWatch (field ,aopTag);
322     aspectInterface.setFieldModificationWatch(field ,aopTag);
323
324
325     // check if we can modifiy (read and write) the field's value at a field-joinpoint
326
int r = test.field; // onFieldAccess is adding 1 to the value of the field (before returning the value)
327
aspectInterface.suspendNotification(Thread.currentThread());
328     assertTrue("onFieldAccess was able to change the field value",test.field==2);
329     aspectInterface.resumeNotification(Thread.currentThread());
330
331     // check if we can modify (read and write) the field's new value assigned to a it at a field-joinpoint
332
test.field = 3; // onFieldModification is adding the new value to the old value
333
aspectInterface.suspendNotification(Thread.currentThread());
334     assertTrue("onFieldModification was able to change the new field value",test.field==5);
335     aspectInterface.resumeNotification(Thread.currentThread());
336
337   }
338
339
340
341   public void test_0050_GetMethodJoinPointInfo()
342   {
343
344     Object JavaDoc aopTag = new Object JavaDoc();
345     JoinPointHook hook = null;
346     TestClass1 test = new TestClass1();
347
348     hook = new JoinPointHook() {
349       public void onFieldAccess(FieldAccessJoinPoint joinPoint) { }
350       public void onFieldModification(FieldModificationJoinPoint joinPoint) { }
351       public void onMethodEntry(MethodEntryJoinPoint joinPoint) {
352
353
354         assertEquals("methodClass and methodId denotes method",method,joinPoint.getMethod());
355         assertTrue("getThisValue returns an instance of TestClass1",joinPoint.getThis() instanceof TestClass1);
356
357         Object JavaDoc[] params = joinPoint.getArgs();
358
359         assertTrue("type of param[1] is ok",params[0] instanceof Boolean JavaDoc);
360         assertTrue("type of param[2] is ok",params[1] instanceof Byte JavaDoc);
361         assertTrue("type of param[3] is ok",params[2] instanceof Short JavaDoc);
362         assertTrue("type of param[4] is ok",params[3] instanceof Integer JavaDoc);
363         assertTrue("type of param[5] is ok",params[4] instanceof Long JavaDoc);
364         assertTrue("type of param[6] is ok",params[5] instanceof Float JavaDoc);
365         assertTrue("type of param[7] is ok",params[6] instanceof Double JavaDoc);
366         assertTrue("type of param[8] is ok",params[7] instanceof Character JavaDoc);
367         assertTrue("type of param[9] is ok",params[8] instanceof Object JavaDoc);
368         assertTrue("type of param[10] is ok",params[9] instanceof String JavaDoc);
369
370         assertTrue("value of param[1] is ok",params[0].equals(new Boolean JavaDoc(false)));
371         assertTrue("value of param[2] is ok",params[1].equals(new Byte JavaDoc((byte)1)));
372         assertTrue("value of param[3] is ok",params[2].equals(new Short JavaDoc((short)2)));
373         assertTrue("value of param[4] is ok",params[3].equals(new Integer JavaDoc(3)));
374         assertTrue("value of param[5] is ok",params[4].equals(new Long JavaDoc(4l)));
375         assertTrue("value of param[6] is ok",params[5].equals(new Float JavaDoc(5.0f)));
376         assertTrue("value of param[7] is ok",params[6].equals(new Double JavaDoc(6.0)));
377         assertTrue("value of param[8] is ok",params[7].equals(new Character JavaDoc('a')));
378         assertTrue("value of param[9] is ok",params[8].equals("hello"));
379         assertTrue("value of param[10] is ok",params[9].equals("world"));
380
381         joinPoint.setArg(0,new Boolean JavaDoc(true));
382         joinPoint.setArg(1,new Byte JavaDoc((byte)10));
383         joinPoint.setArg(2,new Short JavaDoc((short)20));
384         joinPoint.setArg(3,new Integer JavaDoc(30));
385         joinPoint.setArg(4,new Long JavaDoc(40l));
386         joinPoint.setArg(5,new Float JavaDoc(50.0f));
387         joinPoint.setArg(6,new Double JavaDoc(60.0));
388         joinPoint.setArg(7,new Character JavaDoc('k'));
389         joinPoint.setArg(8,"olleh");
390         joinPoint.setArg(9,"dlrow");
391       }
392
393       public void onMethodExit(MethodExitJoinPoint joinPoint) {
394         assertEquals("methodClass and methodId denotes method",method,joinPoint.getMethod());
395         assertTrue("getThisValue returns an instance of TestClass1",joinPoint.getThis() instanceof TestClass1);
396
397         Object JavaDoc[] params = joinPoint.getArgs();
398
399
400         assertTrue("type of param[1] is ok",params[0] instanceof Boolean JavaDoc);
401         assertTrue("type of param[2] is ok",params[1] instanceof Byte JavaDoc);
402         assertTrue("type of param[3] is ok",params[2] instanceof Short JavaDoc);
403         assertTrue("type of param[4] is ok",params[3] instanceof Integer JavaDoc);
404         assertTrue("type of param[5] is ok",params[4] instanceof Long JavaDoc);
405         assertTrue("type of param[6] is ok",params[5] instanceof Float JavaDoc);
406         assertTrue("type of param[7] is ok",params[6] instanceof Double JavaDoc);
407         assertTrue("type of param[8] is ok",params[7] instanceof Character JavaDoc);
408         assertTrue("type of param[9] is ok",params[8] instanceof Object JavaDoc);
409         assertTrue("type of param[10] is ok",params[9] instanceof String JavaDoc);
410
411         assertTrue("value of param[1] is ok",params[0].equals(new Boolean JavaDoc(true)));
412         assertTrue("value of param[2] is ok",params[1].equals(new Byte JavaDoc((byte)-10)));
413         assertTrue("value of param[3] is ok",params[2].equals(new Short JavaDoc((short)-20)));
414         assertTrue("value of param[4] is ok",params[3].equals(new Integer JavaDoc(-30)));
415         assertTrue("value of param[5] is ok",params[4].equals(new Long JavaDoc(-40l)));
416         assertTrue("value of param[6] is ok",params[5].equals(new Float JavaDoc(-50.0f)));
417         assertTrue("value of param[7] is ok",params[6].equals(new Double JavaDoc(-60.0)));
418         assertTrue("value of param[8] is ok",params[7].equals(new Character JavaDoc('z')));
419         assertTrue("value of param[9] is ok",params[8] instanceof Date JavaDoc);
420         assertTrue("value of param[10] is ok",params[9].equals("moon"));
421
422     // FIXME: new Aspect interface does now allow set arguments on
423
// method exit join points.
424
// int exceptions = 0;
425
// try { joinPoint.setArg(1,new Integer(1) ); } catch (JVMAIRuntimeException e) { exceptions++; }
426
// try { joinPoint.setArg(1,null ); } catch (JVMAIRuntimeException e) { exceptions++; }
427
// try { joinPoint.setArg(1,"invalid" ); } catch (JVMAIRuntimeException e) { exceptions++; }
428
// try { joinPoint.setArg(2,new Short((short)1)); } catch (JVMAIRuntimeException e) { exceptions++; }
429
// try { joinPoint.setArg(2,null ); } catch (JVMAIRuntimeException e) { exceptions++; }
430
// try { joinPoint.setArg(2,"invalid" ); } catch (JVMAIRuntimeException e) { exceptions++; }
431
// try { joinPoint.setArg(3,new Byte((byte)1) ); } catch (JVMAIRuntimeException e) { exceptions++; }
432
// try { joinPoint.setArg(3,new Integer(1) ); } catch (JVMAIRuntimeException e) { exceptions++; }
433
// try { joinPoint.setArg(3,null ); } catch (JVMAIRuntimeException e) { exceptions++; }
434
// try { joinPoint.setArg(4,new Byte((byte)1) ); } catch (JVMAIRuntimeException e) { exceptions++; }
435
// try { joinPoint.setArg(4,new Float(1.0f) ); } catch (JVMAIRuntimeException e) { exceptions++; }
436
// try { joinPoint.setArg(4,null ); } catch (JVMAIRuntimeException e) { exceptions++; }
437
// try { joinPoint.setArg(5,new Integer(1) ); } catch (JVMAIRuntimeException e) { exceptions++; }
438
// try { joinPoint.setArg(5,new Double(1.0) ); } catch (JVMAIRuntimeException e) { exceptions++; }
439
// try { joinPoint.setArg(5,null ); } catch (JVMAIRuntimeException e) { exceptions++; }
440
// try { joinPoint.setArg(6,new Integer(1) ); } catch (JVMAIRuntimeException e) { exceptions++; }
441
// try { joinPoint.setArg(6,new Double(1.0) ); } catch (JVMAIRuntimeException e) { exceptions++; }
442
// try { joinPoint.setArg(6,null ); } catch (JVMAIRuntimeException e) { exceptions++; }
443
// try { joinPoint.setArg(7,new Integer(1) ); } catch (JVMAIRuntimeException e) { exceptions++; }
444
// try { joinPoint.setArg(7,new Float(1.0f) ); } catch (JVMAIRuntimeException e) { exceptions++; }
445
// try { joinPoint.setArg(7,null ); } catch (JVMAIRuntimeException e) { exceptions++; }
446
// try { joinPoint.setArg(8,new Byte((byte)1) ); } catch (JVMAIRuntimeException e) { exceptions++; }
447
// try { joinPoint.setArg(8,new Integer(1) ); } catch (JVMAIRuntimeException e) { exceptions++; }
448
// try { joinPoint.setArg(8,null ); } catch (JVMAIRuntimeException e) { exceptions++; }
449
// try { joinPoint.setArg(10,new Date() ); } catch (JVMAIRuntimeException e) { exceptions++; }
450
// assertTrue("25 exceptions because of type-missmatch",exceptions==25);
451

452 // exceptions = 0;
453
// try { joinPoint.setArg(9,new Integer(1) ); } catch (JVMAIRuntimeException e) { exceptions++; }
454
// try { joinPoint.setArg(9,new Byte((byte)1) ); } catch (JVMAIRuntimeException e) { exceptions++; }
455
// try { joinPoint.setArg(9,null ); } catch (JVMAIRuntimeException e) { exceptions++; }
456
// try { joinPoint.setArg(10,new String("1") ); } catch (JVMAIRuntimeException e) { exceptions++; }
457
// try { joinPoint.setArg(10,null ); } catch (JVMAIRuntimeException e) { exceptions++; }
458
// assertTrue("no exceptions because of type-missmatch",exceptions==0);
459

460
461     try
462       {
463     Integer JavaDoc value = (Integer JavaDoc)joinPoint.getResult();
464         joinPoint.setResult(new Integer JavaDoc(value.intValue()+1));
465       }
466     catch (RuntimeException JavaDoc x)
467       {
468
469       }
470
471       }
472       public void onExceptionThrow(ExceptionJoinPoint joinPoint) { }
473       public void onExceptionCatch(ExceptionCatchJoinPoint joinPoint) { }
474       public void onClassLoad(Class JavaDoc cls) { }
475     };
476
477
478     aspectInterface.setJoinPointHook(hook);
479
480     aspectInterface.setMethodEntryWatch (method,aopTag);
481     aspectInterface.setMethodExitWatch (method,aopTag);
482
483     int t = test.method(false,(byte)1,(short)2,3,4l,5.0f,6.0,'a',"hello","world");
484
485
486     aspectInterface.clearMethodEntryWatch (method);
487     aspectInterface.clearMethodExitWatch (method);
488
489     assertTrue("onMethodExit was able to change the return value",t==-59);
490
491
492   }
493
494
495   /**
496    * Test suite.
497    * @return test instance
498    */

499   public static
500   Test suite()
501   {
502     return new TestSuite(JVMInfoInterfaceTest.class);
503   }
504
505 }
506
507
508 //======================================================================
509
//
510
// $Log: JVMInfoInterfaceTest.java,v $
511
// Revision 1.3 2004/05/12 17:26:51 anicoara
512
// Adapt Junit tests to 3.8.1 version and the new package structure
513
//
514
// Revision 1.1.1.1 2003/07/02 15:30:42 apopovic
515
// Imported from ETH Zurich
516
//
517
// Revision 1.2 2003/07/02 12:42:34 anicoara
518
// Added CatchJoinPoint Functionality (Requests, Join-Points, Filters, CatchCuts, Tests)
519
//
520
// Revision 1.1 2003/05/05 14:02:33 popovici
521
// renaming from runes to prose
522
//
523
// Revision 1.7 2003/04/30 20:16:18 popovici
524
// Changes for windows portability
525
//
526
// Revision 1.6 2003/04/30 14:50:11 popovici
527
// junit test for checking parameter modification added; tests for checking parameters modification (old) updated; they used to fail silently
528
//
529
// Revision 1.5 2003/04/17 15:15:02 popovici
530
// Extension->Aspect renaming
531
//
532
// Revision 1.4 2003/04/17 12:49:39 popovici
533
// Refactoring of the crosscut package
534
// ExceptionCut renamed to ThrowCut
535
// McutSignature is now SignaturePattern
536
//
537
// Revision 1.3 2003/04/17 08:46:44 popovici
538
// Important functionality additions
539
// - Cflow specializers
540
// - Restructuring of the MethodCut, SetCut, ThrowCut, and GetCut (they are much smaller)
541
// - Transactional capabilities
542
// - Total refactoring of Specializer evaluation, which permits fine-grained distinction
543
// between static and dynamic specializers.
544
// - Functionality pulled up in abstract classes
545
// - Uniformization of advice methods patterns and names
546
//
547
// Revision 1.2 2003/03/04 18:36:09 popovici
548
// Organization of imprts
549
//
550
// Revision 1.1 2003/03/04 12:10:28 popovici
551
// Moved from inf/jvmai (whitebox location) to inf/runes/ (bb location)
552
//
553
// Revision 1.5 2002/11/26 17:15:23 pschoch
554
// RootComponent now added (replaces RootComponent now added (replaces old ProseSystem)
555
// ProseSystem now owns and starts the Aspect interface.
556
// ProseSystem now containes a 'test' AspectManager
557
// AspectManager now owns the JoinPointManager.
558
// ExtensionManger can be 'connected' to the JVM, or disconnected. The
559
// JoinPointManager of a connected Ext.Mgr enables joinpoints; the
560
// JoinPointManger of a disconnected Ext.Mgr never enables join-points
561
// Documentation updated accordingly.
562
//
563
// Revision 1.4 2002/10/17 17:05:46 pschoch
564
// Added throw capabability to JVMAI
565
//
566
// Revision 1.3 2002/02/15 17:21:02 popovici
567
// *** empty log message ***
568
//
569
// Revision 1.2 2002/02/15 12:27:25 smarkwal
570
// doesn't rely anymore on Provider.getProvider(...)
571
//
572
// Revision 1.1 2002/02/05 11:13:15 smarkwal
573
// Initial revision
574
//
575
//
576
Popular Tags