KickJava   Java API By Example, From Geeks To Geeks.

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


1 // $Id: AbstractCrosscutSpecializerTest.java,v 1.3 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.Proxy JavaDoc;
12 import java.util.List JavaDoc;
13
14 import junit.framework.*;
15 import ch.ethz.jvmai.CodeJoinPoint;
16 import ch.ethz.jvmai.JoinPoint;
17 import ch.ethz.prose.engine.JoinPointRequest;
18
19 /**
20  * JUnit testcase for class PointCutter.
21  *
22  * @version $Revision: 1.3 $
23  * @author Andrei Popovici
24  */

25 public
26 class AbstractCrosscutSpecializerTest extends TestCase {
27
28     // fixture
29
static class TestRequest extends JoinPointRequest
30     {
31         long mySignature;
32         public String JavaDoc getKind()
33         {
34             return "";
35         }
36     
37         public int getMask()
38         {
39           return 0;
40         }
41
42         public TestRequest(long signature)
43         {
44             super(null);
45             mySignature = signature;
46         }
47         
48         protected void setWatch(Object JavaDoc listeners) { }
49         protected void clearWatch() { }
50         public boolean equals(Object JavaDoc other)
51          { return ((other instanceof TestRequest) && (((TestRequest)other).mySignature==mySignature)); }
52         public int hashCode() { return (int)mySignature; }
53     }
54
55     interface TestEvent extends JoinPoint
56     {
57         public long myValue();
58     }
59
60     static class TestEventHandler implements java.lang.reflect.InvocationHandler JavaDoc
61     {
62         protected long myValue;
63         public Object JavaDoc invoke(Object JavaDoc proxy,Method JavaDoc m, Object JavaDoc[] args) throws Throwable JavaDoc
64         {
65             if(m.getName().equals("myValue"))
66             return new Long JavaDoc(myValue);
67             else
68             return null;
69         }
70     
71         static TestEventHandler create(long val)
72         {
73             TestEventHandler x = new TestEventHandler();
74             x.myValue = val;
75             return x;
76         }
77     }
78
79     static class SpecializerSmaller extends PointCutter {
80
81         long limit;
82     
83         SpecializerSmaller(long theLimit)
84         {
85             limit = theLimit;
86         }
87     
88         protected boolean doIsSpecialRequest(JoinPointRequest req)
89         {
90             if (req instanceof TestRequest)
91             {
92                 return ((TestRequest)req).mySignature < limit;
93             }
94             else
95             return true;
96         }
97     
98     
99         protected boolean doIsSpecialEvent(CodeJoinPoint ev)
100         {
101             if (ev instanceof TestEvent)
102             {
103                 return ((TestEvent)ev).myValue() < limit;
104             }
105             else
106             return true;
107         }
108     }
109
110     TestEvent e1000;
111     TestEvent e2000;
112     TestEvent e3000;
113     TestRequest r1000;
114     TestRequest r2000;
115     TestRequest r3000;
116     SpecializerSmaller spec1500; ;
117     SpecializerSmaller spec500;
118
119   /**
120    * Construct test with given name.
121    * @param name test name
122    */

123   public AbstractCrosscutSpecializerTest(String JavaDoc name)
124   {
125     super(name);
126   }
127
128   /**
129    * Set up fixture.
130    */

131   protected
132   void setUp()
133   {
134       e1000=(TestEvent)Proxy.newProxyInstance(this.getClass().getClassLoader(),new Class JavaDoc[] { TestEvent.class},TestEventHandler.create(1000));
135       e2000=(TestEvent)Proxy.newProxyInstance(TestEvent.class.getClassLoader(),new Class JavaDoc[] { TestEvent.class},TestEventHandler.create(2000));
136       e3000=(TestEvent)Proxy.newProxyInstance(TestEvent.class.getClassLoader(),new Class JavaDoc[] { TestEvent.class},TestEventHandler.create(3000));
137       r1000= new TestRequest(1000);
138       r2000= new TestRequest(2000);
139       r3000= new TestRequest(3000);
140       spec1500= new SpecializerSmaller(1500);
141       spec500= new SpecializerSmaller(500);
142   }
143
144     public void testAnd()
145     {
146         PointFilter andspec= spec1500.AND(spec500);
147         assertTrue(!andspec.isSpecialRequest(r1000));
148         assertTrue(!andspec.isSpecialRequest(r2000));
149         assertTrue(!andspec.isSpecialRequest(r3000));
150         assertTrue(!andspec.isSpecialEvent(e1000));
151         assertTrue(!andspec.isSpecialEvent(e2000));
152         assertTrue(!andspec.isSpecialEvent(e3000));
153     }
154
155     public void testOr()
156     {
157         PointFilter orspec = spec1500.OR(spec500);
158         assertTrue(orspec.isSpecialRequest(r1000));
159         assertTrue(!orspec.isSpecialRequest(r2000));
160         assertTrue(!orspec.isSpecialRequest(r3000));
161         assertTrue(orspec.isSpecialEvent(e1000));
162         assertTrue(!orspec.isSpecialEvent(e2000));
163         assertTrue(!orspec.isSpecialEvent(e3000));
164     }
165
166     public void testComposition()
167     {
168         PointCutter someSpec = spec1500.OR(spec500.AND(spec1500));
169         List JavaDoc members = someSpec.memberPointFilters();
170         assertTrue("Two members", members.size() == 2);
171     }
172
173   /**
174    * Test suite.
175    * @return test instance
176    */

177   public static
178   Test suite()
179   {
180         return new TestSuite(AbstractCrosscutSpecializerTest.class);
181   }
182 }
183
184
185 //======================================================================
186
//
187
// $Log: AbstractCrosscutSpecializerTest.java,v $
188
// Revision 1.3 2004/05/12 17:26:52 anicoara
189
// Adapt Junit tests to 3.8.1 version and the new package structure
190
//
191
// Revision 1.2 2003/07/17 13:11:10 apopovic
192
// refactorization: from PointFilter.memberSpecializers to PointFilter.memberPointFilters;
193
// improved documentation (removed references to specializers)
194
//
195
// Revision 1.1.1.1 2003/07/02 15:30:43 apopovic
196
// Imported from ETH Zurich
197
//
198
// Revision 1.2 2003/05/20 16:04:56 popovici
199
//
200
// New QueryManager replaces functionality in AspectManager (better Soc)
201
// New 'Surrogate' classes for usage in the QueryManager
202
// The 'RemoteAspectManager' and tools modified to use the Surrogates and the QueryManager
203
//
204
// Revision 1.1 2003/05/05 14:03:00 popovici
205
// renaming from runes to prose
206
//
207
// Revision 1.6 2003/04/27 13:09:00 popovici
208
// Specializers renamed to PointCutter
209
//
210
// Revision 1.5 2003/04/17 12:49:29 popovici
211
// Refactoring of the crosscut package
212
// ExceptionCut renamed to ThrowCut
213
// McutSignature is now SignaturePattern
214
//
215
// Revision 1.4 2003/04/17 08:46:49 popovici
216
// Important functionality additions
217
// - Cflow specializers
218
// - Restructuring of the MethodCut, SetCut, ThrowCut, and GetCut (they are much smaller)
219
// - Transactional capabilities
220
// - Total refactoring of Specializer evaluation, which permits fine-grained distinction
221
// between static and dynamic specializers.
222
// - Functionality pulled up in abstract classes
223
// - Uniformization of advice methods patterns and names
224
//
225
// Revision 1.3 2003/03/04 18:36:12 popovici
226
// Organization of imprts
227
//
228
// Revision 1.2 2003/03/04 11:26:01 popovici
229
// Important refactorization step (march):
230
// - removal of 'JoinPointEvents'; JoinPoints now have the same function as events
231
// - reimplementation of the JVMAIDebuggerAspectInterface (better performance, coding conventions, removal of ProseVM
232
// structures
233
//
234
// Revision 1.1 2002/05/07 10:47:01 popovici
235
// Reorganization of the Specializer package. All specializer related classes
236
// moved to ch.ethz.inf.crossucut.spec; Classes ORSpecializer, ANDspecializer and NOTspecializer is
237
// introduced, the static analysis of filtering simplified, because now specializers
238
// contain a field 'filterType' which is propagated to the root of composite specializers. junit packages updated accordingly
239
//
240
// Revision 1.3 2002/02/21 13:03:05 popovici
241
// Updated to new performance-optimized design: Crosscuts receive joinpoints, no Event notification, etc
242
//
243
// Revision 1.2 2002/02/05 11:19:56 smarkwal
244
// modifications to test JVMAI-based implementation
245
//
246
// Revision 1.1.1.1 2001/11/29 18:13:30 popovici
247
// Sources from runes
248
//
249
// Revision 1.1.2.1 2000/10/23 18:49:38 popovici
250
// Renamed from 'CrosscutSpecializerTest' to 'AbstractCrosscutSpecializerTest'
251
//
252
// Revision 1.1 2000/10/16 11:41:43 popovici
253
// Initial Revision
254
//
255
Popular Tags