001: // $Id: FunctionalCrosscutTest.java,v 1.2 2004/05/12 17:26:51 anicoara Exp $
002: // =====================================================================
003: //
004: // (history at end)
005: //
006:
007: package ch.ethz.prose.crosscut;
008:
009: // used packages
010: import java.lang.reflect.Method;
011: import java.util.*;
012:
013: import junit.framework.*;
014: import ch.ethz.prose.ProseSystem;
015: import ch.ethz.prose.filter.PointCutter;
016: import ch.ethz.prose.filter.Within;
017:
018: /**
019: * JUnit testcase for class FunctionalCrosscut.
020: *
021: * @version $Revision: 1.2 $
022: * @author Andrei Popovici
023: */
024: public class FunctionalCrosscutTest extends TestCase {
025:
026: class FunctionalCrosscutExample extends MethodCut {
027: void METHOD_ARGS(ANY this Object, REST params) {
028: System.err.println(">>>" + this Object.getObject() + "/"
029: + params.getObject());
030: }
031:
032: protected PointCutter pointCutter() {
033: return null;
034: }
035: }
036:
037: /**
038: * Construct test with given name.
039: * @param name test name
040: */
041: public FunctionalCrosscutTest(String name) {
042: super (name);
043: }
044:
045: List lastEACall;
046: MethodCut exampleCrosscut1 = null;
047: MethodCut exampleCrosscut2 = null;
048: MethodCut exampleCrosscut3 = null;
049: MethodCut exampleCrosscut4 = null;
050: MethodCut exampleCrosscut5 = null;
051: MethodCut exampleCrosscut6 = null;
052:
053: /**
054: * Set up fixture.
055: */
056: protected void setUp() {
057: try {
058: exampleCrosscut1 = new FunctionalCrosscutExample();
059:
060: exampleCrosscut2 = new MethodCut() {
061: protected PointCutter pointCutter() {
062: return Within.method("someMethod");
063: }
064:
065: public void METHOD_ARGS(ANY this Object, REST params) {
066: }
067: };
068:
069: exampleCrosscut4 = new MethodCut() {
070: public void METHOD_ARGS(String receiver, REST params) {
071: }
072:
073: protected PointCutter pointCutter() {
074: return Within.method("someOtherMethod");
075: }
076: };
077:
078: exampleCrosscut5 = new MethodCut() {
079: public void METHOD_ARGS(Vector receiver, int param) {
080: }
081:
082: protected PointCutter pointCutter() {
083: return null;
084: }
085: };
086:
087: exampleCrosscut6 = new MethodCut() {
088: public void METHOD_ARGS(Vector receiver, int param,
089: REST theRestArgs) {
090: }
091:
092: protected PointCutter pointCutter() {
093: return null;
094: }
095: };
096:
097: ProseSystem.startup();
098: } catch (Throwable e) {
099: e.printStackTrace();
100: Assert.fail("ProseSystem.startup() failed.");
101: }
102:
103: try {
104: exampleCrosscut1.insertionAction(true);
105: exampleCrosscut2.insertionAction(true);
106: exampleCrosscut4.insertionAction(true);
107: exampleCrosscut5.insertionAction(true);
108: exampleCrosscut6.insertionAction(true);
109: } catch (Exception e) {
110: // let exampleCrosscut 1 be initialized properly. We
111: // are going to test just a the 'doCreateRequestMethod',
112: // thus missing some initialization steps in create request.
113: }
114:
115: lastEACall = null;
116: }
117:
118: protected void tearDown() {
119: try {
120: ProseSystem.teardown();
121: } catch (Exception e) {
122: Assert.fail("ProseSystem.teardown() failed");
123: }
124: }
125:
126: public void testAdviceMethod() {
127: Method meth1 = ((MethodCutSignaturePattern) (exampleCrosscut1.adviceSignature)).methodObj;
128: assertNotNull(meth1);
129: assertEquals(meth1.getName(), "METHOD_ARGS");
130: Method meth2 = ((MethodCutSignaturePattern) (exampleCrosscut2.adviceSignature)).methodObj;
131: assertNotNull(meth2);
132:
133: Exception thrownException = null;
134: try {
135: exampleCrosscut3 = new MethodCut() {
136: protected PointCutter pointCutter() {
137: return null;
138: }
139: };
140: } catch (MissingInformationException e) {
141: thrownException = e;
142: }
143:
144: assertNotNull("thrown exception should be non-null",
145: thrownException);
146: }
147:
148: public void testPotentialCroscutClasses() {
149: assertTrue("ANY matches at least 100 classes", exampleCrosscut1
150: .potentialCrosscutClasses().length > 100);
151: assertTrue(exampleCrosscut4.potentialCrosscutClasses()[0] == String.class);
152: }
153:
154: public void testDoCreateRequest() throws Exception {
155: try {
156: CrosscutRequest cr1 = exampleCrosscut1
157: .doCreateRequest(Vector.class);
158: assertTrue("list of public method in vector in non-empty",
159: cr1.size() > 0);
160:
161: CrosscutRequest cr5 = exampleCrosscut5
162: .doCreateRequest(Vector.class);
163:
164: CrosscutRequest cr6 = exampleCrosscut6
165: .doCreateRequest(Vector.class);
166:
167: assertTrue("more methods in cr6", cr6.size() > cr5.size());
168: } catch (Exception e) {
169: e.printStackTrace();
170: throw e;
171: }
172: }
173:
174: public void exampleAdvice(ANY c, int a, REST params) {
175: lastEACall = new Vector();
176: lastEACall.add(c.getObject());
177: lastEACall.add(new Integer(a));
178: lastEACall.add(params.getObject());
179: }
180:
181: public void exampleLocalCall(int a, String b, Date c) {
182: }
183:
184: /**
185: * Test whether the actions are ok
186: */
187: public void _testDoCreateLocalAction() throws Exception {
188: try {
189: Method eaMethod = getClass()
190: .getMethod(
191: "exampleAdvice",
192: new Class[] { ANY.class, Integer.TYPE,
193: REST.class });
194: assertNotNull(eaMethod);
195: Object[] localParams = new Object[] { "RECEIVER",
196: new Integer(5), "hahah", new Date() };
197:
198: //exampleCrosscut1.localActionImpl(this,
199: // eaMethod,
200: // "RECEIVER",
201: // localParams);
202:
203: assertEquals(lastEACall.get(0), "RECEIVER");
204: assertEquals(lastEACall.get(1), new Integer(5));
205: assertEquals(((Object[]) (lastEACall.get(2)))[0], "hahah");
206: } catch (Exception e) {
207: e.printStackTrace();
208: throw e;
209: }
210: }
211:
212: /**
213: * Test suite. Die methode
214: *
215: * @return test instance
216: */
217: public static Test suite() {
218: return new TestSuite(FunctionalCrosscutTest.class);
219: }
220: }
221:
222: //======================================================================
223: //
224: // $Log: FunctionalCrosscutTest.java,v $
225: // Revision 1.2 2004/05/12 17:26:51 anicoara
226: // Adapt Junit tests to 3.8.1 version and the new package structure
227: //
228: // Revision 1.1.1.1 2003/07/02 15:30:43 apopovic
229: // Imported from ETH Zurich
230: //
231: // Revision 1.1 2003/05/05 14:03:28 popovici
232: // renaming from runes to prose
233: //
234: // Revision 1.17 2003/04/27 13:08:55 popovici
235: // Specializers renamed to PointCutter
236: //
237: // Revision 1.16 2003/04/17 15:15:17 popovici
238: // Extension->Aspect renaming
239: //
240: // Revision 1.15 2003/04/17 13:54:33 popovici
241: // Refactorization of 'ExecutionS' into 'Within' and 'Executions'.
242: // Method names refer now to 'types'
243: //
244: // Revision 1.14 2003/04/17 12:49:43 popovici
245: // Refactoring of the crosscut package
246: // ExceptionCut renamed to ThrowCut
247: // McutSignature is now SignaturePattern
248: //
249: // Revision 1.13 2003/04/17 08:46:48 popovici
250: // Important functionality additions
251: // - Cflow specializers
252: // - Restructuring of the MethodCut, SetCut, ThrowCut, and GetCut (they are much smaller)
253: // - Transactional capabilities
254: // - Total refactoring of Specializer evaluation, which permits fine-grained distinction
255: // between static and dynamic specializers.
256: // - Functionality pulled up in abstract classes
257: // - Uniformization of advice methods patterns and names
258: //
259: // Revision 1.12 2003/03/05 15:26:44 popovici
260: // Bug fixes after the extraction of 'AdviceMethod' and 'AdviceExcecution' as top level classes:
261: // - a new Abstract class is superclassing 'UserDefinedAdvice' and 'DefaultAdvice'
262: //
263: // Revision 1.11 2003/03/04 18:36:40 popovici
264: // Organization of imprts
265: //
266: // Revision 1.10 2003/03/04 11:26:00 popovici
267: // Important refactorization step (march):
268: // - removal of 'JoinPointEvents'; JoinPoints now have the same function as events
269: // - reimplementation of the JVMAIDebuggerAspectInterface (better performance, coding conventions, removal of ProseVM
270: // structures
271: //
272: // Revision 1.9 2002/11/26 17:15:36 pschoch
273: // RootComponent now added (replaces RootComponent now added (replaces old ProseSystem)
274: // ProseSystem now owns and starts the Aspect interface.
275: // ProseSystem now containes a 'test' AspectManager
276: // AspectManager now owns the JoinPointManager.
277: // ExtensionManger can be 'connected' to the JVM, or disconnected. The
278: // JoinPointManager of a connected Ext.Mgr enables joinpoints; the
279: // JoinPointManger of a disconnected Ext.Mgr never enables join-points
280: // Documentation updated accordingly.
281: //
282: // Revision 1.8 2002/06/06 18:53:49 popovici
283: // 1. Bug fix: methodAdvice is now public; the constructor works for all subclasses.
284: // 2. Feature change/bug fix: ADVICE_NAME is now a protected method
285: //
286: // Revision 1.7 2002/06/06 14:39:49 popovici
287: // Renamings: FunctionalCrosscut->MethodCut
288: // AllFields->SetCut
289: // SetCu.fieldModiticationAdvice -> SetCut.setAdvice
290: //
291: // Revision 1.6 2002/06/03 13:01:16 popovici
292: // renaming of the inner classes & objects, elimination of the local action
293: //
294: // Revision 1.5 2002/06/03 12:15:13 popovici
295: // VisibleCrosscutClass eliminated; test suites adapted for the fact that crosscutsjunit/ch/ethz/inf/runes/crosscut/FunctionalCrosscutTest.java
296: // now miss information upon creation (not upon insertion)
297: //
298: // Revision 1.4 2002/03/06 13:48:50 popovici
299: // joinPointAction now in 4 flavours, depending on the join point type
300: //
301: // Revision 1.3 2002/02/21 13:03:06 popovici
302: // Updated to new performance-optimized design: Crosscuts receive joinpoints, no Event notification, etc
303: //
304: // Revision 1.2 2002/02/05 11:19:29 smarkwal
305: // modifications to test JVMAI-based implementation
306: //
307: // Revision 1.1.1.1 2001/11/29 18:13:31 popovici
308: // Sources from runes
309: //
310: // Revision 1.1.2.3 2001/11/21 11:56:38 popovici
311: //
312: // -The sun.tools.agent and ch.ethz.inf.util.JVMDIUtil functionality
313: // replaced with the iks.jvmdi package. References to this old
314: // functionality replaced throughout the code.
315: // -Partial reimplementation of the ch.ethz.inf.iks.runes classes,
316: // part of their functionality moved to the ch.ethz.prose.reflect
317: // abstract classes. New classes and functionality added to the
318: // ch.ethz.prose.reflect package, partially to reflect the
319: // more stable features taken from the iks.runes packages, partially
320: // to reflect the structure of the VM (constant pool, etc). Functionality in
321: // ch.ethz.prose.crosscut and the junit classes adapted to use the
322: // new form of the ch.ethz.prose.reflect package
323: //
324: // Revision 1.1.2.2 2001/01/18 14:28:55 popovici
325: // Test 'doCreateLocalAction' handles now exceptions verbosely.
326: //
327: // Revision 1.1.2.1 2000/10/23 18:50:30 popovici
328: // Initial Revision
329: //
|