KickJava   Java API By Example, From Geeks To Geeks.

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


1 // $Id $
2
// =====================================================================
3
//
4
// (history at end)
5
//
6

7 package ch.ethz.prose;
8
9 // used packages
10
import java.lang.reflect.Field JavaDoc;
11
12 import junit.framework.*;
13 import ch.ethz.jvmai.FieldAccessJoinPoint;
14 import ch.ethz.jvmai.FieldModificationJoinPoint;
15 import ch.ethz.prose.crosscut.*;
16 import ch.ethz.prose.filter.PointCutter;
17
18
19 /**
20  * FieldNotificationTestWithOutput. This is almost the same as
21  * <code>FieldNotificationTest</code>, but this one produces output
22  * rather than doing some assertion tests to allow the user to see how
23  * the field access and modification mechanism actually works.
24  *
25  * @version $Revision: 1.2 $
26  * @author G�rard Roos
27  */

28 public class FieldNotificationTestWithOutput extends TestCase {
29
30   // fixture
31

32   static class TestClass {
33     int initial = 1;
34     int inConstr;
35     int undefined;
36
37     int[] array;
38
39     Object JavaDoc o = null;
40
41     public TestClass() {
42       inConstr = 2;
43     }
44
45   }
46
47   public static class TestExtension extends DefaultAspect {
48
49     public Crosscut c1 = new GetCut()
50       {
51     public void GET_ARGS()
52       {
53         FieldAccessJoinPoint theEv = (FieldAccessJoinPoint)thisJoinPoint();
54         Field JavaDoc f = theEv.getField();
55
56         Object JavaDoc owner = theEv.getTarget();
57
58         try
59           {
60         System.out.println("READ ACCESS");
61         System.out.println("class: " + owner.getClass().getName());
62         System.out.println("owner: " + owner);
63         System.out.println("fieldname: " + f.getName());
64         System.out.println("value: " + f.get(owner));
65         System.out.println();
66           }
67         catch ( Exception JavaDoc e )
68           {
69         e.printStackTrace();
70           }
71       }
72
73       protected PointCutter pointCutter()
74       { return null;}
75
76       };
77
78     public Crosscut c = new SetCut()
79       {
80     public void SET_ARGS()
81       {
82         try
83           {
84         FieldModificationJoinPoint fme = (FieldModificationJoinPoint)thisJoinPoint();
85
86         System.out.println("MODIFICATION ACCESS");
87         System.out.println("class: " + fme.getTarget().getClass().getName());
88         System.out.println("owner: " + fme.getTarget());
89         System.out.println("fieldname: " + fme.getField().getName());
90         System.out.println("old value: " + fme.getField().get(fme.getTarget()));
91         System.out.println("new value: " + fme.getNewValue());
92         System.out.println();
93           }
94         catch ( Exception JavaDoc e )
95           {
96         e.printStackTrace();
97           }
98       }
99
100       protected PointCutter pointCutter()
101       { return null;}
102
103
104     // restrict to TestClass
105
protected Class JavaDoc[] potentialCrosscutClasses() {
106       Class JavaDoc[] result = {TestClass.class};
107       return result;
108     }
109       };
110   };
111
112
113   TestClass test;
114
115
116   /**
117    * Construct test with given name.
118    * @param name test name
119    */

120     public FieldNotificationTestWithOutput(String JavaDoc name) {
121       super(name);
122     }
123
124
125   /**
126    * Set up fixture.
127    */

128   protected void setUp() {
129     try {
130       ProseSystem.startup();
131     }
132     catch ( Exception JavaDoc e ) {
133       Assert.fail("ProseSystem.startup() failed.");
134     }
135   }
136
137   /**
138    *
139    */

140   protected void tearDown() throws SystemTeardownException {
141     try {
142       ProseSystem.teardown();
143     }
144     catch ( Exception JavaDoc e ) {
145       Assert.fail("ProseSystem.teardown() failed.");
146     }
147   }
148
149
150   /**
151    *
152    */

153   public void testInstantiation() throws Exception JavaDoc {
154
155     int[] arr = {1,2,3,4,5};
156
157     System.out.println("\n\ncreate new instance...\n");
158     ProseSystem.getAspectManager().insert(new TestExtension());
159     test = new TestClass();
160
161     System.out.println("\naccess the fields...\n");
162     test.undefined = -5;
163     test.o = new Object JavaDoc();
164     test.array = arr;
165     arr[0] = 0;
166     test.array = arr;
167     test.array[1] = 9;
168     test.array[3] = 1;
169     test.array[4] = 10;
170   }
171
172
173
174   /**
175    * Test suite.
176    * @return test instance
177    */

178   public static
179   Test suite() {
180     return new TestSuite(FieldNotificationTestWithOutput.class);
181   }
182
183   }
184
185
186 //======================================================================
187
//
188
// $Log: FieldNotificationTestWithOutput.java,v $
189
// Revision 1.2 2004/05/12 17:26:51 anicoara
190
// Adapt Junit tests to 3.8.1 version and the new package structure
191
//
192
// Revision 1.1.1.1 2003/07/02 15:30:42 apopovic
193
// Imported from ETH Zurich
194
//
195
// Revision 1.1 2003/05/05 14:02:30 popovici
196
// renaming from runes to prose
197
//
198
// Revision 1.12 2003/04/27 13:08:40 popovici
199
// Specializers renamed to PointCutter
200
//
201
// Revision 1.11 2003/04/17 15:15:02 popovici
202
// Extension->Aspect renaming
203
//
204
// Revision 1.10 2003/04/17 12:49:39 popovici
205
// Refactoring of the crosscut package
206
// ExceptionCut renamed to ThrowCut
207
// McutSignature is now SignaturePattern
208
//
209
// Revision 1.9 2003/04/17 08:46:44 popovici
210
// Important functionality additions
211
// - Cflow specializers
212
// - Restructuring of the MethodCut, SetCut, ThrowCut, and GetCut (they are much smaller)
213
// - Transactional capabilities
214
// - Total refactoring of Specializer evaluation, which permits fine-grained distinction
215
// between static and dynamic specializers.
216
// - Functionality pulled up in abstract classes
217
// - Uniformization of advice methods patterns and names
218
//
219
// Revision 1.8 2003/03/04 18:36:09 popovici
220
// Organization of imprts
221
//
222
// Revision 1.7 2003/03/04 11:25:57 popovici
223
// Important refactorization step (march):
224
// - removal of 'JoinPointEvents'; JoinPoints now have the same function as events
225
// - reimplementation of the JVMAIDebuggerAspectInterface (better performance, coding conventions, removal of ProseVM
226
// structures
227
//
228
// Revision 1.6 2002/11/26 17:15:31 pschoch
229
// RootComponent now added (replaces RootComponent now added (replaces old ProseSystem)
230
// ProseSystem now owns and starts the Aspect interface.
231
// ProseSystem now containes a 'test' AspectManager
232
// AspectManager now owns the JoinPointManager.
233
// ExtensionManger can be 'connected' to the JVM, or disconnected. The
234
// JoinPointManager of a connected Ext.Mgr enables joinpoints; the
235
// JoinPointManger of a disconnected Ext.Mgr never enables join-points
236
// Documentation updated accordingly.
237
//
238
// Revision 1.5 2002/06/06 14:39:53 popovici
239
// Renamings: FunctionalCrosscut->MethodCut
240
// AllFields->SetCut
241
// SetCu.fieldModiticationAdvice -> SetCut.setAdvice
242
//
243
// Revision 1.4 2002/06/06 12:01:47 popovici
244
// fieldAccessAdvice removed from AllFields; tests and usage of AllFields's
245
// ability to intercept gets moved to 'GetCut'
246
// Minor bug fixes;
247
//
248
// Revision 1.3 2002/06/05 12:03:49 popovici
249
// thisJoinPoint() updated everywhere. The 'fieldModificationAdvice is now parameterless'; older implemnentations now
250
// use 'thisJoinPoint()'
251
//
252
// Revision 1.2 2002/02/05 11:20:43 smarkwal
253
// modifications to test JVMAI-based implementation
254
//
255
// Revision 1.1.1.1 2001/11/29 18:13:30 popovici
256
// Sources from runes
257
//
258
// Revision 1.1.2.2 2001/02/22 16:52:23 popovici
259
// ProseSystem.setup replaced with startup; teardown introduced
260
//
261
// Revision 1.1.2.1 2001/01/17 21:25:47 groos
262
// initial revision.
263
//
264
Popular Tags