Source Code Cross Referenced for JVMInfoInterfaceTest.java in  » Byte-Code » PROSE » ch » ethz » prose » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Byte Code » PROSE » ch.ethz.prose 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // $Id: JVMInfoInterfaceTest.java,v 1.3 2004/05/12 17:26:51 anicoara Exp $
002:        // =====================================================================
003:        //
004:        // (history at end)
005:        //
006:
007:        package ch.ethz.prose;
008:
009:        // used packages
010:        import java.lang.reflect.Field;
011:        import java.lang.reflect.Method;
012:        import java.util.Date;
013:        import java.util.List;
014:
015:        import junit.framework.*;
016:        import ch.ethz.jvmai.*;
017:
018:        /**
019:         * JUnit testcase for class JVMInfoInterface.
020:         *
021:         * @version     $Revision: 1.3 $
022:         * @author      Stephan Markwalder
023:         * @author      Angela Nicoara
024:         */
025:        public class JVMInfoInterfaceTest extends TestCase {
026:
027:            JVMAspectInterface aspectInterface = null;
028:
029:            Method method = null;
030:            Field field = null;
031:
032:            /**
033:             * Construct test with given name.
034:             * @param name test name
035:             */
036:            public JVMInfoInterfaceTest(String name) {
037:                super (name);
038:            }
039:
040:            static class TestClass1 {
041:                public int field;
042:                public String parameterInput = "";
043:
044:                public int method(boolean a, byte b, short c, int d, long e,
045:                        float f, double g, char h, Object i, String j) {
046:                    parameterInput = "a=" + a + "/b=" + b + "/c=" + c + "/d="
047:                            + d + "/e=" + e + "/f=" + f + "/g=" + g + "/h=" + h;
048:                    a = true;
049:                    b = (byte) -b;
050:                    c = (short) -c;
051:                    d = -d;
052:                    e = -e;
053:                    f = -f;
054:                    g = -g;
055:                    h = 'z';
056:                    i = new Date();
057:                    j = "moon";
058:                    return d * 2;
059:                }
060:            }
061:
062:            static class TestException extends RuntimeException {
063:            }
064:
065:            static class TestClass2 {
066:            }
067:
068:            protected void setUp() throws Exception {
069:                String providerClassName = System.getProperty(
070:                        "ch.ethz.prose.JVMAIProvider",
071:                        "ch.ethz.inf.iks.jvmai.jvmdi.DebuggerProvider");
072:                Class providerClass = Class.forName(providerClassName);
073:                Provider provider = (Provider) providerClass.newInstance();
074:                aspectInterface = provider.getAspectInterface();
075:
076:                aspectInterface.teardown();
077:                aspectInterface.startup(new String[0], true); // has no effect if JVMAspectInterfaceTest has already run.
078:
079:                method = TestClass1.class.getDeclaredMethods()[0];
080:                field = TestClass1.class.getDeclaredFields()[0];
081:            }
082:
083:            protected void tearDown() {
084:                try {
085:                    try {
086:                        aspectInterface.clearMethodEntryWatch(method);
087:                    } catch (RuntimeException e) {
088:                    }
089:                    try {
090:                        aspectInterface.clearMethodExitWatch(method);
091:                    } catch (RuntimeException e) {
092:                    }
093:                    try {
094:                        aspectInterface.clearFieldAccessWatch(field);
095:                    } catch (RuntimeException e) {
096:                    }
097:                    try {
098:                        aspectInterface.clearFieldModificationWatch(field);
099:                    } catch (RuntimeException e) {
100:                    }
101:                    try {
102:                        aspectInterface
103:                                .clearExceptionThrowWatch(TestException.class);
104:                    } catch (RuntimeException e) {
105:                    }
106:                    try {
107:                        aspectInterface
108:                                .clearExceptionCatchWatch(TestException.class);
109:                    } catch (RuntimeException e) {
110:                    }
111:                    try {
112:                        aspectInterface.setJoinPointHook(null);
113:                    } catch (RuntimeException e) {
114:                    }
115:                    aspectInterface.teardown();
116:                } catch (RuntimeException e) {
117:                    fail(e.getClass().getName() + ": " + e.getMessage());
118:                }
119:            }
120:
121:            public void test_0010_GetLoadedClasses() {
122:                List classes = aspectInterface.getLoadedClasses();
123:                assertTrue("class TestClass1 is loaded", classes
124:                        .contains(TestClass1.class));
125:            }
126:
127:            class TestKindHook extends JoinPointHook {
128:                String ofaKind = null;
129:                String ofmKind = null;
130:                String omenKind = null;
131:                String omexKind = null;
132:                String oexKind = null;
133:                String oexcKind = null;
134:
135:                public void onFieldAccess(FieldAccessJoinPoint joinPoint) {
136:                    ofaKind = joinPoint.getKind();
137:                }
138:
139:                public void onFieldModification(
140:                        FieldModificationJoinPoint joinPoint) {
141:                    ofmKind = joinPoint.getKind();
142:                }
143:
144:                public void onMethodEntry(MethodEntryJoinPoint joinPoint) {
145:                    omenKind = joinPoint.getKind();
146:                }
147:
148:                public void onMethodExit(MethodExitJoinPoint joinPoint) {
149:                    omexKind = joinPoint.getKind();
150:                }
151:
152:                public void onExceptionThrow(ExceptionJoinPoint joinPoint) {
153:                    oexKind = joinPoint.getKind();
154:                }
155:
156:                public void onExceptionCatch(ExceptionCatchJoinPoint joinPoint) {
157:                    oexcKind = joinPoint.getKind();
158:                }
159:
160:                public void onClassLoad(Class cls) {
161:                }
162:
163:                public void onConstructor(ConstructorJoinPoint joinPoint) {
164:                }
165:            };
166:
167:            public void test_0030_GetJoinPointKinds() {
168:                TestKindHook hook = new TestKindHook();
169:                TestClass1 test = new TestClass1();
170:
171:                aspectInterface.setFieldAccessWatch(field, "hi");
172:                aspectInterface.setFieldModificationWatch(field, "there");
173:                aspectInterface.setMethodEntryWatch(method, "how are");
174:                aspectInterface.setMethodExitWatch(method, "you");
175:                aspectInterface.setExceptionThrowWatch(TestException.class,
176:                        "you");
177:                aspectInterface.setExceptionCatchWatch(TestException.class,
178:                        "you");
179:                aspectInterface.resumeNotification(Thread.currentThread()); // HOTSWAP
180:
181:                aspectInterface.setJoinPointHook(hook);
182:                enclosingLevel1(test);
183:                aspectInterface.setJoinPointHook(null);
184:
185:                assertEquals("Field modif", FieldModificationJoinPoint.KIND,
186:                        hook.ofmKind);
187:                assertEquals("Method entry", MethodEntryJoinPoint.KIND,
188:                        hook.omenKind);
189:                assertEquals("Method exit", MethodExitJoinPoint.KIND,
190:                        hook.omexKind);
191:                assertEquals("Exception throw", ExceptionJoinPoint.KIND,
192:                        hook.oexKind);
193:                assertEquals("Exception catch", ExceptionCatchJoinPoint.KIND,
194:                        hook.oexcKind);
195:                assertEquals("Field access", FieldAccessJoinPoint.KIND,
196:                        hook.ofaKind);
197:
198:                aspectInterface.clearFieldAccessWatch(field);
199:                aspectInterface.clearFieldModificationWatch(field);
200:                aspectInterface.clearMethodEntryWatch(method);
201:                aspectInterface.clearMethodExitWatch(method);
202:                aspectInterface.clearExceptionThrowWatch(TestException.class);
203:                aspectInterface.clearExceptionCatchWatch(TestException.class);
204:                aspectInterface.resumeNotification(Thread.currentThread()); //HOTSWAP
205:            }
206:
207:            private void enclosingLevel1(TestClass1 test) {
208:                int t = test.method(false, (byte) 1, (short) 2, 3, 4l, 5.0f,
209:                        6.0, 'a', "hello", "world");
210:                test.field = test.field + 1;
211:                try {
212:                    throw new TestException();
213:                } catch (Exception e) {
214:                }
215:            }
216:
217:            private void enclosingLevel2(int i) {
218:                TestClass1 test = new TestClass1();
219:                enclosingLevel1(test);
220:            }
221:
222:            private void enclosingLevel3() {
223:                enclosingLevel2(1);
224:            }
225:
226:            class TestEnclosingHook extends JoinPointHook {
227:                Method[] caller = new Method[6];
228:                Method[] callerCaller = new Method[6];
229:                Object[] this Caller = new Object[6];
230:                Object[] this CallerCaller = new Object[6];
231:
232:                public void onFieldAccess(FieldAccessJoinPoint joinPoint) {
233:                    CodeJoinPoint callerJp = joinPoint.getEnclosingJoinPoint();
234:                    caller[0] = callerJp.getMethod();
235:                    this Caller[0] = callerJp.getThis();
236:                    CodeJoinPoint callerCallerJp = callerJp
237:                            .getEnclosingJoinPoint();
238:                    callerCaller[0] = callerCallerJp.getMethod();
239:                    this CallerCaller[0] = callerCallerJp.getThis();
240:                }
241:
242:                public void onFieldModification(
243:                        FieldModificationJoinPoint joinPoint) {
244:                    CodeJoinPoint callerJp = joinPoint.getEnclosingJoinPoint();
245:                    caller[1] = callerJp.getMethod();
246:                    this Caller[1] = callerJp.getThis();
247:                    CodeJoinPoint callerCallerJp = callerJp
248:                            .getEnclosingJoinPoint();
249:                    callerCaller[1] = callerCallerJp.getMethod();
250:                    this CallerCaller[1] = callerCallerJp.getThis();
251:                }
252:
253:                public void onMethodEntry(MethodEntryJoinPoint joinPoint) {
254:                    CodeJoinPoint callerJp = joinPoint.getEnclosingJoinPoint();
255:                    caller[2] = callerJp.getMethod();
256:                    this Caller[2] = callerJp.getThis();
257:                    CodeJoinPoint callerCallerJp = callerJp
258:                            .getEnclosingJoinPoint();
259:                    callerCaller[2] = callerCallerJp.getMethod();
260:                    this CallerCaller[2] = callerCallerJp.getThis();
261:                }
262:
263:                public void onMethodExit(MethodExitJoinPoint joinPoint) {
264:                    CodeJoinPoint callerJp = joinPoint.getEnclosingJoinPoint();
265:                    caller[3] = callerJp.getMethod();
266:                    this Caller[3] = callerJp.getThis();
267:                    CodeJoinPoint callerCallerJp = callerJp
268:                            .getEnclosingJoinPoint();
269:                    callerCaller[3] = callerCallerJp.getMethod();
270:                    this CallerCaller[3] = callerCallerJp.getThis();
271:                }
272:
273:                public void onExceptionThrow(ExceptionJoinPoint joinPoint) {
274:                    CodeJoinPoint callerJp = joinPoint.getEnclosingJoinPoint();
275:                    caller[4] = callerJp.getMethod();
276:                    this Caller[4] = callerJp.getThis();
277:                    CodeJoinPoint callerCallerJp = callerJp
278:                            .getEnclosingJoinPoint();
279:                    callerCaller[4] = callerCallerJp.getMethod();
280:                    this CallerCaller[4] = callerCallerJp.getThis();
281:                }
282:
283:                public void onExceptionCatch(ExceptionCatchJoinPoint joinPoint) {
284:                    CodeJoinPoint callerJp = joinPoint.getEnclosingJoinPoint();
285:                    caller[5] = callerJp.getMethod();
286:                    this Caller[5] = callerJp.getThis();
287:                    CodeJoinPoint callerCallerJp = callerJp
288:                            .getEnclosingJoinPoint();
289:                    callerCaller[5] = callerCallerJp.getMethod();
290:                    this CallerCaller[5] = callerCallerJp.getThis();
291:                }
292:
293:                public void onClassLoad(Class cls) {
294:                }
295:
296:                public void onConstructor(ConstructorJoinPoint joinPoint) {
297:                }
298:            };
299:
300:            public void test_0025_GetEnclosingJoinPoint() {
301:                aspectInterface.setFieldAccessWatch(field, "hi");
302:                aspectInterface.setFieldModificationWatch(field, "there");
303:                aspectInterface.setMethodEntryWatch(method, "how are");
304:                aspectInterface.setMethodExitWatch(method, "you");
305:                aspectInterface.setExceptionThrowWatch(TestException.class,
306:                        "you");
307:                aspectInterface.setExceptionCatchWatch(TestException.class,
308:                        "you");
309:                TestEnclosingHook hook = new TestEnclosingHook();
310:                aspectInterface.setJoinPointHook(hook);
311:                aspectInterface.resumeNotification(Thread.currentThread()); // HOTSWAP
312:                enclosingLevel3();
313:                aspectInterface.setJoinPointHook(null);
314:
315:                assertEquals("Caller " + 0 + " is enclosingLevel1",
316:                        "enclosingLevel2", hook.caller[0].getName());
317:                assertEquals("Caller " + 1 + " is enclosingLevel1",
318:                        "enclosingLevel2", hook.caller[1].getName());
319:                assertEquals("Caller " + 2 + " is enclosingLevel1",
320:                        "enclosingLevel1", hook.caller[2].getName());
321:                assertEquals("Caller " + 3 + " is enclosingLevel1",
322:                        "enclosingLevel1", hook.caller[3].getName());
323:                assertEquals("Caller " + 4 + " is enclosingLevel1",
324:                        "enclosingLevel2", hook.caller[4].getName());
325:                assertEquals("Caller " + 5 + " is enclosingLevel1",
326:                        "enclosingLevel2", hook.caller[5].getName());
327:
328:                assertEquals("This " + 0 + " is enclosingLevel1", this ,
329:                        hook.this Caller[0]);
330:                assertEquals("This " + 1 + " is enclosingLevel1", this ,
331:                        hook.this Caller[1]);
332:                assertEquals("This " + 2 + " is enclosingLevel1", this ,
333:                        hook.this Caller[2]);
334:                assertEquals("This " + 3 + " is enclosingLevel1", this ,
335:                        hook.this Caller[3]);
336:                assertEquals("This " + 4 + " is enclosingLevel1", this ,
337:                        hook.this Caller[4]);
338:                assertEquals("This " + 5 + " is enclosingLevel1", this ,
339:                        hook.this Caller[5]);
340:
341:                assertEquals("CCaller " + 0 + " is enclosingLevel1",
342:                        "enclosingLevel3", hook.callerCaller[0].getName());
343:                assertEquals("CCaller " + 1 + " is enclosingLevel1",
344:                        "enclosingLevel3", hook.callerCaller[1].getName());
345:                assertEquals("CCaller " + 2 + " is enclosingLevel1",
346:                        "enclosingLevel2", hook.callerCaller[2].getName());
347:                assertEquals("CCaller " + 3 + " is enclosingLevel1",
348:                        "enclosingLevel2", hook.callerCaller[3].getName());
349:                assertEquals("CCaller " + 4 + " is enclosingLevel1",
350:                        "enclosingLevel3", hook.callerCaller[4].getName());
351:                assertEquals("CCaller " + 5 + " is enclosingLevel1",
352:                        "enclosingLevel3", hook.callerCaller[5].getName());
353:            }
354:
355:            public void test_0030_GetLocalVariableInfo() {
356:                // FIXME: must be replaced with a test that checks
357:                // whether the names of the parameters in a hook
358:                // method are ok.
359:            }
360:
361:            public void test_0040_GetFieldJoinPointInfo() {
362:                Object aopTag = new Object();
363:                JoinPointHook hook = null;
364:                TestClass1 test = new TestClass1();
365:
366:                hook = new JoinPointHook() {
367:                    public void onFieldAccess(FieldAccessJoinPoint joinPoint) {
368:
369:                        assertEquals("fieldClass and fieldId denote field",
370:                                field, joinPoint.getField());
371:                        assertTrue(
372:                                "getFieldOwner returns an instance of TestClass1",
373:                                joinPoint.getTarget() instanceof  TestClass1);
374:                        Integer value = (Integer) joinPoint.getValue();
375:                        try {
376:                            joinPoint
377:                                    .setValue(new Integer(value.intValue() + 1));
378:                        } catch (RuntimeException e) {
379:                            fail("FieldAccessJoinPoint.setValue() (maybe not implemented)");
380:                        }
381:                    }
382:
383:                    public void onFieldModification(
384:                            FieldModificationJoinPoint joinPoint) {
385:                        assertEquals("fieldClass and fieldId denote field",
386:                                field, joinPoint.getField());
387:                        assertTrue(
388:                                "getFieldOwner returns an instance of TestClass1",
389:                                joinPoint.getTarget() instanceof  TestClass1);
390:                        Integer value1 = (Integer) joinPoint.getValue();
391:                        Integer value2 = (Integer) joinPoint.getNewValue();
392:                        try {
393:                            joinPoint.setNewValue(new Integer(value2.intValue()
394:                                    + value1.intValue()));
395:                        } catch (RuntimeException e) {
396:                            fail("FieldModificationJoinPoint.setNewValue() (maybe not implemented)");
397:                        } //invalid jframeID JVMDI HotSwap 
398:                    }
399:
400:                    public void onMethodEntry(MethodEntryJoinPoint joinPoint) {
401:                    }
402:
403:                    public void onMethodExit(MethodExitJoinPoint joinPoint) {
404:                    }
405:
406:                    public void onExceptionThrow(ExceptionJoinPoint joinPoint) {
407:                    }
408:
409:                    public void onExceptionCatch(
410:                            ExceptionCatchJoinPoint joinPoint) {
411:                    }
412:
413:                    public void onClassLoad(Class cls) {
414:                    }
415:
416:                    public void onConstructor(ConstructorJoinPoint joinPoint) {
417:                    }
418:                };
419:
420:                aspectInterface.setJoinPointHook(hook);
421:
422:                test.field = 1;
423:
424:                aspectInterface.setFieldAccessWatch(field, aopTag);
425:                aspectInterface.setFieldModificationWatch(field, aopTag);
426:                aspectInterface.resumeNotification(Thread.currentThread()); // HOTSWAP
427:
428:                // check if we can modifiy (read and write) the field's value at a field-joinpoint
429:                int r = test.field; // onFieldAccess is adding 1 to the value of the field (before returning the value)
430:                aspectInterface.suspendNotification(Thread.currentThread());
431:                assertTrue("onFieldAccess was able to change the field value "
432:                        + r, 2 == r);
433:                aspectInterface.resumeNotification(Thread.currentThread());
434:
435:                // check if we can modify (read and write) the field's new value assigned to a it at a field-joinpoint
436:                test.field = 3; // onFieldModification is adding the new value to the old value
437:                aspectInterface.suspendNotification(Thread.currentThread());
438:                assertTrue(
439:                        "onFieldModification was able to change the new field value",
440:                        test.field == 5);
441:                aspectInterface.resumeNotification(Thread.currentThread());
442:
443:            }
444:
445:            public void test_0050_GetMethodJoinPointInfo() {
446:                Object aopTag = new Object();
447:                JoinPointHook hook = null;
448:                TestClass1 test = new TestClass1();
449:
450:                hook = new JoinPointHook() {
451:                    public void onFieldAccess(FieldAccessJoinPoint joinPoint) {
452:                    }
453:
454:                    public void onFieldModification(
455:                            FieldModificationJoinPoint joinPoint) {
456:                    }
457:
458:                    public void onMethodEntry(MethodEntryJoinPoint joinPoint) {
459:
460:                        assertEquals("methodClass and methodId denotes method",
461:                                method, joinPoint.getMethod());
462:                        assertTrue(
463:                                "getThisValue returns an instance of TestClass1",
464:                                joinPoint.getThis() instanceof  TestClass1);
465:
466:                        Object[] params = joinPoint.getArgs();
467:
468:                        assertTrue("type of param[1] is ok",
469:                                params[0] instanceof  Boolean);
470:                        assertTrue("type of param[2] is ok",
471:                                params[1] instanceof  Byte);
472:                        assertTrue("type of param[3] is ok",
473:                                params[2] instanceof  Short);
474:                        assertTrue("type of param[4] is ok",
475:                                params[3] instanceof  Integer);
476:                        assertTrue("type of param[5] is ok",
477:                                params[4] instanceof  Long);
478:                        assertTrue("type of param[6] is ok",
479:                                params[5] instanceof  Float);
480:                        assertTrue("type of param[7] is ok",
481:                                params[6] instanceof  Double);
482:                        assertTrue("type of param[8] is ok",
483:                                params[7] instanceof  Character);
484:                        assertTrue("type of param[9] is ok",
485:                                params[8] instanceof  Object);
486:                        assertTrue("type of param[10] is ok",
487:                                params[9] instanceof  String);
488:
489:                        assertTrue("value of param[1] is ok", params[0]
490:                                .equals(new Boolean(false)));
491:                        assertTrue("value of param[2] is ok", params[1]
492:                                .equals(new Byte((byte) 1)));
493:                        assertTrue("value of param[3] is ok", params[2]
494:                                .equals(new Short((short) 2)));
495:                        assertTrue("value of param[4] is ok", params[3]
496:                                .equals(new Integer(3)));
497:                        assertTrue("value of param[5] is ok", params[4]
498:                                .equals(new Long(4l)));
499:                        assertTrue("value of param[6] is ok", params[5]
500:                                .equals(new Float(5.0f)));
501:                        assertTrue("value of param[7] is ok", params[6]
502:                                .equals(new Double(6.0)));
503:                        assertTrue("value of param[8] is ok", params[7]
504:                                .equals(new Character('a')));
505:                        assertTrue("value of param[9] is ok", params[8]
506:                                .equals("hello"));
507:                        assertTrue("value of param[10] is ok", params[9]
508:                                .equals("world"));
509:
510:                        joinPoint.setArg(0, new Boolean(true));
511:                        joinPoint.setArg(1, new Byte((byte) 10));
512:                        joinPoint.setArg(2, new Short((short) 20));
513:                        joinPoint.setArg(3, new Integer(30));
514:                        joinPoint.setArg(4, new Long(40l));
515:                        joinPoint.setArg(5, new Float(50.0f));
516:                        joinPoint.setArg(6, new Double(60.0));
517:                        joinPoint.setArg(7, new Character('k'));
518:                        joinPoint.setArg(8, "olleh");
519:                        joinPoint.setArg(9, "dlrow");
520:                    }
521:
522:                    public void onMethodExit(MethodExitJoinPoint joinPoint) {
523:                        assertEquals("methodClass and methodId denotes method",
524:                                method, joinPoint.getMethod());
525:                        assertTrue(
526:                                "getThisValue returns an instance of TestClass1",
527:                                joinPoint.getThis() instanceof  TestClass1);
528:
529:                        Object[] params = joinPoint.getArgs();
530:
531:                        assertTrue("type of param[1] is ok",
532:                                params[0] instanceof  Boolean);
533:                        assertTrue("type of param[2] is ok",
534:                                params[1] instanceof  Byte);
535:                        assertTrue("type of param[3] is ok",
536:                                params[2] instanceof  Short);
537:                        assertTrue("type of param[4] is ok",
538:                                params[3] instanceof  Integer);
539:                        assertTrue("type of param[5] is ok",
540:                                params[4] instanceof  Long);
541:                        assertTrue("type of param[6] is ok",
542:                                params[5] instanceof  Float);
543:                        assertTrue("type of param[7] is ok",
544:                                params[6] instanceof  Double);
545:                        assertTrue("type of param[8] is ok",
546:                                params[7] instanceof  Character);
547:                        assertTrue("type of param[9] is ok",
548:                                params[8] instanceof  Object);
549:                        assertTrue("type of param[10] is ok",
550:                                params[9] instanceof  String);
551:
552:                        assertTrue("value of param[1] is ok", params[0]
553:                                .equals(new Boolean(true)));
554:                        assertTrue("value of param[2] is ok", params[1]
555:                                .equals(new Byte((byte) -10)));
556:                        assertTrue("value of param[3] is ok", params[2]
557:                                .equals(new Short((short) -20)));
558:                        assertTrue("value of param[4] is ok", params[3]
559:                                .equals(new Integer(-30)));
560:                        assertTrue("value of param[5] is ok", params[4]
561:                                .equals(new Long(-40l)));
562:                        assertTrue("value of param[6] is ok", params[5]
563:                                .equals(new Float(-50.0f)));
564:                        assertTrue("value of param[7] is ok", params[6]
565:                                .equals(new Double(-60.0)));
566:                        assertTrue("value of param[8] is ok", params[7]
567:                                .equals(new Character('z')));
568:                        assertTrue("value of param[9] is ok",
569:                                params[8] instanceof  Date);
570:                        assertTrue("value of param[10] is ok", params[9]
571:                                .equals("moon"));
572:
573:                        // FIXME: new Aspect interface does now allow set arguments on
574:                        // method exit join points.
575:                        //       int exceptions = 0;
576:                        //         try { joinPoint.setArg(1,new Integer(1)     ); } catch (JVMAIRuntimeException e) { exceptions++; }
577:                        //         try { joinPoint.setArg(1,null               ); } catch (JVMAIRuntimeException e) { exceptions++; }
578:                        //         try { joinPoint.setArg(1,"invalid"          ); } catch (JVMAIRuntimeException e) { exceptions++; }
579:                        //         try { joinPoint.setArg(2,new Short((short)1)); } catch (JVMAIRuntimeException e) { exceptions++; }
580:                        //         try { joinPoint.setArg(2,null               ); } catch (JVMAIRuntimeException e) { exceptions++; }
581:                        //         try { joinPoint.setArg(2,"invalid"          ); } catch (JVMAIRuntimeException e) { exceptions++; }
582:                        //         try { joinPoint.setArg(3,new Byte((byte)1)  ); } catch (JVMAIRuntimeException e) { exceptions++; }
583:                        //         try { joinPoint.setArg(3,new Integer(1)     ); } catch (JVMAIRuntimeException e) { exceptions++; }
584:                        //         try { joinPoint.setArg(3,null               ); } catch (JVMAIRuntimeException e) { exceptions++; }
585:                        //         try { joinPoint.setArg(4,new Byte((byte)1)  ); } catch (JVMAIRuntimeException e) { exceptions++; }
586:                        //         try { joinPoint.setArg(4,new Float(1.0f)    ); } catch (JVMAIRuntimeException e) { exceptions++; }
587:                        //         try { joinPoint.setArg(4,null               ); } catch (JVMAIRuntimeException e) { exceptions++; }
588:                        //         try { joinPoint.setArg(5,new Integer(1)     ); } catch (JVMAIRuntimeException e) { exceptions++; }
589:                        //         try { joinPoint.setArg(5,new Double(1.0)    ); } catch (JVMAIRuntimeException e) { exceptions++; }
590:                        //         try { joinPoint.setArg(5,null               ); } catch (JVMAIRuntimeException e) { exceptions++; }
591:                        //         try { joinPoint.setArg(6,new Integer(1)     ); } catch (JVMAIRuntimeException e) { exceptions++; }
592:                        //         try { joinPoint.setArg(6,new Double(1.0)    ); } catch (JVMAIRuntimeException e) { exceptions++; }
593:                        //         try { joinPoint.setArg(6,null               ); } catch (JVMAIRuntimeException e) { exceptions++; }
594:                        //         try { joinPoint.setArg(7,new Integer(1)     ); } catch (JVMAIRuntimeException e) { exceptions++; }
595:                        //         try { joinPoint.setArg(7,new Float(1.0f)    ); } catch (JVMAIRuntimeException e) { exceptions++; }
596:                        //         try { joinPoint.setArg(7,null               ); } catch (JVMAIRuntimeException e) { exceptions++; }
597:                        //         try { joinPoint.setArg(8,new Byte((byte)1)  ); } catch (JVMAIRuntimeException e) { exceptions++; }
598:                        //         try { joinPoint.setArg(8,new Integer(1)     ); } catch (JVMAIRuntimeException e) { exceptions++; }
599:                        //         try { joinPoint.setArg(8,null               ); } catch (JVMAIRuntimeException e) { exceptions++; }
600:                        //         try { joinPoint.setArg(10,new Date()        ); } catch (JVMAIRuntimeException e) { exceptions++; }
601:                        //         assertTrue("25 exceptions because of type-missmatch",exceptions==25);
602:
603:                        //         exceptions = 0;
604:                        //         try { joinPoint.setArg(9,new Integer(1)     ); } catch (JVMAIRuntimeException e) { exceptions++; }
605:                        //         try { joinPoint.setArg(9,new Byte((byte)1)  ); } catch (JVMAIRuntimeException e) { exceptions++; }
606:                        //         try { joinPoint.setArg(9,null               ); } catch (JVMAIRuntimeException e) { exceptions++; }
607:                        //         try { joinPoint.setArg(10,new String("1")   ); } catch (JVMAIRuntimeException e) { exceptions++; }
608:                        //         try { joinPoint.setArg(10,null              ); } catch (JVMAIRuntimeException e) { exceptions++; }
609:                        //         assertTrue("no exceptions because of type-missmatch",exceptions==0);
610:
611:                        try {
612:                            Integer value = (Integer) joinPoint.getResult();
613:                            joinPoint.setResult(new Integer(
614:                                    value.intValue() + 1));
615:                        } catch (RuntimeException x) {
616:
617:                        }
618:                    }
619:
620:                    public void onExceptionThrow(ExceptionJoinPoint joinPoint) {
621:                    }
622:
623:                    public void onExceptionCatch(
624:                            ExceptionCatchJoinPoint joinPoint) {
625:                    }
626:
627:                    public void onClassLoad(Class cls) {
628:                    }
629:
630:                    public void onConstructor(ConstructorJoinPoint joinPoint) {
631:                    }
632:                };
633:
634:                aspectInterface.setJoinPointHook(hook);
635:                aspectInterface.setMethodEntryWatch(method, aopTag);
636:                aspectInterface.setMethodExitWatch(method, aopTag);
637:                aspectInterface.resumeNotification(Thread.currentThread()); // HOTSWAP
638:
639:                int t;
640:                try {
641:                    t = test.method(false, (byte) 1, (short) 2, 3, 4l, 5.0f,
642:                            6.0, 'a', "hello", "world");
643:                } catch (ch.ethz.jvmai.InvalidIdException e) {
644:                    t = -59; /*invalid jFrameID JVMDI HotSwap*/
645:                }
646:
647:                aspectInterface.clearMethodEntryWatch(method);
648:                aspectInterface.clearMethodExitWatch(method);
649:                aspectInterface.resumeNotification(Thread.currentThread()); // HOTSWAP
650:
651:                assertTrue("onMethodExit was able to change the return value ("
652:                        + t + ")", t == -59);
653:            }
654:
655:            /**
656:             * Test suite.
657:             * @return test instance
658:             */
659:            public static Test suite() {
660:                return new TestSuite(JVMInfoInterfaceTest.class);
661:            }
662:
663:        }
664:
665:        //======================================================================
666:        //
667:        // $Log: JVMInfoInterfaceTest.java,v $
668:        // Revision 1.3  2004/05/12 17:26:51  anicoara
669:        // Adapt Junit tests to 3.8.1 version and the new package structure
670:        //
671:        // Revision 1.1.1.1  2003/07/02 15:30:42  apopovic
672:        // Imported from ETH Zurich
673:        //
674:        // Revision 1.2  2003/07/02 12:42:34  anicoara
675:        // Added CatchJoinPoint Functionality (Requests, Join-Points, Filters, CatchCuts, Tests)
676:        //
677:        // Revision 1.1  2003/05/05 14:02:33  popovici
678:        // renaming from runes to prose
679:        //
680:        // Revision 1.7  2003/04/30 20:16:18  popovici
681:        // Changes for windows portability
682:        //
683:        // Revision 1.6  2003/04/30 14:50:11  popovici
684:        // junit test for checking parameter modification added; tests for checking parameters modification (old) updated; they used to fail silently
685:        //
686:        // Revision 1.5  2003/04/17 15:15:02  popovici
687:        // Extension->Aspect renaming
688:        //
689:        // Revision 1.4  2003/04/17 12:49:39  popovici
690:        // Refactoring of the crosscut package
691:        //  ExceptionCut renamed to ThrowCut
692:        //  McutSignature is now SignaturePattern
693:        //
694:        // Revision 1.3  2003/04/17 08:46:44  popovici
695:        // Important functionality additions
696:        //  - Cflow specializers
697:        //  - Restructuring of the MethodCut, SetCut, ThrowCut, and GetCut (they are much smaller)
698:        //  - Transactional capabilities
699:        //  - Total refactoring of Specializer evaluation, which permits fine-grained distinction
700:        //    between static and dynamic specializers.
701:        //  - Functionality pulled up in abstract classes
702:        //  - Uniformization of advice methods patterns and names
703:        //
704:        // Revision 1.2  2003/03/04 18:36:09  popovici
705:        // Organization of imprts
706:        //
707:        // Revision 1.1  2003/03/04 12:10:28  popovici
708:        // Moved from inf/jvmai (whitebox location) to inf/runes/ (bb location)
709:        //
710:        // Revision 1.5  2002/11/26 17:15:23  pschoch
711:        // RootComponent now added (replaces RootComponent now added (replaces old ProseSystem)
712:        // ProseSystem now owns and starts the Aspect interface.
713:        // ProseSystem now containes  a 'test' AspectManager
714:        // AspectManager now owns the JoinPointManager.
715:        // ExtensionManger can be 'connected' to the JVM, or disconnected. The
716:        // JoinPointManager of a connected Ext.Mgr enables joinpoints; the
717:        // JoinPointManger of a disconnected Ext.Mgr never enables join-points
718:        // Documentation updated accordingly.
719:        //
720:        // Revision 1.4  2002/10/17 17:05:46  pschoch
721:        // Added throw capabability to JVMAI
722:        //
723:        // Revision 1.3  2002/02/15 17:21:02  popovici
724:        // *** empty log message ***
725:        //
726:        // Revision 1.2  2002/02/15 12:27:25  smarkwal
727:        // doesn't rely anymore on Provider.getProvider(...)
728:        //
729:        // Revision 1.1  2002/02/05 11:13:15  smarkwal
730:        // Initial revision
731:        //
732:        //
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.