KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ch > ethz > prose > crosscut > FunctionalCrosscutTest


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

7 package ch.ethz.prose.crosscut;
8
9 // used packages
10
import java.lang.reflect.Method JavaDoc;
11 import java.util.*;
12
13 import junit.framework.*;
14 import ch.ethz.prose.ProseSystem;
15 import ch.ethz.prose.filter.PointCutter;
16 import ch.ethz.prose.filter.Within;
17
18 /**
19  * JUnit testcase for class FunctionalCrosscut.
20  *
21  * @version $Revision: 1.2 $
22  * @author Andrei Popovici
23  */

24 public
25 class FunctionalCrosscutTest extends TestCase {
26
27   // fixture
28
class FunctionalCrosscutExample extends MethodCut
29   {
30     void METHOD_ARGS(ANY thisObject,REST params)
31     {
32         System.err.println(">>>" + thisObject.getObject() + "/" + params.getObject());
33     }
34
35     protected PointCutter pointCutter()
36     {
37         return null;
38     }
39   }
40
41   /**
42    * Construct test with given name.
43    * @param name test name
44    */

45   public FunctionalCrosscutTest(String JavaDoc name)
46   {
47       super(name);
48   }
49
50   List lastEACall;
51   MethodCut exampleCrosscut1 = null;
52   MethodCut exampleCrosscut2 = null;
53   MethodCut exampleCrosscut3 = null;
54   MethodCut exampleCrosscut4 = null;
55   MethodCut exampleCrosscut5 = null;
56   MethodCut exampleCrosscut6 = null;
57
58   /**
59    * Set up fixture.
60    */

61   protected void setUp() {
62     try
63       {
64         exampleCrosscut1 = new FunctionalCrosscutExample();
65     
66         exampleCrosscut2 = new MethodCut() {
67               protected PointCutter pointCutter()
68               {
69                 return Within.method("someMethod");
70               }
71     
72               public void METHOD_ARGS(ANY thisObject, REST params) { }
73         };
74     
75         exampleCrosscut4 = new MethodCut() {
76             public void METHOD_ARGS(String JavaDoc receiver,REST params) { }
77     
78             protected PointCutter pointCutter()
79             {
80                 return Within.method("someOtherMethod") ;
81             }
82         };
83     
84         exampleCrosscut5 = new MethodCut() {
85             public void METHOD_ARGS(Vector receiver,int param) { }
86     
87             protected PointCutter pointCutter()
88             {
89                  return null;
90             }
91         };
92     
93         exampleCrosscut6 = new MethodCut() {
94             public void METHOD_ARGS(Vector receiver,int param, REST theRestArgs) { }
95     
96             protected PointCutter pointCutter()
97             {
98                  return null;
99             }
100         };
101     
102         ProseSystem.startup();
103         }
104         catch ( Throwable JavaDoc e )
105         {
106             e.printStackTrace();
107             Assert.fail("ProseSystem.startup() failed.");
108         }
109
110     try
111     {
112         exampleCrosscut1.insertionAction(true);
113         exampleCrosscut2.insertionAction(true);
114         exampleCrosscut4.insertionAction(true);
115         exampleCrosscut5.insertionAction(true);
116         exampleCrosscut6.insertionAction(true);
117     }
118     catch (Exception JavaDoc e)
119     {
120         // let exampleCrosscut 1 be initialized properly. We
121
// are going to test just a the 'doCreateRequestMethod',
122
// thus missing some initialization steps in create request.
123
}
124
125     lastEACall = null;
126   }
127
128   protected void tearDown()
129   {
130       try
131       { ProseSystem.teardown(); }
132       catch (Exception JavaDoc e)
133       {
134           Assert.fail("ProseSystem.teardown() failed"); }
135       }
136
137   public void testAdviceMethod()
138   {
139       Method JavaDoc meth1 = ((MethodCutSignaturePattern)(exampleCrosscut1.adviceSignature)).methodObj;
140       assertNotNull(meth1);
141       assertEquals(meth1.getName(),"METHOD_ARGS");
142       Method JavaDoc meth2 = ((MethodCutSignaturePattern)(exampleCrosscut2.adviceSignature)).methodObj;
143       assertNotNull(meth2);
144
145       Exception JavaDoc thrownException = null;
146       try
147       {
148           exampleCrosscut3 = new MethodCut()
149             {
150             protected PointCutter pointCutter()
151             {
152                 return null;
153             }
154             };
155       }
156       catch (MissingInformationException e)
157       {
158           thrownException=e;
159       }
160
161       assertNotNull("thrown exception should be non-null",thrownException);
162     }
163
164   public void testPotentialCroscutClasses()
165   {
166       assertTrue("ANY matches at least 100 classes",exampleCrosscut1.potentialCrosscutClasses().length > 100);
167       assertTrue(exampleCrosscut4.potentialCrosscutClasses()[0]==String JavaDoc.class);
168   }
169
170   public void testDoCreateRequest() throws Exception JavaDoc
171   {
172       try
173       {
174           CrosscutRequest cr1 = exampleCrosscut1.doCreateRequest(Vector.class);
175           assertTrue("list of public method in vector in non-empty", cr1.size() > 0);
176     
177           CrosscutRequest cr5 = exampleCrosscut5.doCreateRequest(Vector.class);
178     
179           CrosscutRequest cr6 = exampleCrosscut6.doCreateRequest(Vector.class);
180     
181           assertTrue("more methods in cr6",cr6.size() > cr5.size());
182       }
183       catch(Exception JavaDoc e)
184       {
185           e.printStackTrace();
186           throw e;
187       }
188   }
189
190   public void exampleAdvice(ANY c, int a, REST params)
191   {
192       lastEACall = new Vector();
193       lastEACall.add(c.getObject());
194       lastEACall.add(new Integer JavaDoc(a));
195       lastEACall.add(params.getObject());
196   }
197
198
199   public void exampleLocalCall(int a, String JavaDoc b, Date c)
200   {
201   }
202
203
204   /** Test whether the actions are ok
205    *
206    */

207   public void _testDoCreateLocalAction() throws Exception JavaDoc
208   {
209       try
210       {
211           Method JavaDoc eaMethod = getClass().getMethod("exampleAdvice",new Class JavaDoc[]{ANY.class,Integer.TYPE,REST.class});
212           assertNotNull(eaMethod);
213           Object JavaDoc[] localParams = new Object JavaDoc[]{"RECEIVER",new Integer JavaDoc(5),"hahah", new Date()};
214     
215           //exampleCrosscut1.localActionImpl(this,
216
// eaMethod,
217
// "RECEIVER",
218
// localParams);
219

220           assertEquals(lastEACall.get(0),"RECEIVER");
221           assertEquals(lastEACall.get(1),new Integer JavaDoc(5));
222           assertEquals(((Object JavaDoc[])(lastEACall.get(2)))[0],"hahah");
223        }
224        catch (Exception JavaDoc e)
225        {
226           e.printStackTrace();
227           throw e;
228        }
229   }
230
231   /**
232    * Test suite. Die methode
233    *
234    * @return test instance
235    */

236   public static
237   Test suite()
238   {
239       return new TestSuite(FunctionalCrosscutTest.class);
240   }
241 }
242
243
244 //======================================================================
245
//
246
// $Log: FunctionalCrosscutTest.java,v $
247
// Revision 1.2 2004/05/12 17:26:51 anicoara
248
// Adapt Junit tests to 3.8.1 version and the new package structure
249
//
250
// Revision 1.1.1.1 2003/07/02 15:30:43 apopovic
251
// Imported from ETH Zurich
252
//
253
// Revision 1.1 2003/05/05 14:03:28 popovici
254
// renaming from runes to prose
255
//
256
// Revision 1.17 2003/04/27 13:08:55 popovici
257
// Specializers renamed to PointCutter
258
//
259
// Revision 1.16 2003/04/17 15:15:17 popovici
260
// Extension->Aspect renaming
261
//
262
// Revision 1.15 2003/04/17 13:54:33 popovici
263
// Refactorization of 'ExecutionS' into 'Within' and 'Executions'.
264
// Method names refer now to 'types'
265
//
266
// Revision 1.14 2003/04/17 12:49:43 popovici
267
// Refactoring of the crosscut package
268
// ExceptionCut renamed to ThrowCut
269
// McutSignature is now SignaturePattern
270
//
271
// Revision 1.13 2003/04/17 08:46:48 popovici
272
// Important functionality additions
273
// - Cflow specializers
274
// - Restructuring of the MethodCut, SetCut, ThrowCut, and GetCut (they are much smaller)
275
// - Transactional capabilities
276
// - Total refactoring of Specializer evaluation, which permits fine-grained distinction
277
// between static and dynamic specializers.
278
// - Functionality pulled up in abstract classes
279
// - Uniformization of advice methods patterns and names
280
//
281
// Revision 1.12 2003/03/05 15:26:44 popovici
282
// Bug fixes after the extraction of 'AdviceMethod' and 'AdviceExcecution' as top level classes:
283
// - a new Abstract class is superclassing 'UserDefinedAdvice' and 'DefaultAdvice'
284
//
285
// Revision 1.11 2003/03/04 18:36:40 popovici
286
// Organization of imprts
287
//
288
// Revision 1.10 2003/03/04 11:26:00 popovici
289
// Important refactorization step (march):
290
// - removal of 'JoinPointEvents'; JoinPoints now have the same function as events
291
// - reimplementation of the JVMAIDebuggerAspectInterface (better performance, coding conventions, removal of ProseVM
292
// structures
293
//
294
// Revision 1.9 2002/11/26 17:15:36 pschoch
295
// RootComponent now added (replaces RootComponent now added (replaces old ProseSystem)
296
// ProseSystem now owns and starts the Aspect interface.
297
// ProseSystem now containes a 'test' AspectManager
298
// AspectManager now owns the JoinPointManager.
299
// ExtensionManger can be 'connected' to the JVM, or disconnected. The
300
// JoinPointManager of a connected Ext.Mgr enables joinpoints; the
301
// JoinPointManger of a disconnected Ext.Mgr never enables join-points
302
// Documentation updated accordingly.
303
//
304
// Revision 1.8 2002/06/06 18:53:49 popovici
305
// 1. Bug fix: methodAdvice is now public; the constructor works for all subclasses.
306
// 2. Feature change/bug fix: ADVICE_NAME is now a protected method
307
//
308
// Revision 1.7 2002/06/06 14:39:49 popovici
309
// Renamings: FunctionalCrosscut->MethodCut
310
// AllFields->SetCut
311
// SetCu.fieldModiticationAdvice -> SetCut.setAdvice
312
//
313
// Revision 1.6 2002/06/03 13:01:16 popovici
314
// renaming of the inner classes & objects, elimination of the local action
315
//
316
// Revision 1.5 2002/06/03 12:15:13 popovici
317
// VisibleCrosscutClass eliminated; test suites adapted for the fact that crosscutsjunit/ch/ethz/inf/runes/crosscut/FunctionalCrosscutTest.java
318
// now miss information upon creation (not upon insertion)
319
//
320
// Revision 1.4 2002/03/06 13:48:50 popovici
321
// joinPointAction now in 4 flavours, depending on the join point type
322
//
323
// Revision 1.3 2002/02/21 13:03:06 popovici
324
// Updated to new performance-optimized design: Crosscuts receive joinpoints, no Event notification, etc
325
//
326
// Revision 1.2 2002/02/05 11:19:29 smarkwal
327
// modifications to test JVMAI-based implementation
328
//
329
// Revision 1.1.1.1 2001/11/29 18:13:31 popovici
330
// Sources from runes
331
//
332
// Revision 1.1.2.3 2001/11/21 11:56:38 popovici
333
//
334
// -The sun.tools.agent and ch.ethz.inf.util.JVMDIUtil functionality
335
// replaced with the iks.jvmdi package. References to this old
336
// functionality replaced throughout the code.
337
// -Partial reimplementation of the ch.ethz.inf.iks.runes classes,
338
// part of their functionality moved to the ch.ethz.prose.reflect
339
// abstract classes. New classes and functionality added to the
340
// ch.ethz.prose.reflect package, partially to reflect the
341
// more stable features taken from the iks.runes packages, partially
342
// to reflect the structure of the VM (constant pool, etc). Functionality in
343
// ch.ethz.prose.crosscut and the junit classes adapted to use the
344
// new form of the ch.ethz.prose.reflect package
345
//
346
// Revision 1.1.2.2 2001/01/18 14:28:55 popovici
347
// Test 'doCreateLocalAction' handles now exceptions verbosely.
348
//
349
// Revision 1.1.2.1 2000/10/23 18:50:30 popovici
350
// Initial Revision
351
//
352
Popular Tags