001: /*
002: * Copyright (c) 2001-2007, Jean Tessier
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions
007: * are met:
008: *
009: * * Redistributions of source code must retain the above copyright
010: * notice, this list of conditions and the following disclaimer.
011: *
012: * * Redistributions in binary form must reproduce the above copyright
013: * notice, this list of conditions and the following disclaimer in the
014: * documentation and/or other materials provided with the distribution.
015: *
016: * * Neither the name of Jean Tessier nor the names of his contributors
017: * may be used to endorse or promote products derived from this software
018: * without specific prior written permission.
019: *
020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
021: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
022: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
023: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
024: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
025: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
026: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
027: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
028: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
029: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
030: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
031: */
032:
033: package com.jeantessier.dependency;
034:
035: import java.io.*;
036: import java.util.*;
037:
038: import junit.framework.*;
039:
040: import org.apache.oro.text.perl.*;
041:
042: public class TestLinkMinimizerSystematic extends TestCase {
043: NodeFactory factory;
044:
045: PackageNode a;
046: ClassNode a_A;
047: FeatureNode a_A_a;
048:
049: PackageNode b;
050: ClassNode b_B;
051: FeatureNode b_B_b;
052:
053: protected void setUp() throws Exception {
054: factory = new NodeFactory();
055:
056: a = factory.createPackage("a");
057: a_A = factory.createClass("a.A");
058: a_A_a = factory.createFeature("a.A.a()");
059:
060: b = factory.createPackage("b");
061: b_B = factory.createClass("b.B");
062: b_B_b = factory.createFeature("b.B.b()");
063: }
064:
065: public void testPackagePackage() {
066: a.addDependency(b);
067:
068: Visitor visitor = new LinkMinimizer();
069: visitor.traverseNodes(factory.getPackages().values());
070:
071: assertEquals("a outbound", 1, a.getOutboundDependencies()
072: .size());
073: assertTrue("Missing a --> b", a.getOutboundDependencies()
074: .contains(b));
075: assertEquals("a inbound", 0, a.getInboundDependencies().size());
076: assertEquals("a_A outbound", 0, a_A.getOutboundDependencies()
077: .size());
078: assertEquals("a_A inbound", 0, a_A.getInboundDependencies()
079: .size());
080: assertEquals("a_A_a outbound", 0, a_A_a
081: .getOutboundDependencies().size());
082: assertEquals("a_A_a inbound", 0, a_A_a.getInboundDependencies()
083: .size());
084: assertEquals("b outbound", 0, b.getOutboundDependencies()
085: .size());
086: assertEquals("b inbound", 1, b.getInboundDependencies().size());
087: assertTrue("Missing b <-- a", b.getInboundDependencies()
088: .contains(a));
089: assertEquals("b_B outbound", 0, b_B.getOutboundDependencies()
090: .size());
091: assertEquals("b_B inbound", 0, b_B.getInboundDependencies()
092: .size());
093: assertEquals("b_B_b outbound", 0, b_B_b
094: .getOutboundDependencies().size());
095: assertEquals("b_B_b inbound", 0, b_B_b.getInboundDependencies()
096: .size());
097: }
098:
099: public void testPackageClass() {
100: a.addDependency(b);
101: a.addDependency(b_B);
102:
103: Visitor visitor = new LinkMinimizer();
104: visitor.traverseNodes(factory.getPackages().values());
105:
106: assertEquals("a outbound", 1, a.getOutboundDependencies()
107: .size());
108: assertTrue("Missing a --> b.B", a.getOutboundDependencies()
109: .contains(b_B));
110: assertEquals("a inbound", 0, a.getInboundDependencies().size());
111: assertEquals("a_A outbound", 0, a_A.getOutboundDependencies()
112: .size());
113: assertEquals("a_A inbound", 0, a_A.getInboundDependencies()
114: .size());
115: assertEquals("a_A_a outbound", 0, a_A_a
116: .getOutboundDependencies().size());
117: assertEquals("a_A_a inbound", 0, a_A_a.getInboundDependencies()
118: .size());
119: assertEquals("b outbound", 0, b.getOutboundDependencies()
120: .size());
121: assertEquals("b inbound", 0, b.getInboundDependencies().size());
122: assertEquals("b_B outbound", 0, b_B.getOutboundDependencies()
123: .size());
124: assertEquals("b_B inbound", 1, b_B.getInboundDependencies()
125: .size());
126: assertTrue("Missing b.B <-- a", b_B.getInboundDependencies()
127: .contains(a));
128: assertEquals("b_B_b outbound", 0, b_B_b
129: .getOutboundDependencies().size());
130: assertEquals("b_B_b inbound", 0, b_B_b.getInboundDependencies()
131: .size());
132: }
133:
134: public void testPackageFeature() {
135: a.addDependency(b);
136: a.addDependency(b_B);
137: a.addDependency(b_B_b);
138:
139: Visitor visitor = new LinkMinimizer();
140: visitor.traverseNodes(factory.getPackages().values());
141:
142: assertEquals("a outbound", 1, a.getOutboundDependencies()
143: .size());
144: assertTrue("Missing a --> b.B.b", a.getOutboundDependencies()
145: .contains(b_B_b));
146: assertEquals("a inbound", 0, a.getInboundDependencies().size());
147: assertEquals("a_A outbound", 0, a_A.getOutboundDependencies()
148: .size());
149: assertEquals("a_A inbound", 0, a_A.getInboundDependencies()
150: .size());
151: assertEquals("a_A_a outbound", 0, a_A_a
152: .getOutboundDependencies().size());
153: assertEquals("a_A_a inbound", 0, a_A_a.getInboundDependencies()
154: .size());
155: assertEquals("b outbound", 0, b.getOutboundDependencies()
156: .size());
157: assertEquals("b inbound", 0, b.getInboundDependencies().size());
158: assertEquals("b_B outbound", 0, b_B.getOutboundDependencies()
159: .size());
160: assertEquals("b_B inbound", 0, b_B.getInboundDependencies()
161: .size());
162: assertEquals("b_B_b outbound", 0, b_B_b
163: .getOutboundDependencies().size());
164: assertEquals("b_B_b inbound", 1, b_B_b.getInboundDependencies()
165: .size());
166: assertTrue("Missing b.B.b <-- a", b_B_b
167: .getInboundDependencies().contains(a));
168: }
169:
170: public void testClassPackage() {
171: a.addDependency(b);
172: a_A.addDependency(b);
173:
174: Visitor visitor = new LinkMinimizer();
175: visitor.traverseNodes(factory.getPackages().values());
176:
177: assertEquals("a outbound", 0, a.getOutboundDependencies()
178: .size());
179: assertEquals("a inbound", 0, a.getInboundDependencies().size());
180: assertEquals("a_A outbound", 1, a_A.getOutboundDependencies()
181: .size());
182: assertTrue("Missing a.A --> b", a_A.getOutboundDependencies()
183: .contains(b));
184: assertEquals("a_A inbound", 0, a_A.getInboundDependencies()
185: .size());
186: assertEquals("a_A_a outbound", 0, a_A_a
187: .getOutboundDependencies().size());
188: assertEquals("a_A_a inbound", 0, a_A_a.getInboundDependencies()
189: .size());
190: assertEquals("b outbound", 0, b.getOutboundDependencies()
191: .size());
192: assertEquals("b inbound", 1, b.getInboundDependencies().size());
193: assertTrue("Missing b <-- a.A", b.getInboundDependencies()
194: .contains(a_A));
195: assertEquals("b_B outbound", 0, b_B.getOutboundDependencies()
196: .size());
197: assertEquals("b_B inbound", 0, b_B.getInboundDependencies()
198: .size());
199: assertEquals("b_B_b outbound", 0, b_B_b
200: .getOutboundDependencies().size());
201: assertEquals("b_B_b inbound", 0, b_B_b.getInboundDependencies()
202: .size());
203: }
204:
205: public void testClassClass() {
206: a.addDependency(b);
207: a.addDependency(b_B);
208: a_A.addDependency(b);
209: a_A.addDependency(b_B);
210:
211: Visitor visitor = new LinkMinimizer();
212: visitor.traverseNodes(factory.getPackages().values());
213:
214: assertEquals("a outbound", 0, a.getOutboundDependencies()
215: .size());
216: assertEquals("a inbound", 0, a.getInboundDependencies().size());
217: assertEquals("a_A outbound", 1, a_A.getOutboundDependencies()
218: .size());
219: assertTrue("Missing a.A --> b.B", a_A.getOutboundDependencies()
220: .contains(b_B));
221: assertEquals("a_A inbound", 0, a_A.getInboundDependencies()
222: .size());
223: assertEquals("a_A_a outbound", 0, a_A_a
224: .getOutboundDependencies().size());
225: assertEquals("a_A_a inbound", 0, a_A_a.getInboundDependencies()
226: .size());
227: assertEquals("b outbound", 0, b.getOutboundDependencies()
228: .size());
229: assertEquals("b inbound", 0, b.getInboundDependencies().size());
230: assertEquals("b_B outbound", 0, b_B.getOutboundDependencies()
231: .size());
232: assertEquals("b_B inbound", 1, b_B.getInboundDependencies()
233: .size());
234: assertTrue("Missing b.B <-- a.A", b_B.getInboundDependencies()
235: .contains(a_A));
236: assertEquals("b_B_b outbound", 0, b_B_b
237: .getOutboundDependencies().size());
238: assertEquals("b_B_b inbound", 0, b_B_b.getInboundDependencies()
239: .size());
240: }
241:
242: public void testClassClassSparse() {
243: a.addDependency(b);
244: a_A.addDependency(b_B);
245:
246: Visitor visitor = new LinkMinimizer();
247: visitor.traverseNodes(factory.getPackages().values());
248:
249: assertEquals("a outbound", 0, a.getOutboundDependencies()
250: .size());
251: assertEquals("a inbound", 0, a.getInboundDependencies().size());
252: assertEquals("a_A outbound", 1, a_A.getOutboundDependencies()
253: .size());
254: assertTrue("Missing a.A --> b.B", a_A.getOutboundDependencies()
255: .contains(b_B));
256: assertEquals("a_A inbound", 0, a_A.getInboundDependencies()
257: .size());
258: assertEquals("a_A_a outbound", 0, a_A_a
259: .getOutboundDependencies().size());
260: assertEquals("a_A_a inbound", 0, a_A_a.getInboundDependencies()
261: .size());
262: assertEquals("b outbound", 0, b.getOutboundDependencies()
263: .size());
264: assertEquals("b inbound", 0, b.getInboundDependencies().size());
265: assertEquals("b_B outbound", 0, b_B.getOutboundDependencies()
266: .size());
267: assertEquals("b_B inbound", 1, b_B.getInboundDependencies()
268: .size());
269: assertTrue("Missing b.B <-- a_A", b_B.getInboundDependencies()
270: .contains(a_A));
271: assertEquals("b_B_b outbound", 0, b_B_b
272: .getOutboundDependencies().size());
273: assertEquals("b_B_b inbound", 0, b_B_b.getInboundDependencies()
274: .size());
275: }
276:
277: public void testClassFeature() {
278: a.addDependency(b);
279: a.addDependency(b_B);
280: a.addDependency(b_B_b);
281: a_A.addDependency(b);
282: a_A.addDependency(b_B);
283: a_A.addDependency(b_B_b);
284:
285: Visitor visitor = new LinkMinimizer();
286: visitor.traverseNodes(factory.getPackages().values());
287:
288: assertEquals("a outbound", 0, a.getOutboundDependencies()
289: .size());
290: assertEquals("a inbound", 0, a.getInboundDependencies().size());
291: assertEquals("a_A outbound", 1, a_A.getOutboundDependencies()
292: .size());
293: assertTrue("Missing a.A --> b.B.b", a_A
294: .getOutboundDependencies().contains(b_B_b));
295: assertEquals("a_A inbound", 0, a_A.getInboundDependencies()
296: .size());
297: assertEquals("a_A_a outbound", 0, a_A_a
298: .getOutboundDependencies().size());
299: assertEquals("a_A_a inbound", 0, a_A_a.getInboundDependencies()
300: .size());
301: assertEquals("b outbound", 0, b.getOutboundDependencies()
302: .size());
303: assertEquals("b inbound", 0, b.getInboundDependencies().size());
304: assertEquals("b_B outbound", 0, b_B.getOutboundDependencies()
305: .size());
306: assertEquals("b_B inbound", 0, b_B.getInboundDependencies()
307: .size());
308: assertEquals("b_B_b outbound", 0, b_B_b
309: .getOutboundDependencies().size());
310: assertEquals("b_B_b inbound", 1, b_B_b.getInboundDependencies()
311: .size());
312: assertTrue("Missing b.B.b <-- a_A", b_B_b
313: .getInboundDependencies().contains(a_A));
314: }
315:
316: public void testFeaturePackage() {
317: a.addDependency(b);
318: a_A.addDependency(b);
319: a_A_a.addDependency(b);
320:
321: Visitor visitor = new LinkMinimizer();
322: visitor.traverseNodes(factory.getPackages().values());
323:
324: assertEquals("a outbound", 0, a.getOutboundDependencies()
325: .size());
326: assertEquals("a inbound", 0, a.getInboundDependencies().size());
327: assertEquals("a_A outbound", 0, a_A.getOutboundDependencies()
328: .size());
329: assertEquals("a_A inbound", 0, a_A.getInboundDependencies()
330: .size());
331: assertEquals("a_A_a outbound", 1, a_A_a
332: .getOutboundDependencies().size());
333: assertTrue("Missing a.A.a --> b", a_A_a
334: .getOutboundDependencies().contains(b));
335: assertEquals("a_A_a inbound", 0, a_A_a.getInboundDependencies()
336: .size());
337: assertEquals("b outbound", 0, b.getOutboundDependencies()
338: .size());
339: assertEquals("b inbound", 1, b.getInboundDependencies().size());
340: assertTrue("Missing b <-- a.A.a", b.getInboundDependencies()
341: .contains(a_A_a));
342: assertEquals("b_B outbound", 0, b_B.getOutboundDependencies()
343: .size());
344: assertEquals("b_B inbound", 0, b_B.getInboundDependencies()
345: .size());
346: assertEquals("b_B_b outbound", 0, b_B_b
347: .getOutboundDependencies().size());
348: assertEquals("b_B_b inbound", 0, b_B_b.getInboundDependencies()
349: .size());
350: }
351:
352: public void testFeatureClass() {
353: a.addDependency(b);
354: a.addDependency(b_B);
355: a_A.addDependency(b);
356: a_A.addDependency(b_B);
357: a_A_a.addDependency(b);
358: a_A_a.addDependency(b_B);
359:
360: Visitor visitor = new LinkMinimizer();
361: visitor.traverseNodes(factory.getPackages().values());
362:
363: assertEquals("a outbound", 0, a.getOutboundDependencies()
364: .size());
365: assertEquals("a inbound", 0, a.getInboundDependencies().size());
366: assertEquals("a_A outbound", 0, a_A.getOutboundDependencies()
367: .size());
368: assertEquals("a_A inbound", 0, a_A.getInboundDependencies()
369: .size());
370: assertEquals("a_A_a outbound", 1, a_A_a
371: .getOutboundDependencies().size());
372: assertTrue("Missing a.A.a --> b.B", a_A_a
373: .getOutboundDependencies().contains(b_B));
374: assertEquals("a_A_a inbound", 0, a_A_a.getInboundDependencies()
375: .size());
376: assertEquals("b outbound", 0, b.getOutboundDependencies()
377: .size());
378: assertEquals("b inbound", 0, b.getInboundDependencies().size());
379: assertEquals("b_B outbound", 0, b_B.getOutboundDependencies()
380: .size());
381: assertEquals("b_B inbound", 1, b_B.getInboundDependencies()
382: .size());
383: assertTrue("Missing b.B <-- a.A.a", b_B
384: .getInboundDependencies().contains(a_A_a));
385: assertEquals("b_B_b outbound", 0, b_B_b
386: .getOutboundDependencies().size());
387: assertEquals("b_B_b inbound", 0, b_B_b.getInboundDependencies()
388: .size());
389: }
390:
391: public void testFeatureFeature() {
392: a.addDependency(b);
393: a.addDependency(b_B);
394: a.addDependency(b_B_b);
395: a_A.addDependency(b);
396: a_A.addDependency(b_B);
397: a_A.addDependency(b_B_b);
398: a_A_a.addDependency(b);
399: a_A_a.addDependency(b_B);
400: a_A_a.addDependency(b_B_b);
401:
402: Visitor visitor = new LinkMinimizer();
403: visitor.traverseNodes(factory.getPackages().values());
404:
405: assertEquals("a outbound", 0, a.getOutboundDependencies()
406: .size());
407: assertEquals("a inbound", 0, a.getInboundDependencies().size());
408: assertEquals("a_A outbound", 0, a_A.getOutboundDependencies()
409: .size());
410: assertEquals("a_A inbound", 0, a_A.getInboundDependencies()
411: .size());
412: assertEquals("a_A_a outbound", 1, a_A_a
413: .getOutboundDependencies().size());
414: assertTrue("Missing a.A.a --> b.B.b", a_A_a
415: .getOutboundDependencies().contains(b_B_b));
416: assertEquals("a_A_a inbound", 0, a_A_a.getInboundDependencies()
417: .size());
418: assertEquals("b outbound", 0, b.getOutboundDependencies()
419: .size());
420: assertEquals("b inbound", 0, b.getInboundDependencies().size());
421: assertEquals("b_B outbound", 0, b_B.getOutboundDependencies()
422: .size());
423: assertEquals("b_B inbound", 0, b_B.getInboundDependencies()
424: .size());
425: assertEquals("b_B_b outbound", 0, b_B_b
426: .getOutboundDependencies().size());
427: assertEquals("b_B_b inbound", 1, b_B_b.getInboundDependencies()
428: .size());
429: assertTrue("Missing b.B.b <-- a.A.a", b_B_b
430: .getInboundDependencies().contains(a_A_a));
431: }
432:
433: public void testFeatureFeatureSparse() {
434: a.addDependency(b);
435: a_A.addDependency(b_B);
436: a_A_a.addDependency(b_B_b);
437:
438: Visitor visitor = new LinkMinimizer();
439: visitor.traverseNodes(factory.getPackages().values());
440:
441: assertEquals("a outbound", 0, a.getOutboundDependencies()
442: .size());
443: assertEquals("a inbound", 0, a.getInboundDependencies().size());
444: assertEquals("a_A outbound", 0, a_A.getOutboundDependencies()
445: .size());
446: assertEquals("a_A inbound", 0, a_A.getInboundDependencies()
447: .size());
448: assertEquals("a_A_a outbound", 1, a_A_a
449: .getOutboundDependencies().size());
450: assertTrue("Missing a.A.a --> b.B.b", a_A_a
451: .getOutboundDependencies().contains(b_B_b));
452: assertEquals("a_A_a inbound", 0, a_A_a.getInboundDependencies()
453: .size());
454: assertEquals("b outbound", 0, b.getOutboundDependencies()
455: .size());
456: assertEquals("b inbound", 0, b.getInboundDependencies().size());
457: assertEquals("b_B outbound", 0, b_B.getOutboundDependencies()
458: .size());
459: assertEquals("b_B inbound", 0, b_B.getInboundDependencies()
460: .size());
461: assertEquals("b_B_b outbound", 0, b_B_b
462: .getOutboundDependencies().size());
463: assertEquals("b_B_b inbound", 1, b_B_b.getInboundDependencies()
464: .size());
465: assertTrue("Missing b.B.b <-- a.A.a", b_B_b
466: .getInboundDependencies().contains(a_A_a));
467: }
468: }
|