Source Code Cross Referenced for SurrogateTest.java in  » Byte-Code » PROSE » ch » ethz » prose » query » 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.query 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // $Id: SurrogateTest.java,v 1.2 2004/05/12 17:26:52 anicoara Exp $
002:        // =====================================================================
003:        //
004:        // (history at end)
005:        //
006:
007:        package ch.ethz.prose.query;
008:
009:        // used packages
010:        import java.lang.reflect.Field;
011:        import java.lang.reflect.Method;
012:        import java.util.TreeMap;
013:
014:        import junit.framework.*;
015:        import ch.ethz.jvmai.*;
016:        import ch.ethz.prose.*;
017:        import ch.ethz.prose.crosscut.Crosscut;
018:        import ch.ethz.prose.crosscut.ThrowCut;
019:        import ch.ethz.prose.engine.*;
020:        import ch.ethz.prose.filter.Exceptions;
021:        import ch.ethz.prose.filter.PointCutter;
022:
023:        /**
024:         * JUnit testcase for classes ClassSurrogate, MethodSurrogate, FieldSurogate
025:         * and JoinPointRequestSurrogate.
026:         *
027:         * @version	$Revision: 1.2 $
028:         * @author	Philippe Schoch
029:         */
030:        public class SurrogateTest extends TestCase {
031:
032:            public static abstract class MyTestClass {
033:                public static int fa;
034:                public boolean fb;
035:                public static String fc;
036:                public AspectManager fd;
037:                protected int[] fe;
038:                private Object ff;
039:
040:                public static void ma() {
041:                }
042:
043:                public String mb(byte a, short b, int c, long d, float e,
044:                        double f, boolean g) {
045:                    return null;
046:                }
047:
048:                public static int mc(Object a, String b, AspectManager c,
049:                        TreeMap d, boolean e, double[] f, Throwable[][][] g) {
050:                    return 0;
051:                }
052:
053:                public abstract Class[] md();
054:
055:                protected void me() {
056:                }
057:
058:                private boolean mf() {
059:                    return true;
060:                }
061:            }
062:
063:            public static class MyExtension extends DefaultAspect {
064:                public Crosscut ca = new ThrowCut() {
065:                    public void THROW_ARGS() {
066:                    }
067:
068:                    public Class[] potentialCrosscutClasses() {
069:                        Class[] result = { LinkageError.class,
070:                                IllegalStateException.class,
071:                                InstantiationError.class,
072:                                NullPointerException.class,
073:                                RuntimeException.class, ClassFormatError.class,
074:                                UnknownError.class };
075:                        return result;
076:                    }
077:
078:                    protected PointCutter pointCutter() {
079:                        return ((Exceptions.type("InstantiationError"))
080:                                .OR(Exceptions.type("UnknownError")));
081:                    }
082:                };
083:
084:                public Crosscut cb = new ThrowCut() {
085:                    public void THROW_ARGS() {
086:                    }
087:
088:                    public Class[] potentialCrosscutClasses() {
089:                        Class[] result = { LinkageError.class,
090:                                IllegalStateException.class,
091:                                InstantiationError.class,
092:                                NullPointerException.class,
093:                                RuntimeException.class, ClassFormatError.class,
094:                                UnknownError.class };
095:                        return result;
096:                    }
097:
098:                    protected PointCutter pointCutter() {
099:                        return ((Exceptions.type("NullPointerException"))
100:                                .OR(Exceptions.type("RuntimeException")));
101:                    }
102:                };
103:
104:                public Crosscut cc = new ThrowCut() {
105:                    public void THROW_ARGS() {
106:                    }
107:
108:                    public Class[] potentialCrosscutClasses() {
109:                        Class[] result = { LinkageError.class,
110:                                IllegalStateException.class,
111:                                InstantiationError.class,
112:                                NullPointerException.class,
113:                                RuntimeException.class, ClassFormatError.class,
114:                                UnknownError.class };
115:                        return result;
116:                    }
117:
118:                    protected PointCutter pointCutter() {
119:                        return ((Exceptions.type("ClassFormatError"))
120:                                .OR(Exceptions.type("UnknownError")));
121:                    }
122:                };
123:            }
124:
125:            MyTestClass tstClsObj = null;
126:            Class tstCls = null;
127:            JVMAspectInterface ai = null;
128:
129:            /**
130:             * Construct test with given name.
131:             * @param name test name
132:             */
133:            public SurrogateTest(String name) {
134:                super (name);
135:            }
136:
137:            /**
138:             * Set up fixture.
139:             */
140:            protected void setUp() {
141:                try {
142:                    ProseSystem.startup();
143:                } catch (SystemStartupException e) {
144:                    Assert.fail("could not start ProseSystem");
145:                }
146:                tstClsObj = new MyTestClass() {
147:                    public Class[] md() {
148:                        return null;
149:                    }
150:                };
151:                tstCls = SurrogateTest.MyTestClass.class;
152:                ai = ProseSystem.getAspectManager().getJoinPointManager()
153:                        .getAspectInterface();
154:
155:            }
156:
157:            public void tearDown() {
158:                try {
159:                    ProseSystem.teardown();
160:                } catch (SystemTeardownException e) {
161:                    Assert.fail("could not teardown ProseSystem");
162:                }
163:            }
164:
165:            // create a methodSurrogate and recreate the Method.
166:            public void test0010_MethodSurrogate() {
167:                try {
168:                    Method m;
169:                    MethodSurrogate sur;
170:                    Class[] paramTypes;
171:
172:                    Method[] mArr = tstCls.getDeclaredMethods();
173:                    for (int j = 0; j < mArr.length; j++) {
174:                        m = mArr[j];
175:                        paramTypes = m.getParameterTypes();
176:                        sur = new MethodSurrogate(m);
177:                        assertTrue(
178:                                "["
179:                                        + j
180:                                        + "] name of Surrogate and method are the same",
181:                                sur.getName().equals(m.getName()));
182:                        assertTrue("[" + j
183:                                + "] recreated method is still the same", sur
184:                                .toRealInstance(tstCls.getName()).equals(m));
185:                    }
186:                } catch (Exception e) {
187:                    e.printStackTrace();
188:                }
189:            }
190:
191:            // create a fieldSurrogate and recreate the Field.
192:            public void test0020_FieldSurrogate() {
193:                try {
194:                    Field f;
195:                    FieldSurrogate sur;
196:                    Class type;
197:
198:                    Field[] fArr = tstCls.getDeclaredFields();
199:                    for (int j = 0; j < fArr.length; j++) {
200:                        f = fArr[j];
201:                        type = f.getType();
202:                        sur = new FieldSurrogate(f);
203:                        assertTrue("[" + j
204:                                + "] name of Surrogate and field are the same",
205:                                sur.getName().equals(f.getName()));
206:                        assertTrue("[" + j
207:                                + "] recreated field is still the same", sur
208:                                .toRealInstance(tstCls.getName()).equals(f));
209:                    }
210:                } catch (Exception e) {
211:                    e.printStackTrace();
212:                }
213:            }
214:
215:            // create a classSurrogate and recreate the Class.
216:            public void test0030_ClassSurrogate() {
217:                try {
218:                    Class c;
219:                    ClassSurrogate sur;
220:
221:                    Class[] cArr = new Class[] { MyTestClass.class,
222:                            MyExtension.class, SurrogateTest.class };
223:                    for (int j = 0; j < cArr.length; j++) {
224:                        c = cArr[j];
225:                        sur = new ClassSurrogate(c);
226:                        assertTrue(c.getName() + ": class names are equal", sur
227:                                .getName().equals(c.getName()));
228:                        assertTrue(c.getName() + " class is still the same",
229:                                sur.toRealInstance().equals(c));
230:                    }
231:                } catch (Exception e) {
232:                    e.printStackTrace();
233:                }
234:            }
235:
236:            // create JoinPointRequestSurrogates and recreate the JoinPointRequests.
237:            public void test0040_JoinPointRequestSurrogate() {
238:                try {
239:                    JoinPointManager jpm;
240:                    JoinPointRequest jpr;
241:                    JoinPointRequestSurrogate sur;
242:                    Method m;
243:                    Field f;
244:                    Class c;
245:                    jpm = ProseSystem.getAspectManager().getJoinPointManager();
246:                    QueryManager qm = new QueryManager(ProseSystem
247:                            .getAspectManager());
248:
249:                    Method[] mArr = tstCls.getDeclaredMethods();
250:                    for (int j = 0; j < mArr.length; j++) {
251:                        m = mArr[j];
252:
253:                        jpr = (MethodEntryRequest) jpm.createJoinPointRequest(
254:                                MethodEntryJoinPoint.KIND, m);
255:                        sur = new JoinPointRequestSurrogate(jpr);
256:                        assertTrue(
257:                                "["
258:                                        + j
259:                                        + "] recreated MethodEntryRequest is still the same",
260:                                qm.reconstructRequest(sur).equals(jpr));
261:
262:                        jpr = (MethodExitRequest) jpm.createJoinPointRequest(
263:                                MethodExitJoinPoint.KIND, m);
264:                        sur = new JoinPointRequestSurrogate(jpr);
265:                        assertTrue(
266:                                "["
267:                                        + j
268:                                        + "] recreated MethodExitRequest is still the same",
269:                                qm.reconstructRequest(sur).equals(jpr));
270:                    }
271:
272:                    Field[] fArr = tstCls.getDeclaredFields();
273:                    for (int j = 0; j < fArr.length; j++) {
274:                        f = fArr[j];
275:
276:                        jpr = (FieldAccessRequest) jpm.createJoinPointRequest(
277:                                FieldAccessJoinPoint.KIND, f);
278:                        sur = new JoinPointRequestSurrogate(jpr);
279:                        assertTrue(
280:                                "["
281:                                        + j
282:                                        + "] recreated FieldAccessRequest is still the same",
283:                                qm.reconstructRequest(sur).equals(jpr));
284:
285:                        jpr = (FieldModificationRequest) jpm
286:                                .createJoinPointRequest(
287:                                        FieldModificationJoinPoint.KIND, f);
288:                        sur = new JoinPointRequestSurrogate(jpr);
289:                        assertTrue(
290:                                "["
291:                                        + j
292:                                        + "] recreated FieldModificationRequest is still the same",
293:                                qm.reconstructRequest(sur).equals(jpr));
294:                    }
295:
296:                    Class[] cArr = new Class[] { Error.class,
297:                            SystemStartupException.class,
298:                            ArrayIndexOutOfBoundsException.class };
299:                    for (int j = 0; j < cArr.length; j++) {
300:                        c = cArr[j];
301:
302:                        jpr = (ExceptionThrowRequest) jpm
303:                                .createJoinPointRequest(
304:                                        ExceptionJoinPoint.KIND, c);
305:                        sur = new JoinPointRequestSurrogate(jpr);
306:                        assertTrue(
307:                                "["
308:                                        + j
309:                                        + "] recreated ExceptionThrowRequest is still the same",
310:                                qm.reconstructRequest(sur).equals(jpr));
311:
312:                    }
313:                } catch (Exception e) {
314:                    e.printStackTrace();
315:                }
316:            }
317:
318:            public void test0050_equals() {
319:                Method m;
320:                Field f;
321:                Class c;
322:                Aspect ext = new MyExtension();
323:                Crosscut cr = new ThrowCut() {
324:                    public void THROW_ARGS() {
325:                    }
326:
327:                    public Class[] potentialCrosscutClasses() {
328:                        Class[] result = { LinkageError.class,
329:                                IllegalStateException.class,
330:                                InstantiationError.class,
331:                                NullPointerException.class,
332:                                RuntimeException.class, ClassFormatError.class,
333:                                UnknownError.class };
334:                        return result;
335:                    }
336:
337:                    protected PointCutter pointCutter() {
338:                        return ((Exceptions.type("InstantiationError"))
339:                                .OR(Exceptions.type("UnknownError")));
340:                    }
341:                };
342:
343:                JoinPointManager jpm = ProseSystem.getAspectManager()
344:                        .getJoinPointManager();
345:                try {
346:                    Class c1 = MyTestClass.class;
347:                    Class c2 = MyTestClass.class;
348:                    ClassSurrogate s1 = new ClassSurrogate(c1);
349:                    ClassSurrogate s2 = new ClassSurrogate(c2);
350:                    assertEquals("ClassSurrogate equals", s1, s2);
351:
352:                    MethodSurrogate sur1, sur2;
353:                    Class[] paramTypes;
354:                    Method[] mArr = tstCls.getDeclaredMethods();
355:                    for (int j = 0; j < mArr.length; j++) {
356:                        m = mArr[j];
357:                        paramTypes = m.getParameterTypes();
358:                        sur1 = new MethodSurrogate(m);
359:                        sur2 = new MethodSurrogate(m);
360:                        assertEquals("MethodSurrogate equals", sur1, sur2);
361:                    }
362:
363:                    FieldSurrogate fsur1, fsur2;
364:                    Class type;
365:                    Field[] fArr = tstCls.getDeclaredFields();
366:                    for (int j = 0; j < fArr.length; j++) {
367:                        f = fArr[j];
368:                        type = f.getType();
369:                        fsur1 = new FieldSurrogate(f);
370:                        fsur2 = new FieldSurrogate(f);
371:                        assertEquals("FieldSurrogate equals", fsur1, fsur2);
372:                    }
373:
374:                    JoinPointRequest jpr;
375:                    JoinPointRequestSurrogate jsur1, jsur2;
376:
377:                    mArr = tstCls.getDeclaredMethods();
378:                    for (int j = 0; j < mArr.length; j++) {
379:                        m = mArr[j];
380:
381:                        jpr = (MethodEntryRequest) jpm.createJoinPointRequest(
382:                                MethodEntryJoinPoint.KIND, m);
383:                        jsur1 = new JoinPointRequestSurrogate(jpr);
384:                        jsur2 = new JoinPointRequestSurrogate(jpr);
385:                        assertEquals("JoinPointRequestSurrogate equals "
386:                                + jsur1.getKind(), jsur1, jsur2);
387:                        assertEquals("Tupel equals" + jsur1.getKind(),
388:                                new Tuple(new AspectSurrogate(ext),
389:                                        new CrosscutSurrogate(
390:                                                new AspectSurrogate(ext), cr),
391:                                        jsur1), new Tuple(new AspectSurrogate(
392:                                        ext), new CrosscutSurrogate(
393:                                        new AspectSurrogate(ext), cr), jsur2));
394:
395:                        jpr = (MethodExitRequest) jpm.createJoinPointRequest(
396:                                MethodExitJoinPoint.KIND, m);
397:                        jsur1 = new JoinPointRequestSurrogate(jpr);
398:                        jsur2 = new JoinPointRequestSurrogate(jpr);
399:                        assertEquals("JoinPointRequestSurrogate equals "
400:                                + jsur1.getKind(), jsur1, jsur2);
401:                    }
402:
403:                    fArr = tstCls.getDeclaredFields();
404:                    for (int j = 0; j < fArr.length; j++) {
405:                        f = fArr[j];
406:
407:                        jpr = (FieldAccessRequest) jpm.createJoinPointRequest(
408:                                FieldAccessJoinPoint.KIND, f);
409:                        jsur1 = new JoinPointRequestSurrogate(jpr);
410:                        jsur2 = new JoinPointRequestSurrogate(jpr);
411:                        assertEquals("JoinPointRequestSurrogate equals "
412:                                + jsur1.getKind(), jsur1, jsur2);
413:
414:                        jpr = (FieldModificationRequest) jpm
415:                                .createJoinPointRequest(
416:                                        FieldModificationJoinPoint.KIND, f);
417:                        jsur1 = new JoinPointRequestSurrogate(jpr);
418:                        jsur2 = new JoinPointRequestSurrogate(jpr);
419:                        assertEquals("JoinPointRequestSurrogate equals "
420:                                + jsur1.getKind(), jsur1, jsur2);
421:                    }
422:
423:                    Class[] cArr = new Class[] { Error.class,
424:                            SystemStartupException.class,
425:                            ArrayIndexOutOfBoundsException.class };
426:                    for (int j = 0; j < cArr.length; j++) {
427:                        c = cArr[j];
428:
429:                        jpr = (ExceptionThrowRequest) jpm
430:                                .createJoinPointRequest(
431:                                        ExceptionJoinPoint.KIND, c);
432:                        jsur1 = new JoinPointRequestSurrogate(jpr);
433:                        jsur2 = new JoinPointRequestSurrogate(jpr);
434:                        assertEquals("JoinPointRequestSurrogate equals "
435:                                + jsur1.getKind(), jsur1, jsur2);
436:                    }
437:                } catch (Exception e) {
438:                    e.printStackTrace();
439:                }
440:            }
441:
442:            /**
443:             * Test suite.
444:             * @return test instance
445:             */
446:            public static Test suite() {
447:                return new TestSuite(SurrogateTest.class);
448:            }
449:
450:        }
451:
452:        //======================================================================
453:        //
454:        // $Log: SurrogateTest.java,v $
455:        // Revision 1.2  2004/05/12 17:26:52  anicoara
456:        // Adapt Junit tests to 3.8.1 version and the new package structure
457:        //
458:        // Revision 1.1.1.1  2003/07/02 15:30:43  apopovic
459:        // Imported from ETH Zurich
460:        //
461:        // Revision 1.2  2003/05/20 16:04:57  popovici
462:        //
463:        // New QueryManager replaces functionality in AspectManager (better Soc)
464:        // New 'Surrogate' classes for usage in the QueryManager
465:        // The 'RemoteAspectManager' and tools modified to use the Surrogates and the QueryManager
466:        //
467:        // Revision 1.1  2003/05/05 14:03:42  popovici
468:        // renaming from runes to prose
469:        //
470:        // Revision 1.10  2003/04/27 13:09:03  popovici
471:        // Specializers renamed to PointCutter
472:        //
473:        // Revision 1.9  2003/04/26 18:51:46  popovici
474:        // 1 Bug fix which lead to a refactoring step:
475:        //    1. the bug: 'JoinPointRequests' used to write to a static list, which survived a startup/teardown;
476:        //                now this list belongs to the JoinPointManager;
477:        //    2. the refactoring: the JoinPointManager now creates (and shares state) with join-points.
478:        //
479:        // Revision 1.8  2003/04/17 15:15:18  popovici
480:        // Extension->Aspect renaming
481:        //
482:        // Revision 1.7  2003/04/17 14:51:16  popovici
483:        // ExceptionS renamed to Exception; method renamings
484:        //
485:        // Revision 1.6  2003/04/17 12:49:45  popovici
486:        // Refactoring of the crosscut package
487:        //  ExceptionCut renamed to ThrowCut
488:        //  McutSignature is now SignaturePattern
489:        //
490:        // Revision 1.5  2003/04/17 08:46:55  popovici
491:        // Important functionality additions
492:        //  - Cflow specializers
493:        //  - Restructuring of the MethodCut, SetCut, ThrowCut, and GetCut (they are much smaller)
494:        //  - Transactional capabilities
495:        //  - Total refactoring of Specializer evaluation, which permits fine-grained distinction
496:        //    between static and dynamic specializers.
497:        //  - Functionality pulled up in abstract classes
498:        //  - Uniformization of advice methods patterns and names
499:        //
500:        // Revision 1.4  2003/03/04 18:36:43  popovici
501:        // Organization of imprts
502:        //
503:        // Revision 1.3  2003/03/04 11:26:06  popovici
504:        // Important refactorization step (march):
505:        // - removal of 'JoinPointEvents'; JoinPoints now have the same function as events
506:        // - reimplementation of the JVMAIDebuggerAspectInterface (better performance, coding conventions, removal of ProseVM
507:        //   structures
508:        //
509:        // Revision 1.2  2003/01/27 12:52:23  pschoch
510:        // Advice-Method now without parameter
511:        //
512:        // Revision 1.1  2003/01/17 17:19:28  pschoch
513:        // Tests for Surrogate package
514:        //
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.