KickJava   Java API By Example, From Geeks To Geeks.

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


1 // $Id: MethodSTest.java,v 1.2 2004/05/12 17:26:52 anicoara Exp $
2
// =====================================================================
3
//
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.lang.reflect.Modifier JavaDoc;
12
13 import junit.framework.*;
14 import ch.ethz.jvmai.MethodEntryJoinPoint;
15 import ch.ethz.prose.ProseSystem;
16 import ch.ethz.prose.engine.JoinPointManager;
17 import ch.ethz.prose.engine.MethodEntryRequest;
18
19 /**
20  * JUnit testcase for class MethodS.
21  *
22  * @version $Revision: 1.2 $
23  * @author Andrei Popovici
24  */

25 public
26 class MethodSTest extends TestCase {
27
28   ////
29
//// fixture
30
////
31
// some example methods
32
static void fooBar(){}
33   public void niceFooBar(){}
34   protected void badFooBar(){}
35   public synchronized void aSimpleMethodBody(){}
36   synchronized final void aSimpleBody(){}
37   void aSeccondBody(){}
38
39
40   // the requests for the funny methods
41
MethodEntryRequest fooBarRequest;
42   MethodEntryRequest niceFooBarRequest;
43   MethodEntryRequest badFooBarRequest;
44   MethodEntryRequest aSimpleMethodBodyRequest;
45   MethodEntryRequest aSimpleBodyRequest;
46   MethodEntryRequest aSeccondBodyRequest;
47
48   // and some MethodS selectors
49

50
51   /**
52    * Construct test with given name.
53    * @param name test name
54    */

55   public MethodSTest(String JavaDoc name)
56   {
57     super(name);
58   }
59
60   /**
61    * Set up fixture.
62    */

63   protected
64   void setUp() throws Exception JavaDoc
65   {
66     ProseSystem.startup();
67
68     JoinPointManager jpm = ProseSystem.getAspectManager().getJoinPointManager();
69
70     Method JavaDoc fooBarMethod = getClass().getDeclaredMethod("fooBar" ,new Class JavaDoc[]{});
71     Method JavaDoc niceFooBarMethod = getClass().getDeclaredMethod("niceFooBar" ,new Class JavaDoc[]{});
72     Method JavaDoc badFooBarMethod = getClass().getDeclaredMethod("badFooBar" ,new Class JavaDoc[]{});
73     Method JavaDoc aSimpleMethodBodyMethod = getClass().getDeclaredMethod("aSimpleMethodBody",new Class JavaDoc[]{});
74     Method JavaDoc aSimpleBodyMethod = getClass().getDeclaredMethod("aSimpleBody" ,new Class JavaDoc[]{});
75     Method JavaDoc aSeccondBodyMethod = getClass().getDeclaredMethod("aSeccondBody" ,new Class JavaDoc[]{});
76
77     fooBarRequest = (MethodEntryRequest)jpm.createJoinPointRequest(MethodEntryJoinPoint.KIND,fooBarMethod );
78     niceFooBarRequest = (MethodEntryRequest)jpm.createJoinPointRequest(MethodEntryJoinPoint.KIND,niceFooBarMethod );
79     badFooBarRequest = (MethodEntryRequest)jpm.createJoinPointRequest(MethodEntryJoinPoint.KIND,badFooBarMethod );
80     aSimpleMethodBodyRequest = (MethodEntryRequest)jpm.createJoinPointRequest(MethodEntryJoinPoint.KIND,aSimpleMethodBodyMethod);
81     aSimpleBodyRequest = (MethodEntryRequest)jpm.createJoinPointRequest(MethodEntryJoinPoint.KIND,aSimpleBodyMethod );
82     aSeccondBodyRequest = (MethodEntryRequest)jpm.createJoinPointRequest(MethodEntryJoinPoint.KIND,aSeccondBodyMethod );
83   }
84
85   protected
86   void tearDown()
87   {
88     try
89       { ProseSystem.teardown(); }
90     catch (Exception JavaDoc e)
91       { Assert.fail("ProseSystem.teardown() failed"); }
92   }
93
94
95   public void testMethodsNamed()
96   {
97     PointCutter simpleMethods = (Within.method("aSimple.*"));
98     assertTrue(simpleMethods.isSpecialRequest(aSimpleBodyRequest));
99     assertTrue(!simpleMethods.isSpecialRequest(fooBarRequest));
100     PointCutter bodyMethods = (Within.method(".*Body.*"));
101     assertTrue(bodyMethods.isSpecialRequest(aSimpleMethodBodyRequest));
102     assertTrue(!bodyMethods.isSpecialRequest(fooBarRequest));
103     PointFilter simpleBodySpec = (simpleMethods).AND(bodyMethods);
104     assertTrue(simpleBodySpec.isSpecialRequest(aSimpleBodyRequest));
105     assertTrue(!simpleBodySpec.isSpecialRequest(aSeccondBodyRequest));
106     assertTrue(simpleBodySpec.isSpecialRequest(aSimpleMethodBodyRequest));
107   }
108
109   public void testMethodDefined()
110   {
111     PointCutter synchMethos = (Within.method(Modifier.SYNCHRONIZED));
112     assertTrue("a simple Body is synchronized", synchMethos.isSpecialRequest(aSimpleBodyRequest));
113     assertTrue("a seccond body is not synchronized",!synchMethos.isSpecialRequest(aSeccondBodyRequest));
114
115     PointFilter protOrPubMethods =
116       (Within.method(Modifier.PROTECTED)) .OR
117       (Within.method(Modifier.PUBLIC));
118     assertTrue("niceFooBar is pro or pub", protOrPubMethods.isSpecialRequest(niceFooBarRequest));
119     assertTrue("niceFooBar is pro or pub", protOrPubMethods.isSpecialRequest(badFooBarRequest));
120     assertTrue("niceFooBar is pro or pub", protOrPubMethods.isSpecialRequest(aSimpleMethodBodyRequest));
121   }
122
123   public void testMethodBefore()
124   {
125     PointCutter beforeM = Executions.before();
126     assertTrue("all requests are ok",beforeM.isSpecialRequest(aSeccondBodyRequest));
127   }
128
129 /**
130  * Test suite.
131  * @return test instance
132  */

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