KickJava   Java API By Example, From Geeks To Geeks.

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


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

7 package ch.ethz.prose;
8
9 // used packages
10
import java.util.List JavaDoc;
11 import java.util.Vector JavaDoc;
12
13 import junit.framework.*;
14 import ch.ethz.jvmai.JVMAspectInterface;
15 import ch.ethz.prose.engine.JoinPointManager;
16
17
18 /**
19  * JUnit testcase for class ProseSystem.
20  *
21  * @version $Revision: 1.2 $
22  * @author Andrei Popovici
23  */

24 public
25 class ExtensionSystemTest extends TestCase {
26
27   public static class ExampleExtensionSystem{
28
29     public static boolean appSetupVisited = false;
30
31     public static void startup() throws SystemStartupException { appSetupVisited=true;}
32     public static void teardown() throws SystemTeardownException {}
33   }
34
35   public static class ExampleExtensionManager implements AspectManager {
36
37     public ExampleExtensionManager(boolean ic, JVMAspectInterface ai) { }
38
39     public List JavaDoc withdrawnExtensions = new Vector JavaDoc();
40     public List JavaDoc insertedExtensions = new Vector JavaDoc();
41
42     public List JavaDoc getAllJoinpoints(){return null;}
43     public void insert(Aspect ext,Object JavaDoc tx){}
44     public void withdraw(Aspect ext,Object JavaDoc tx){}
45     public void commit(Object JavaDoc tx){}
46     public void abort(Object JavaDoc tx){}
47     public void insert(Aspect ext) { insertedExtensions.add(ext);}
48     public void withdraw(Aspect ext) { withdrawnExtensions.add(ext);}
49
50     public List JavaDoc getAllAspects() {return null;}
51     public JoinPointManager getJoinPointManager() {return null;}
52     public void teardown() { }
53     public void startup() { }
54     public List JavaDoc queryAspects(List JavaDoc aspectList, int selectFields, int groupBy) { return null; }
55     public List JavaDoc queryCrosscuts(List JavaDoc crosscutList, int selectFields, int groupBy) { return null; }
56     public List JavaDoc queryJoinpoints(List JavaDoc joinpointList, int selectFields, int groupBy) { return null; }
57
58   }
59
60   /**
61    * Construct test with given name.
62    * @param name test name
63    */

64   public ExtensionSystemTest(String JavaDoc name)
65   {
66     super(name);
67   }
68
69   /**
70    * Set up fixture.
71    */

72   protected
73   void setUp()
74   {
75     System.setProperty("ch.ethz.prose.EXManager",
76                "ch.ethz.prose.ExtensionSystemTest$ExampleExtensionManager");
77     System.setProperty("ch.ethz.prose.ESSystem.1",
78                "ch.ethz.prose.ExtensionSystemTest$ExampleExtensionSystem");
79   }
80
81   public void tearDown()
82   {
83     System.getProperties().remove("ch.ethz.prose.EXManager");
84     System.getProperties().remove("ch.ethz.prose.ESSystem.1");
85   }
86
87   /**
88    * Test suite.
89    * @return test instance
90    */

91   public static
92   Test suite()
93   {
94     return new TestSuite(ExtensionSystemTest.class);
95   }
96
97   // this test just calls the normal setup procedure
98
// with no set property values;
99
public void test1_SimpleSetup() throws Exception JavaDoc
100   {
101     System.getProperties().remove("ch.ethz.prose.EXManager");
102     System.getProperties().remove("ch.ethz.prose.ESSystem.1");
103
104     ProseSystem.startup();
105     assertNotNull(ProseSystem.getAspectManager());
106     assertNotNull(ProseSystem.getTestAspectManager());
107     ProseSystem.teardown();
108   }
109
110   // this tests tests if the setup works in the presence
111
// of correct set system properties
112
public void test2_CustomSetup() throws Exception JavaDoc
113   {
114       try
115       {
116           System.getProperties().remove("ch.ethz.prose.ESSystem.1");
117
118           ProseSystem.startup();
119           assertNotNull(ProseSystem.getAspectManager());
120           assertNotNull(ProseSystem.getTestAspectManager());
121           assertTrue("current extension Manager have the correct type",
122              ProseSystem.getAspectManager() instanceof ExampleExtensionManager);
123           assertTrue("test extension Manager have the correct type",
124              ProseSystem.getTestAspectManager() instanceof ExampleExtensionManager);
125           ProseSystem.teardown();
126       }
127       catch (RuntimeException JavaDoc e)
128       {
129           e.printStackTrace();
130           throw e;
131       }
132   }
133
134   // this tests if the setup works in the presence of an application-specific
135
// setup method.
136
public void test3_FullCustomSetup() throws Exception JavaDoc
137   {
138       try {
139         RootComponent.startup();
140         assertTrue(" the initialization procedure touched the flag",
141                ExampleExtensionSystem.appSetupVisited);
142         RootComponent.teardown();
143       }
144       catch (Exception JavaDoc e)
145       {
146         e.printStackTrace();
147       }
148   }
149
150     // test that the teardown action actually removes all
151
// extensions and leaves no dangling join-point in the
152
// virtual machine
153
public void test4_Teardown() throws Exception JavaDoc
154   {
155     try
156         {
157         System.getProperties().remove("ch.ethz.prose.EXManager");
158         System.getProperties().remove("ch.ethz.prose.ESSystem.1");
159
160         // start the extension
161
ProseSystem.startup();
162         assertNotNull(ProseSystem.getAspectManager());
163         assertNotNull(ProseSystem.getTestAspectManager());
164
165         // insert a few extensions
166
Aspect x1 = new DefaultAspect(){};
167         Aspect x2 = new DefaultAspect(){};
168
169
170         ProseSystem.getAspectManager().insert(x1);
171         ProseSystem.getAspectManager().insert(x2);
172
173         ProseSystem.getTestAspectManager().insert(x1);
174         ProseSystem.getTestAspectManager().insert(x2);
175
176         // teardown the system
177
AspectManager currentMgr = ProseSystem.getAspectManager();
178         AspectManager testMgr = ProseSystem.getTestAspectManager();
179         ProseSystem.teardown();
180
181         // assert that all extensions where withdrawn
182
assertTrue("empty extension list in currentMgr", currentMgr.getAllAspects().isEmpty());
183         assertTrue("empty extension list in testMgr", testMgr.getAllAspects().isEmpty());
184         }
185     catch (Exception JavaDoc e)
186     {
187         e.printStackTrace();
188         throw e;
189     }
190
191   }
192
193 }
194
195
196 //======================================================================
197
//
198
// $Log: ExtensionSystemTest.java,v $
199
// Revision 1.2 2004/05/12 17:26:50 anicoara
200
// Adapt Junit tests to 3.8.1 version and the new package structure
201
//
202
// Revision 1.1.1.1 2003/07/02 15:30:42 apopovic
203
// Imported from ETH Zurich
204
//
205
// Revision 1.2 2003/06/10 12:59:48 popovici
206
// startup and teardown idempotence used to produce a startup during the teardown;
207
// flag is now set *after* the teardown has successfully completed
208
//
209
// Revision 1.1 2003/05/05 14:02:30 popovici
210
// renaming from runes to prose
211
//
212
// Revision 1.10 2003/04/17 15:15:01 popovici
213
// Extension->Aspect renaming
214
//
215
// Revision 1.9 2003/04/17 12:49:38 popovici
216
// Refactoring of the crosscut package
217
// ExceptionCut renamed to ThrowCut
218
// McutSignature is now SignaturePattern
219
//
220
// Revision 1.8 2003/04/17 08:46:43 popovici
221
// Important functionality additions
222
// - Cflow specializers
223
// - Restructuring of the MethodCut, SetCut, ThrowCut, and GetCut (they are much smaller)
224
// - Transactional capabilities
225
// - Total refactoring of Specializer evaluation, which permits fine-grained distinction
226
// between static and dynamic specializers.
227
// - Functionality pulled up in abstract classes
228
// - Uniformization of advice methods patterns and names
229
//
230
// Revision 1.7 2003/03/04 18:36:09 popovici
231
// Organization of imprts
232
//
233
// Revision 1.6 2003/03/04 11:25:56 popovici
234
// Important refactorization step (march):
235
// - removal of 'JoinPointEvents'; JoinPoints now have the same function as events
236
// - reimplementation of the JVMAIDebuggerAspectInterface (better performance, coding conventions, removal of ProseVM
237
// structures
238
//
239
// Revision 1.5 2003/02/17 13:52:52 popovici
240
// Bug fix: the 'allJoinpoints() methods used to miss
241
//
242
// Revision 1.4 2003/01/17 14:44:00 pschoch
243
// Introduction of 'query' methods in the AspectManager and its
244
// subclasses. The result set is given back in form of surrogates; 4 new tests added to ExtensionManagerTest
245
// ExtensionSystemTest
246
//
247
// Revision 1.3 2002/11/26 17:15:29 pschoch
248
// RootComponent now added (replaces RootComponent now added (replaces old ProseSystem)
249
// ProseSystem now owns and starts the Aspect interface.
250
// ProseSystem now containes a 'test' AspectManager
251
// AspectManager now owns the JoinPointManager.
252
// ExtensionManger can be 'connected' to the JVM, or disconnected. The
253
// JoinPointManager of a connected Ext.Mgr enables joinpoints; the
254
// JoinPointManger of a disconnected Ext.Mgr never enables join-points
255
// Documentation updated accordingly.
256
//
257
// Revision 1.2 2002/02/05 11:20:11 smarkwal
258
// modifications to test JVMAI-based implementation
259
//
260
// Revision 1.1.1.1 2001/11/29 18:13:30 popovici
261
// Sources from runes
262
//
263
// Revision 1.1.2.6 2001/06/06 10:05:22 popovici
264
// Methods 'registerListener' and 'unregisterListener' for classLoadListeners
265
// added.
266
//
267
// Revision 1.1.2.5 2001/03/22 17:29:26 popovici
268
// ExampleExtensionSystem changed to contain the 'suspend/resumeNotificationListener' methods
269
//
270
// Revision 1.1.2.4 2001/02/22 16:54:49 popovici
271
// ProseSystem.setup replaced with startup; teardown introduced
272
// - bug fixed in properties defintion
273
// - test 'testTeardown' introduced
274
//
275
// Revision 1.1.2.3 2001/02/07 12:04:33 popovici
276
// ProseSystem test adapted to the new 'startup/teardown' framework.
277
//
278
// Revision 1.1.2.2 2000/11/21 14:40:31 groos
279
// adapted to the modifications of JoinPointManager:
280
// new abstract methods createFieldAccessRequest(Field f) and createFieldModificationRequest(Field f) must be declared, too.
281
//
282
// Revision 1.1.2.1 2000/10/24 17:59:53 popovici
283
// Initial Revision
284
//
285
Popular Tags