KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ch > ethz > prose > filter > DeclarationSTest


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

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

26 public
27 class DeclarationSTest extends TestCase {
28
29   ////
30
//// fixture
31
////
32
// some example methods
33
static class FooBar
34     {static void fooBar(){}}
35     static public class NiceFooBar
36     { public void niceFooBar(){}}
37     static class BadFooBar
38     {void badFooBar(){}}
39     static public class ASimpleMethodBody
40     {public synchronized void aSimpleMethodBody(){}}
41     static final class ASimpleBody
42     { synchronized final void aSimpleBody(){}}
43     static class ASeccondBody extends Vector JavaDoc
44     { void aSeccondBody(){} }
45
46
47   // the requests for the funny methods
48
MethodEntryRequest fooBarRequest;
49   MethodEntryRequest niceFooBarRequest;
50   MethodEntryRequest badFooBarRequest;
51   MethodEntryRequest aSimpleMethodBodyRequest;
52   MethodEntryRequest aSimpleBodyRequest;
53   MethodEntryRequest aSeccondBodyRequest;
54
55   // and some Within selectors
56

57
58   /**
59    * Construct test with given name.
60    * @param name test name
61    */

62   public DeclarationSTest(String JavaDoc name)
63   {
64     super(name);
65   }
66
67   /**
68    * Set up fixture.
69    */

70   protected
71   void setUp() throws Exception JavaDoc
72   {
73     ProseSystem.startup();
74
75     JoinPointManager jpm= ProseSystem.getAspectManager().getJoinPointManager();
76
77     Method JavaDoc fooBarMethod = FooBar.class.getDeclaredMethod("fooBar",new Class JavaDoc[]{});
78     Method JavaDoc niceFooBarMethod = NiceFooBar.class.getDeclaredMethod("niceFooBar",new Class JavaDoc[]{});
79     Method JavaDoc badFooBarMethod = BadFooBar.class.getDeclaredMethod("badFooBar",new Class JavaDoc[]{});
80     Method JavaDoc aSimpleMethodBodyMethod = ASimpleMethodBody.class.getDeclaredMethod("aSimpleMethodBody",new Class JavaDoc[]{});
81     Method JavaDoc aSimpleBodyMethod = ASimpleBody.class.getDeclaredMethod("aSimpleBody",new Class JavaDoc[]{});
82     Method JavaDoc aSeccondBodyMethod = ASeccondBody.class.getDeclaredMethod("aSeccondBody",new Class JavaDoc[]{});
83
84     fooBarRequest = (MethodEntryRequest)jpm.createJoinPointRequest(MethodEntryJoinPoint.KIND,fooBarMethod );
85     niceFooBarRequest = (MethodEntryRequest)jpm.createJoinPointRequest(MethodEntryJoinPoint.KIND,niceFooBarMethod );
86     badFooBarRequest = (MethodEntryRequest)jpm.createJoinPointRequest(MethodEntryJoinPoint.KIND,badFooBarMethod );
87     aSimpleMethodBodyRequest = (MethodEntryRequest)jpm.createJoinPointRequest(MethodEntryJoinPoint.KIND,aSimpleMethodBodyMethod);
88     aSimpleBodyRequest = (MethodEntryRequest)jpm.createJoinPointRequest(MethodEntryJoinPoint.KIND,aSimpleBodyMethod );
89     aSeccondBodyRequest = (MethodEntryRequest)jpm.createJoinPointRequest(MethodEntryJoinPoint.KIND,aSeccondBodyMethod );
90
91   }
92
93
94   protected
95    void tearDown()
96     {
97       try
98         { ProseSystem.teardown(); }
99       catch (Exception JavaDoc e)
100     { Assert.fail("ProseSystem.teardown() failed"); }
101     }
102
103
104   public void testExecutionSNamed()
105   {
106         PointCutter simpleClasses = (Within.type(".*ASimple.*"));
107         assertTrue("1",simpleClasses.isSpecialRequest(aSimpleBodyRequest));
108         assertTrue("2",!simpleClasses.isSpecialRequest(fooBarRequest));
109         PointCutter bodyClasses = (Within.type(".*Body.*"));
110         assertTrue("3",bodyClasses.isSpecialRequest(aSimpleMethodBodyRequest));
111         assertTrue("4",!bodyClasses.isSpecialRequest(fooBarRequest));
112         PointCutter simpleBodySpec = (simpleClasses).AND(bodyClasses);
113         assertTrue("5",simpleBodySpec.isSpecialRequest(aSimpleBodyRequest));
114         assertTrue("6",!simpleBodySpec.isSpecialRequest(aSeccondBodyRequest));
115         assertTrue("7",simpleBodySpec.isSpecialRequest(aSimpleMethodBodyRequest));
116   }
117
118   public void testExecutionSUSER_AND_SYSTEM()
119   {
120         assertTrue(Within.userCode().isSpecialRequest(aSimpleBodyRequest));
121   }
122
123   public void testExecutionSExtending()
124   {
125         PointCutter collectionClasses = Within.subType(Collection JavaDoc.class);
126         assertTrue(collectionClasses.isSpecialRequest(aSeccondBodyRequest));
127         assertTrue(!collectionClasses.isSpecialRequest(aSimpleBodyRequest));
128   }
129
130   public void testExecutionSameType() throws Throwable JavaDoc
131   {
132         PointCutter myCollectionClasses = Within.type(ASeccondBody.class);
133   }
134
135   public void testExecutionSinpackage()
136   {
137         PointCutter inthisPackageClasses = Within.packageTypes("ch.ethz.prose.*");
138         assertTrue(inthisPackageClasses.isSpecialRequest(aSeccondBodyRequest));
139         PointCutter inJavaLangClasses = Within.packageTypes("java.lang.*");
140         assertTrue(!inJavaLangClasses.isSpecialRequest(aSeccondBodyRequest));
141   }
142
143 /**
144  * Test suite.
145  * @return test instance
146  */

147   public static
148   Test suite()
149   {
150     return new TestSuite(DeclarationSTest.class);
151   }
152
153 }
154
155
156 //======================================================================
157
//
158
// $Log: DeclarationSTest.java,v $
159
// Revision 1.2 2004/05/12 17:26:52 anicoara
160
// Adapt Junit tests to 3.8.1 version and the new package structure
161
//
162
// Revision 1.1.1.1 2003/07/02 15:30:43 apopovic
163
// Imported from ETH Zurich
164
//
165
// Revision 1.1 2003/05/05 14:02:59 popovici
166
// renaming from runes to prose
167
//
168
// Revision 1.15 2003/04/27 13:09:00 popovici
169
// Specializers renamed to PointCutter
170
//
171
// Revision 1.14 2003/04/26 18:51:42 popovici
172
// 1 Bug fix which lead to a refactoring step:
173
// 1. the bug: 'JoinPointRequests' used to write to a static list, which survived a startup/teardown;
174
// now this list belongs to the JoinPointManager;
175
// 2. the refactoring: the JoinPointManager now creates (and shares state) with join-points.
176
//
177
// Revision 1.13 2003/04/26 14:10:34 popovici
178
// Fixed testExecutionSameType test; the 'Within.type' had a wrong arg
179
//
180
// Revision 1.12 2003/04/25 15:41:57 popovici
181
// Added the 'equalsTo' type filter in within
182
//
183
// Revision 1.11 2003/04/17 15:14:59 popovici
184
// Extension->Aspect renaming
185
//
186
// Revision 1.10 2003/04/17 14:46:06 popovici
187
// ThiS renamed to This; additional method renamings
188
//
189
// Revision 1.9 2003/04/17 13:59:39 popovici
190
// This class and methods renamed
191
//
192
// Revision 1.8 2003/04/17 13:54:32 popovici
193
// Refactorization of 'ExecutionS' into 'Within' and 'Executions'.
194
// Method names refer now to 'types'
195
//
196
// Revision 1.7 2003/04/17 12:49:30 popovici
197
// Refactoring of the crosscut package
198
// ExceptionCut renamed to ThrowCut
199
// McutSignature is now SignaturePattern
200
//
201
// Revision 1.6 2003/04/17 08:46:50 popovici
202
// Important functionality additions
203
// - Cflow specializers
204
// - Restructuring of the MethodCut, SetCut, ThrowCut, and GetCut (they are much smaller)
205
// - Transactional capabilities
206
// - Total refactoring of Specializer evaluation, which permits fine-grained distinction
207
// between static and dynamic specializers.
208
// - Functionality pulled up in abstract classes
209
// - Uniformization of advice methods patterns and names
210
//
211
// Revision 1.5 2003/03/04 18:36:11 popovici
212
// Organization of imprts
213
//
214
// Revision 1.4 2003/03/04 18:24:17 popovici
215
// Refactoring of the specializer. De-obfuscation
216
// by exposing the inner classes of the factory methods
217
// The specializer implementations now end in 'filter',
218
// whereas the old factory methods 'xxxS' remain
219
// pure bootstrap objects.
220
//
221
// Revision 1.3 2003/03/04 11:26:01 popovici
222
// Important refactorization step (march):
223
// - removal of 'JoinPointEvents'; JoinPoints now have the same function as events
224
// - reimplementation of the JVMAIDebuggerAspectInterface (better performance, coding conventions, removal of ProseVM
225
// structures
226
//
227
// Revision 1.2 2002/11/26 17:15:41 pschoch
228
// RootComponent now added (replaces RootComponent now added (replaces old ProseSystem)
229
// ProseSystem now owns and starts the Aspect interface.
230
// ProseSystem now containes a 'test' AspectManager
231
// AspectManager now owns the JoinPointManager.
232
// ExtensionManger can be 'connected' to the JVM, or disconnected. The
233
// JoinPointManager of a connected Ext.Mgr enables joinpoints; the
234
// JoinPointManger of a disconnected Ext.Mgr never enables join-points
235
// Documentation updated accordingly.
236
//
237
// Revision 1.1 2002/05/16 09:18:23 popovici
238
// ClasseS and CFlow replaced with Target, This; the crosscut spec package is refactorized. Now all
239
// crosscuts are grouped (abstract definitions + concrete definitions). Crosscuts explicitely are dynamic and static, and
240
// or/Not/And combinations can be created.
241
//
242
// Revision 1.2 2002/02/05 11:18:29 smarkwal
243
// modifications to test JVMAI-based implementation
244
//
245
// Revision 1.1.1.1 2001/11/29 18:13:31 popovici
246
// Sources from runes
247
//
248
// Revision 1.1.2.4 2001/11/21 11:56:39 popovici
249
//
250
// -The sun.tools.agent and ch.ethz.inf.util.JVMDIUtil functionality
251
// replaced with the iks.jvmdi package. References to this old
252
// functionality replaced throughout the code.
253
// -Partial reimplementation of the ch.ethz.inf.iks.runes classes,
254
// part of their functionality moved to the ch.ethz.prose.reflect
255
// abstract classes. New classes and functionality added to the
256
// ch.ethz.prose.reflect package, partially to reflect the
257
// more stable features taken from the iks.runes packages, partially
258
// to reflect the structure of the VM (constant pool, etc). Functionality in
259
// ch.ethz.prose.crosscut and the junit classes adapted to use the
260
// new form of the ch.ethz.prose.reflect package
261
//
262
// Revision 1.1.2.3 2001/02/22 16:50:22 popovici
263
// ProseSystem.setup replaced with startup; teardown introduced
264
//
265
// Revision 1.1.2.2 2000/11/28 16:58:04 groos
266
// Within does not work with Locatable anymore, but with ClassSpecific -> ExecutionSTest implements ClassSpecific instead of Locatable.
267
//
268
// Revision 1.1.2.1 2000/10/26 14:29:27 popovici
269
// Initial Revision.
270
//
271
//
272
Popular Tags