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.util.*;
036:
037: import junit.framework.*;
038:
039: public class TestTransitiveClosureEngine extends TestCase {
040: private NodeFactory factory;
041:
042: private PackageNode a;
043: private ClassNode a_A;
044: private FeatureNode a_A_a;
045:
046: private PackageNode b;
047: private ClassNode b_B;
048: private FeatureNode b_B_b;
049:
050: private PackageNode c;
051: private ClassNode c_C;
052: private FeatureNode c_C_c;
053:
054: private RegularExpressionSelectionCriteria startCriteria;
055: private RegularExpressionSelectionCriteria stopCriteria;
056:
057: protected void setUp() throws Exception {
058: super .setUp();
059:
060: factory = new NodeFactory();
061:
062: a = factory.createPackage("a");
063: a_A = factory.createClass("a.A");
064: a_A_a = factory.createFeature("a.A.a");
065:
066: b = factory.createPackage("b");
067: b_B = factory.createClass("b.B");
068: b_B_b = factory.createFeature("b.B.b");
069:
070: c = factory.createPackage("c");
071: c_C = factory.createClass("c.C");
072: c_C_c = factory.createFeature("c.C.c");
073:
074: a_A_a.addDependency(b_B_b);
075: b_B_b.addDependency(c_C_c);
076:
077: startCriteria = new RegularExpressionSelectionCriteria();
078: stopCriteria = new RegularExpressionSelectionCriteria();
079: stopCriteria.setGlobalIncludes("");
080: }
081:
082: public void testSelectScope() {
083: startCriteria.setGlobalIncludes("/a.A.a/");
084:
085: GraphCopier copier = new GraphCopier(
086: new SelectiveTraversalStrategy(startCriteria,
087: new RegularExpressionSelectionCriteria()));
088:
089: copier.traverseNodes(factory.getPackages().values());
090:
091: assertEquals("packages in scope: ", 1, copier.getScopeFactory()
092: .getPackages().values().size());
093: assertEquals("classes in scope", 1, copier.getScopeFactory()
094: .getClasses().values().size());
095: assertEquals("features in scope", 1, copier.getScopeFactory()
096: .getFeatures().values().size());
097:
098: assertEquals("package b in scope", a, copier.getScopeFactory()
099: .getPackages().get("a"));
100: assertEquals("class a.A in scope", a_A, copier
101: .getScopeFactory().getClasses().get("a.A"));
102: assertEquals("feature a.A.a in scope", a_A_a, copier
103: .getScopeFactory().getFeatures().get("a.A.a"));
104: }
105:
106: public void testOutboundStartingPoint() {
107: startCriteria.setGlobalIncludes("/a.A.a/");
108:
109: TransitiveClosureEngine engine = new TransitiveClosureEngine(
110: factory.getPackages().values(), startCriteria,
111: stopCriteria, new ClosureOutboundSelector());
112:
113: assertEquals("Nb layers", 1, engine.getNbLayers());
114:
115: assertEquals("layer 0", 1, engine.getLayer(0).size());
116: assertEquals("a.A.a in layer 0", a_A_a, engine.getLayer(0)
117: .iterator().next());
118: assertNotSame("a.A.a in layer 0", a_A_a, engine.getLayer(0)
119: .iterator().next());
120:
121: assertEquals("Nb outbounds from a.A.a", 0, ((Node) engine
122: .getLayer(0).iterator().next())
123: .getOutboundDependencies().size());
124:
125: assertEquals("packages in scope: ", 1, engine.getFactory()
126: .getPackages().values().size());
127: assertEquals("classes in scope", 1, engine.getFactory()
128: .getClasses().values().size());
129: assertEquals("features in scope", 1, engine.getFactory()
130: .getFeatures().values().size());
131:
132: assertEquals("package a in scope", a, engine.getFactory()
133: .getPackages().get("a"));
134: assertEquals("class a.A in scope", a_A, engine.getFactory()
135: .getClasses().get("a.A"));
136: assertEquals("feature a.A.a in scope", a_A_a, engine
137: .getFactory().getFeatures().get("a.A.a"));
138: }
139:
140: public void testOneOutboundLayer() {
141: startCriteria.setGlobalIncludes("/a.A.a/");
142:
143: TransitiveClosureEngine engine = new TransitiveClosureEngine(
144: factory.getPackages().values(), startCriteria,
145: stopCriteria, new ClosureOutboundSelector());
146: engine.computeNextLayer();
147:
148: assertEquals("Nb layers", 2, engine.getNbLayers());
149:
150: assertEquals("layer 1", 1, engine.getLayer(1).size());
151: assertEquals("b.B.b in layer 1", b_B_b, engine.getLayer(1)
152: .iterator().next());
153: assertNotSame("b.B.b in layer 1", b_B_b, engine.getLayer(1)
154: .iterator().next());
155:
156: assertEquals("Nb outbounds from a.A.a", a_A_a
157: .getOutboundDependencies().size(), ((Node) engine
158: .getLayer(0).iterator().next())
159: .getOutboundDependencies().size());
160: assertEquals("Nb outbounds from b.B.b", 0, ((Node) engine
161: .getLayer(1).iterator().next())
162: .getOutboundDependencies().size());
163:
164: assertEquals("packages in scope: ", 2, engine.getFactory()
165: .getPackages().values().size());
166: assertEquals("classes in scope", 2, engine.getFactory()
167: .getClasses().values().size());
168: assertEquals("features in scope", 2, engine.getFactory()
169: .getFeatures().values().size());
170:
171: assertEquals("package a in scope", a, engine.getFactory()
172: .getPackages().get("a"));
173: assertEquals("class a.A in scope", a_A, engine.getFactory()
174: .getClasses().get("a.A"));
175: assertEquals("feature a.A.a in scope", a_A_a, engine
176: .getFactory().getFeatures().get("a.A.a"));
177: assertEquals("package b in scope", b, engine.getFactory()
178: .getPackages().get("b"));
179: assertEquals("class b.B in scope", b_B, engine.getFactory()
180: .getClasses().get("b.B"));
181: assertEquals("feature b.B.b in scope", b_B_b, engine
182: .getFactory().getFeatures().get("b.B.b"));
183: }
184:
185: public void testTwoOutboundLayers() {
186: startCriteria.setGlobalIncludes("/a.A.a/");
187:
188: TransitiveClosureEngine engine = new TransitiveClosureEngine(
189: factory.getPackages().values(), startCriteria,
190: stopCriteria, new ClosureOutboundSelector());
191: engine.computeNextLayer();
192: engine.computeNextLayer();
193:
194: assertEquals("Nb layers", 3, engine.getNbLayers());
195:
196: assertEquals("layer 2", 1, engine.getLayer(1).size());
197: assertEquals("c.C.c in layer 2", c_C_c, engine.getLayer(2)
198: .iterator().next());
199: assertNotSame("c.C.c in layer 2", c_C_c, engine.getLayer(2)
200: .iterator().next());
201:
202: assertEquals("Nb outbounds from a.A.a", a_A_a
203: .getOutboundDependencies().size(), ((Node) engine
204: .getLayer(0).iterator().next())
205: .getOutboundDependencies().size());
206: assertEquals("Nb outbounds from b.B.b", b_B_b
207: .getOutboundDependencies().size(), ((Node) engine
208: .getLayer(1).iterator().next())
209: .getOutboundDependencies().size());
210: assertEquals("Nb outbounds from c.C.c", 0, ((Node) engine
211: .getLayer(2).iterator().next())
212: .getOutboundDependencies().size());
213:
214: assertEquals("packages in scope: ", 3, engine.getFactory()
215: .getPackages().values().size());
216: assertEquals("classes in scope", 3, engine.getFactory()
217: .getClasses().values().size());
218: assertEquals("features in scope", 3, engine.getFactory()
219: .getFeatures().values().size());
220:
221: assertEquals("package a in scope", a, engine.getFactory()
222: .getPackages().get("a"));
223: assertEquals("class a.A in scope", a_A, engine.getFactory()
224: .getClasses().get("a.A"));
225: assertEquals("feature a.A.a in scope", a_A_a, engine
226: .getFactory().getFeatures().get("a.A.a"));
227: assertEquals("package b in scope", b, engine.getFactory()
228: .getPackages().get("b"));
229: assertEquals("class b.B in scope", b_B, engine.getFactory()
230: .getClasses().get("b.B"));
231: assertEquals("feature b.B.b in scope", b_B_b, engine
232: .getFactory().getFeatures().get("b.B.b"));
233: assertEquals("package c in scope", c, engine.getFactory()
234: .getPackages().get("c"));
235: assertEquals("class c.C in scope", c_C, engine.getFactory()
236: .getClasses().get("c.C"));
237: assertEquals("feature c.C.c in scope", c_C_c, engine
238: .getFactory().getFeatures().get("c.C.c"));
239: }
240:
241: public void testThreeOutboundLayers() {
242: startCriteria.setGlobalIncludes("/a.A.a/");
243:
244: TransitiveClosureEngine engine = new TransitiveClosureEngine(
245: factory.getPackages().values(), startCriteria,
246: stopCriteria, new ClosureOutboundSelector());
247: engine.computeNextLayer();
248: engine.computeNextLayer();
249: engine.computeNextLayer();
250:
251: assertEquals("Nb layers", 3, engine.getNbLayers());
252:
253: assertEquals("Nb outbounds from a.A.a", a_A_a
254: .getOutboundDependencies().size(), ((Node) engine
255: .getLayer(0).iterator().next())
256: .getOutboundDependencies().size());
257: assertEquals("Nb outbounds from b.B.b", b_B_b
258: .getOutboundDependencies().size(), ((Node) engine
259: .getLayer(1).iterator().next())
260: .getOutboundDependencies().size());
261: assertEquals("Nb outbounds from c.C.c", c_C_c
262: .getOutboundDependencies().size(), ((Node) engine
263: .getLayer(2).iterator().next())
264: .getOutboundDependencies().size());
265:
266: assertEquals("packages in scope: ", 3, engine.getFactory()
267: .getPackages().values().size());
268: assertEquals("classes in scope", 3, engine.getFactory()
269: .getClasses().values().size());
270: assertEquals("features in scope", 3, engine.getFactory()
271: .getFeatures().values().size());
272:
273: assertEquals("package a in scope", a, engine.getFactory()
274: .getPackages().get("a"));
275: assertEquals("class a.A in scope", a_A, engine.getFactory()
276: .getClasses().get("a.A"));
277: assertEquals("feature a.A.a in scope", a_A_a, engine
278: .getFactory().getFeatures().get("a.A.a"));
279: assertEquals("package b in scope", b, engine.getFactory()
280: .getPackages().get("b"));
281: assertEquals("class b.B in scope", b_B, engine.getFactory()
282: .getClasses().get("b.B"));
283: assertEquals("feature b.B.b in scope", b_B_b, engine
284: .getFactory().getFeatures().get("b.B.b"));
285: assertEquals("package c in scope", c, engine.getFactory()
286: .getPackages().get("c"));
287: assertEquals("class c.C in scope", c_C, engine.getFactory()
288: .getClasses().get("c.C"));
289: assertEquals("feature c.C.c in scope", c_C_c, engine
290: .getFactory().getFeatures().get("c.C.c"));
291: }
292:
293: public void testFourOutboundLayers() {
294: startCriteria.setGlobalIncludes("/a.A.a/");
295:
296: TransitiveClosureEngine engine = new TransitiveClosureEngine(
297: factory.getPackages().values(), startCriteria,
298: stopCriteria, new ClosureOutboundSelector());
299: engine.computeNextLayer();
300: engine.computeNextLayer();
301: engine.computeNextLayer();
302: engine.computeNextLayer();
303:
304: assertEquals("Nb layers", 3, engine.getNbLayers());
305:
306: assertEquals("Nb outbounds from a.A.a", a_A_a
307: .getOutboundDependencies().size(), ((Node) engine
308: .getLayer(0).iterator().next())
309: .getOutboundDependencies().size());
310: assertEquals("Nb outbounds from b.B.b", b_B_b
311: .getOutboundDependencies().size(), ((Node) engine
312: .getLayer(1).iterator().next())
313: .getOutboundDependencies().size());
314: assertEquals("Nb outbounds from c.C.c", c_C_c
315: .getOutboundDependencies().size(), ((Node) engine
316: .getLayer(2).iterator().next())
317: .getOutboundDependencies().size());
318:
319: assertEquals("packages in scope: ", 3, engine.getFactory()
320: .getPackages().values().size());
321: assertEquals("classes in scope", 3, engine.getFactory()
322: .getClasses().values().size());
323: assertEquals("features in scope", 3, engine.getFactory()
324: .getFeatures().values().size());
325:
326: assertEquals("package a in scope", a, engine.getFactory()
327: .getPackages().get("a"));
328: assertEquals("class a.A in scope", a_A, engine.getFactory()
329: .getClasses().get("a.A"));
330: assertEquals("feature a.A.a in scope", a_A_a, engine
331: .getFactory().getFeatures().get("a.A.a"));
332: assertEquals("package b in scope", b, engine.getFactory()
333: .getPackages().get("b"));
334: assertEquals("class b.B in scope", b_B, engine.getFactory()
335: .getClasses().get("b.B"));
336: assertEquals("feature b.B.b in scope", b_B_b, engine
337: .getFactory().getFeatures().get("b.B.b"));
338: assertEquals("package c in scope", c, engine.getFactory()
339: .getPackages().get("c"));
340: assertEquals("class c.C in scope", c_C, engine.getFactory()
341: .getClasses().get("c.C"));
342: assertEquals("feature c.C.c in scope", c_C_c, engine
343: .getFactory().getFeatures().get("c.C.c"));
344: }
345:
346: public void testInboundStartingPoint() {
347: startCriteria.setGlobalIncludes("/c.C.c/");
348:
349: TransitiveClosureEngine engine = new TransitiveClosureEngine(
350: factory.getPackages().values(), startCriteria,
351: stopCriteria, new ClosureInboundSelector());
352:
353: assertEquals("Nb layers", 1, engine.getNbLayers());
354:
355: assertEquals("layer 0", 1, engine.getLayer(0).size());
356: assertEquals("c.C.c in layer 0", c_C_c, engine.getLayer(0)
357: .iterator().next());
358: assertNotSame("c.C.c in layer 0", c_C_c, engine.getLayer(0)
359: .iterator().next());
360:
361: assertEquals("Nb inbounds from c.C.c", 0, ((Node) engine
362: .getLayer(0).iterator().next())
363: .getInboundDependencies().size());
364:
365: assertEquals("packages in scope: ", 1, engine.getFactory()
366: .getPackages().values().size());
367: assertEquals("classes in scope", 1, engine.getFactory()
368: .getClasses().values().size());
369: assertEquals("features in scope", 1, engine.getFactory()
370: .getFeatures().values().size());
371:
372: assertEquals("package c in scope", c, engine.getFactory()
373: .getPackages().get("c"));
374: assertEquals("class c.C in scope", c_C, engine.getFactory()
375: .getClasses().get("c.C"));
376: assertEquals("feature c.C.c in scope", c_C_c, engine
377: .getFactory().getFeatures().get("c.C.c"));
378: }
379:
380: public void testOneInboundLayer() {
381: startCriteria.setGlobalIncludes("/c.C.c/");
382:
383: TransitiveClosureEngine engine = new TransitiveClosureEngine(
384: factory.getPackages().values(), startCriteria,
385: stopCriteria, new ClosureInboundSelector());
386: engine.computeNextLayer();
387:
388: assertEquals("Nb layers", 2, engine.getNbLayers());
389:
390: assertEquals("layer 1", 1, engine.getLayer(1).size());
391: assertEquals("b.B.b in layer 1", b_B_b, engine.getLayer(1)
392: .iterator().next());
393: assertNotSame("b.B.b in layer 1", b_B_b, engine.getLayer(1)
394: .iterator().next());
395:
396: assertEquals("Nb inbounds from c.C.c", c_C_c
397: .getInboundDependencies().size(), ((Node) engine
398: .getLayer(0).iterator().next())
399: .getInboundDependencies().size());
400: assertEquals("Nb inbounds from b.B.b", 0, ((Node) engine
401: .getLayer(1).iterator().next())
402: .getInboundDependencies().size());
403:
404: assertEquals("packages in scope: ", 2, engine.getFactory()
405: .getPackages().values().size());
406: assertEquals("classes in scope", 2, engine.getFactory()
407: .getClasses().values().size());
408: assertEquals("features in scope", 2, engine.getFactory()
409: .getFeatures().values().size());
410:
411: assertEquals("package b in scope", b, engine.getFactory()
412: .getPackages().get("b"));
413: assertEquals("class b.B in scope", b_B, engine.getFactory()
414: .getClasses().get("b.B"));
415: assertEquals("feature b.B.b in scope", b_B_b, engine
416: .getFactory().getFeatures().get("b.B.b"));
417: assertEquals("package c in scope", c, engine.getFactory()
418: .getPackages().get("c"));
419: assertEquals("class c.C in scope", c_C, engine.getFactory()
420: .getClasses().get("c.C"));
421: assertEquals("feature c.C.c in scope", c_C_c, engine
422: .getFactory().getFeatures().get("c.C.c"));
423: }
424:
425: public void testTwoInboundLayers() {
426: startCriteria.setGlobalIncludes("/c.C.c/");
427:
428: TransitiveClosureEngine engine = new TransitiveClosureEngine(
429: factory.getPackages().values(), startCriteria,
430: stopCriteria, new ClosureInboundSelector());
431: engine.computeNextLayer();
432: engine.computeNextLayer();
433:
434: assertEquals("Nb layers", 3, engine.getNbLayers());
435:
436: assertEquals("layer 2", 1, engine.getLayer(1).size());
437: assertEquals("a.A.a in layer 2", a_A_a, engine.getLayer(2)
438: .iterator().next());
439: assertNotSame("a.A.a in layer 2", a_A_a, engine.getLayer(2)
440: .iterator().next());
441:
442: assertEquals("Nb inbounds from c.C.c", c_C_c
443: .getInboundDependencies().size(), ((Node) engine
444: .getLayer(0).iterator().next())
445: .getInboundDependencies().size());
446: assertEquals("Nb inbounds from b.B.b", b_B_b
447: .getInboundDependencies().size(), ((Node) engine
448: .getLayer(1).iterator().next())
449: .getInboundDependencies().size());
450: assertEquals("Nb inbounds from a.A.a", 0, ((Node) engine
451: .getLayer(2).iterator().next())
452: .getInboundDependencies().size());
453:
454: assertEquals("packages in scope: ", 3, engine.getFactory()
455: .getPackages().values().size());
456: assertEquals("classes in scope", 3, engine.getFactory()
457: .getClasses().values().size());
458: assertEquals("features in scope", 3, engine.getFactory()
459: .getFeatures().values().size());
460:
461: assertEquals("package a in scope", a, engine.getFactory()
462: .getPackages().get("a"));
463: assertEquals("class a.A in scope", a_A, engine.getFactory()
464: .getClasses().get("a.A"));
465: assertEquals("feature a.A.a in scope", a_A_a, engine
466: .getFactory().getFeatures().get("a.A.a"));
467: assertEquals("package b in scope", b, engine.getFactory()
468: .getPackages().get("b"));
469: assertEquals("class b.B in scope", b_B, engine.getFactory()
470: .getClasses().get("b.B"));
471: assertEquals("feature b.B.b in scope", b_B_b, engine
472: .getFactory().getFeatures().get("b.B.b"));
473: assertEquals("package c in scope", c, engine.getFactory()
474: .getPackages().get("c"));
475: assertEquals("class c.C in scope", c_C, engine.getFactory()
476: .getClasses().get("c.C"));
477: assertEquals("feature c.C.c in scope", c_C_c, engine
478: .getFactory().getFeatures().get("c.C.c"));
479: }
480:
481: public void testThreeInboundLayers() {
482: startCriteria.setGlobalIncludes("/c.C.c/");
483:
484: TransitiveClosureEngine engine = new TransitiveClosureEngine(
485: factory.getPackages().values(), startCriteria,
486: stopCriteria, new ClosureInboundSelector());
487: engine.computeNextLayer();
488: engine.computeNextLayer();
489: engine.computeNextLayer();
490:
491: assertEquals("Nb layers", 3, engine.getNbLayers());
492:
493: assertEquals("Nb inbounds from c.C.c", c_C_c
494: .getInboundDependencies().size(), ((Node) engine
495: .getLayer(0).iterator().next())
496: .getInboundDependencies().size());
497: assertEquals("Nb inbounds from b.B.b", b_B_b
498: .getInboundDependencies().size(), ((Node) engine
499: .getLayer(1).iterator().next())
500: .getInboundDependencies().size());
501: assertEquals("Nb inbounds from a.A.a", a_A_a
502: .getInboundDependencies().size(), ((Node) engine
503: .getLayer(2).iterator().next())
504: .getInboundDependencies().size());
505:
506: assertEquals("packages in scope: ", 3, engine.getFactory()
507: .getPackages().values().size());
508: assertEquals("classes in scope", 3, engine.getFactory()
509: .getClasses().values().size());
510: assertEquals("features in scope", 3, engine.getFactory()
511: .getFeatures().values().size());
512:
513: assertEquals("package a in scope", a, engine.getFactory()
514: .getPackages().get("a"));
515: assertEquals("class a.A in scope", a_A, engine.getFactory()
516: .getClasses().get("a.A"));
517: assertEquals("feature a.A.a in scope", a_A_a, engine
518: .getFactory().getFeatures().get("a.A.a"));
519: assertEquals("package b in scope", b, engine.getFactory()
520: .getPackages().get("b"));
521: assertEquals("class b.B in scope", b_B, engine.getFactory()
522: .getClasses().get("b.B"));
523: assertEquals("feature b.B.b in scope", b_B_b, engine
524: .getFactory().getFeatures().get("b.B.b"));
525: assertEquals("package c in scope", c, engine.getFactory()
526: .getPackages().get("c"));
527: assertEquals("class c.C in scope", c_C, engine.getFactory()
528: .getClasses().get("c.C"));
529: assertEquals("feature c.C.c in scope", c_C_c, engine
530: .getFactory().getFeatures().get("c.C.c"));
531: }
532:
533: public void testFourInboundLayers() {
534: startCriteria.setGlobalIncludes("/c.C.c/");
535:
536: TransitiveClosureEngine engine = new TransitiveClosureEngine(
537: factory.getPackages().values(), startCriteria,
538: stopCriteria, new ClosureInboundSelector());
539: engine.computeNextLayer();
540: engine.computeNextLayer();
541: engine.computeNextLayer();
542: engine.computeNextLayer();
543:
544: assertEquals("Nb layers", 3, engine.getNbLayers());
545:
546: assertEquals("Nb inbounds from c.C.c", c_C_c
547: .getInboundDependencies().size(), ((Node) engine
548: .getLayer(0).iterator().next())
549: .getInboundDependencies().size());
550: assertEquals("Nb inbounds from b.B.b", b_B_b
551: .getInboundDependencies().size(), ((Node) engine
552: .getLayer(1).iterator().next())
553: .getInboundDependencies().size());
554: assertEquals("Nb inbounds from a.A.a", a_A_a
555: .getInboundDependencies().size(), ((Node) engine
556: .getLayer(2).iterator().next())
557: .getInboundDependencies().size());
558:
559: assertEquals("packages in scope: ", 3, engine.getFactory()
560: .getPackages().values().size());
561: assertEquals("classes in scope", 3, engine.getFactory()
562: .getClasses().values().size());
563: assertEquals("features in scope", 3, engine.getFactory()
564: .getFeatures().values().size());
565:
566: assertEquals("package a in scope", a, engine.getFactory()
567: .getPackages().get("a"));
568: assertEquals("class a.A in scope", a_A, engine.getFactory()
569: .getClasses().get("a.A"));
570: assertEquals("feature a.A.a in scope", a_A_a, engine
571: .getFactory().getFeatures().get("a.A.a"));
572: assertEquals("package b in scope", b, engine.getFactory()
573: .getPackages().get("b"));
574: assertEquals("class b.B in scope", b_B, engine.getFactory()
575: .getClasses().get("b.B"));
576: assertEquals("feature b.B.b in scope", b_B_b, engine
577: .getFactory().getFeatures().get("b.B.b"));
578: assertEquals("package c in scope", c, engine.getFactory()
579: .getPackages().get("c"));
580: assertEquals("class c.C in scope", c_C, engine.getFactory()
581: .getClasses().get("c.C"));
582: assertEquals("feature c.C.c in scope", c_C_c, engine
583: .getFactory().getFeatures().get("c.C.c"));
584: }
585:
586: public void testStopCriteria() {
587: startCriteria.setGlobalIncludes("/c.C.c/");
588: stopCriteria.setGlobalIncludes("/b.B.b/");
589:
590: TransitiveClosureEngine engine = new TransitiveClosureEngine(
591: factory.getPackages().values(), startCriteria,
592: stopCriteria, new ClosureInboundSelector());
593: engine.computeNextLayer();
594: engine.computeNextLayer();
595: engine.computeNextLayer();
596: engine.computeNextLayer();
597:
598: assertEquals("Nb layers", 2, engine.getNbLayers());
599:
600: assertEquals("Nb inbounds from c.C.c", c_C_c
601: .getInboundDependencies().size(), ((Node) engine
602: .getLayer(0).iterator().next())
603: .getInboundDependencies().size());
604: assertEquals("Nb inbounds from b.B.b", 0, ((Node) engine
605: .getLayer(1).iterator().next())
606: .getInboundDependencies().size());
607:
608: assertEquals("packages in scope: ", 2, engine.getFactory()
609: .getPackages().values().size());
610: assertEquals("classes in scope", 2, engine.getFactory()
611: .getClasses().values().size());
612: assertEquals("features in scope", 2, engine.getFactory()
613: .getFeatures().values().size());
614:
615: assertEquals("package b in scope", b, engine.getFactory()
616: .getPackages().get("b"));
617: assertEquals("class b.B in scope", b_B, engine.getFactory()
618: .getClasses().get("b.B"));
619: assertEquals("feature b.B.b in scope", b_B_b, engine
620: .getFactory().getFeatures().get("b.B.b"));
621: assertEquals("package c in scope", c, engine.getFactory()
622: .getPackages().get("c"));
623: assertEquals("class c.C in scope", c_C, engine.getFactory()
624: .getClasses().get("c.C"));
625: assertEquals("feature c.C.c in scope", c_C_c, engine
626: .getFactory().getFeatures().get("c.C.c"));
627: }
628:
629: public void testComputeAllLayers() {
630: startCriteria.setGlobalIncludes("/c.C.c/");
631:
632: TransitiveClosureEngine engine = new TransitiveClosureEngine(
633: factory.getPackages().values(), startCriteria,
634: stopCriteria, new ClosureInboundSelector());
635: engine.computeAllLayers();
636:
637: assertEquals("Nb layers", 3, engine.getNbLayers());
638:
639: assertEquals("Nb inbounds from c.C.c", c_C_c
640: .getInboundDependencies().size(), ((Node) engine
641: .getLayer(0).iterator().next())
642: .getInboundDependencies().size());
643: assertEquals("Nb inbounds from b.B.b", b_B_b
644: .getInboundDependencies().size(), ((Node) engine
645: .getLayer(1).iterator().next())
646: .getInboundDependencies().size());
647: assertEquals("Nb inbounds from a.A.a", a_A_a
648: .getInboundDependencies().size(), ((Node) engine
649: .getLayer(2).iterator().next())
650: .getInboundDependencies().size());
651:
652: assertEquals("packages in scope: ", 3, engine.getFactory()
653: .getPackages().values().size());
654: assertEquals("classes in scope", 3, engine.getFactory()
655: .getClasses().values().size());
656: assertEquals("features in scope", 3, engine.getFactory()
657: .getFeatures().values().size());
658:
659: assertEquals("package a in scope", a, engine.getFactory()
660: .getPackages().get("a"));
661: assertEquals("class a.A in scope", a_A, engine.getFactory()
662: .getClasses().get("a.A"));
663: assertEquals("feature a.A.a in scope", a_A_a, engine
664: .getFactory().getFeatures().get("a.A.a"));
665: assertEquals("package b in scope", b, engine.getFactory()
666: .getPackages().get("b"));
667: assertEquals("class b.B in scope", b_B, engine.getFactory()
668: .getClasses().get("b.B"));
669: assertEquals("feature b.B.b in scope", b_B_b, engine
670: .getFactory().getFeatures().get("b.B.b"));
671: assertEquals("package c in scope", c, engine.getFactory()
672: .getPackages().get("c"));
673: assertEquals("class c.C in scope", c_C, engine.getFactory()
674: .getClasses().get("c.C"));
675: assertEquals("feature c.C.c in scope", c_C_c, engine
676: .getFactory().getFeatures().get("c.C.c"));
677: }
678:
679: public void testComputeAllLayersWithStopCriteria() {
680: startCriteria.setGlobalIncludes("/c.C.c/");
681: stopCriteria.setGlobalIncludes("/b.B.b/");
682:
683: TransitiveClosureEngine engine = new TransitiveClosureEngine(
684: factory.getPackages().values(), startCriteria,
685: stopCriteria, new ClosureInboundSelector());
686: engine.computeAllLayers();
687:
688: assertEquals("Nb layers", 2, engine.getNbLayers());
689:
690: assertEquals("Nb inbounds from c.C.c", c_C_c
691: .getInboundDependencies().size(), ((Node) engine
692: .getLayer(0).iterator().next())
693: .getInboundDependencies().size());
694: assertEquals("Nb inbounds from b.B.b", 0, ((Node) engine
695: .getLayer(1).iterator().next())
696: .getInboundDependencies().size());
697:
698: assertEquals("packages in scope: ", 2, engine.getFactory()
699: .getPackages().values().size());
700: assertEquals("classes in scope", 2, engine.getFactory()
701: .getClasses().values().size());
702: assertEquals("features in scope", 2, engine.getFactory()
703: .getFeatures().values().size());
704:
705: assertEquals("package b in scope", b, engine.getFactory()
706: .getPackages().get("b"));
707: assertEquals("class b.B in scope", b_B, engine.getFactory()
708: .getClasses().get("b.B"));
709: assertEquals("feature b.B.b in scope", b_B_b, engine
710: .getFactory().getFeatures().get("b.B.b"));
711: assertEquals("package c in scope", c, engine.getFactory()
712: .getPackages().get("c"));
713: assertEquals("class c.C in scope", c_C, engine.getFactory()
714: .getClasses().get("c.C"));
715: assertEquals("feature c.C.c in scope", c_C_c, engine
716: .getFactory().getFeatures().get("c.C.c"));
717: }
718:
719: public void testComputeAllLayersUntilStartCriteria() {
720: startCriteria.setGlobalIncludes("/c.C.c/");
721: stopCriteria.setGlobalIncludes("//");
722:
723: TransitiveClosureEngine engine = new TransitiveClosureEngine(
724: factory.getPackages().values(), startCriteria,
725: stopCriteria, new ClosureInboundSelector());
726: engine.computeAllLayers();
727:
728: assertEquals("Nb layers", 1, engine.getNbLayers());
729:
730: assertEquals("Nb inbounds from c.C.c", 0, ((Node) engine
731: .getLayer(0).iterator().next())
732: .getInboundDependencies().size());
733:
734: assertEquals("packages in scope: ", 1, engine.getFactory()
735: .getPackages().values().size());
736: assertEquals("classes in scope", 1, engine.getFactory()
737: .getClasses().values().size());
738: assertEquals("features in scope", 1, engine.getFactory()
739: .getFeatures().values().size());
740:
741: assertEquals("package c in scope", c, engine.getFactory()
742: .getPackages().get("c"));
743: assertEquals("class c.C in scope", c_C, engine.getFactory()
744: .getClasses().get("c.C"));
745: assertEquals("feature c.C.c in scope", c_C_c, engine
746: .getFactory().getFeatures().get("c.C.c"));
747: }
748:
749: public void testCompute1LayerOnly() {
750: startCriteria.setGlobalIncludes("/c.C.c/");
751: stopCriteria.setGlobalIncludes("");
752:
753: TransitiveClosureEngine engine = new TransitiveClosureEngine(
754: factory.getPackages().values(), startCriteria,
755: stopCriteria, new ClosureInboundSelector());
756: engine.computeLayers(1);
757:
758: assertEquals("Nb layers", 2, engine.getNbLayers());
759:
760: assertEquals("Nb inbounds from c.C.c", c_C_c
761: .getInboundDependencies().size(), ((Node) engine
762: .getLayer(0).iterator().next())
763: .getInboundDependencies().size());
764: assertEquals("Nb inbounds from b.B.b", 0, ((Node) engine
765: .getLayer(1).iterator().next())
766: .getInboundDependencies().size());
767:
768: assertEquals("packages in scope: ", 2, engine.getFactory()
769: .getPackages().values().size());
770: assertEquals("classes in scope", 2, engine.getFactory()
771: .getClasses().values().size());
772: assertEquals("features in scope", 2, engine.getFactory()
773: .getFeatures().values().size());
774:
775: assertEquals("package b in scope", b, engine.getFactory()
776: .getPackages().get("b"));
777: assertEquals("class b.B in scope", b_B, engine.getFactory()
778: .getClasses().get("b.B"));
779: assertEquals("feature b.B.b in scope", b_B_b, engine
780: .getFactory().getFeatures().get("b.B.b"));
781: assertEquals("package c in scope", c, engine.getFactory()
782: .getPackages().get("c"));
783: assertEquals("class c.C in scope", c_C, engine.getFactory()
784: .getClasses().get("c.C"));
785: assertEquals("feature c.C.c in scope", c_C_c, engine
786: .getFactory().getFeatures().get("c.C.c"));
787: }
788:
789: public void testCompute4LayersWithStopCriteria() {
790: startCriteria.setGlobalIncludes("/c.C.c/");
791: stopCriteria.setGlobalIncludes("/b.B.b/");
792:
793: TransitiveClosureEngine engine = new TransitiveClosureEngine(
794: factory.getPackages().values(), startCriteria,
795: stopCriteria, new ClosureInboundSelector());
796: engine.computeLayers(4);
797:
798: assertEquals("Nb layers", 2, engine.getNbLayers());
799:
800: assertEquals("Nb inbounds from c.C.c", c_C_c
801: .getInboundDependencies().size(), ((Node) engine
802: .getLayer(0).iterator().next())
803: .getInboundDependencies().size());
804: assertEquals("Nb inbounds from b.B.b", 0, ((Node) engine
805: .getLayer(1).iterator().next())
806: .getInboundDependencies().size());
807:
808: assertEquals("packages in scope: ", 2, engine.getFactory()
809: .getPackages().values().size());
810: assertEquals("classes in scope", 2, engine.getFactory()
811: .getClasses().values().size());
812: assertEquals("features in scope", 2, engine.getFactory()
813: .getFeatures().values().size());
814:
815: assertEquals("package b in scope", b, engine.getFactory()
816: .getPackages().get("b"));
817: assertEquals("class b.B in scope", b_B, engine.getFactory()
818: .getClasses().get("b.B"));
819: assertEquals("feature b.B.b in scope", b_B_b, engine
820: .getFactory().getFeatures().get("b.B.b"));
821: assertEquals("package c in scope", c, engine.getFactory()
822: .getPackages().get("c"));
823: assertEquals("class c.C in scope", c_C, engine.getFactory()
824: .getClasses().get("c.C"));
825: assertEquals("feature c.C.c in scope", c_C_c, engine
826: .getFactory().getFeatures().get("c.C.c"));
827: }
828:
829: public void testComputeAllOutboundLayersP2P() {
830: startCriteria.setGlobalIncludes("/^a/");
831: stopCriteria.setGlobalIncludes("/^c/");
832:
833: TransitiveClosureEngine engine = new TransitiveClosureEngine(
834: factory.getPackages().values(), startCriteria,
835: stopCriteria, new ClosureOutboundSelector());
836: engine.computeAllLayers();
837:
838: assertEquals("Nb layers", 3, engine.getNbLayers());
839:
840: Node node = null;
841: Iterator i = engine.getLayer(0).iterator();
842: while (i.hasNext()) {
843: Node temp = (Node) i.next();
844: if (temp.equals(a_A_a)) {
845: node = temp;
846: }
847: }
848:
849: assertEquals("Layer 0 size", 3, engine.getLayer(0).size());
850: assertEquals("Layer 0 content", a_A_a.getName(), node.getName());
851: assertEquals("Nb outbounds from a.A.a", a_A_a
852: .getOutboundDependencies().size(), node
853: .getOutboundDependencies().size());
854: assertEquals("Layer 1 size", 1, engine.getLayer(1).size());
855: assertEquals("Layer 1 content", b_B_b.getName(), ((Node) engine
856: .getLayer(1).iterator().next()).getName());
857: assertEquals("Nb outbounds from b.B.b", b_B_b
858: .getOutboundDependencies().size(), ((Node) engine
859: .getLayer(1).iterator().next())
860: .getOutboundDependencies().size());
861: assertEquals("Layer 2 size", 1, engine.getLayer(2).size());
862: assertEquals("Layer 2 content", c_C_c.getName(), ((Node) engine
863: .getLayer(2).iterator().next()).getName());
864: assertEquals("Nb outbounds from c.C.c", c_C_c
865: .getOutboundDependencies().size(), ((Node) engine
866: .getLayer(2).iterator().next())
867: .getOutboundDependencies().size());
868:
869: assertEquals("packages in scope: ", 3, engine.getFactory()
870: .getPackages().values().size());
871: assertEquals("classes in scope", 3, engine.getFactory()
872: .getClasses().values().size());
873: assertEquals("features in scope", 3, engine.getFactory()
874: .getFeatures().values().size());
875:
876: assertEquals("package a in scope", a, engine.getFactory()
877: .getPackages().get("a"));
878: assertEquals("class a.A in scope", a_A, engine.getFactory()
879: .getClasses().get("a.A"));
880: assertEquals("feature a.A.a in scope", a_A_a, engine
881: .getFactory().getFeatures().get("a.A.a"));
882: assertEquals("package b in scope", b, engine.getFactory()
883: .getPackages().get("b"));
884: assertEquals("class b.B in scope", b_B, engine.getFactory()
885: .getClasses().get("b.B"));
886: assertEquals("feature b.B.b in scope", b_B_b, engine
887: .getFactory().getFeatures().get("b.B.b"));
888: assertEquals("package c in scope", c, engine.getFactory()
889: .getPackages().get("c"));
890: assertEquals("class c.C in scope", c_C, engine.getFactory()
891: .getClasses().get("c.C"));
892: assertEquals("feature c.C.c in scope", c_C_c, engine
893: .getFactory().getFeatures().get("c.C.c"));
894: }
895:
896: public void testComputeAllInboundLayersP2P() {
897: startCriteria.setGlobalIncludes("/^c/");
898: stopCriteria.setGlobalIncludes("/^a/");
899:
900: TransitiveClosureEngine engine = new TransitiveClosureEngine(
901: factory.getPackages().values(), startCriteria,
902: stopCriteria, new ClosureInboundSelector());
903: engine.computeAllLayers();
904:
905: assertEquals("Nb layers", 3, engine.getNbLayers());
906:
907: Node node = null;
908: Iterator i = engine.getLayer(0).iterator();
909: while (i.hasNext()) {
910: Node temp = (Node) i.next();
911: if (temp.equals(c_C_c)) {
912: node = temp;
913: }
914: }
915:
916: assertEquals("Layer 0 size", 3, engine.getLayer(0).size());
917: assertEquals("Layer 0 content", c_C_c.getName(), node.getName());
918: assertEquals("Nb inbounds from c.C.c", c_C_c
919: .getInboundDependencies().size(), node
920: .getInboundDependencies().size());
921: assertEquals("Layer 1 size", 1, engine.getLayer(1).size());
922: assertEquals("Layer 1 content", b_B_b.getName(), ((Node) engine
923: .getLayer(1).iterator().next()).getName());
924: assertEquals("Nb inbounds from b.B.b", b_B_b
925: .getInboundDependencies().size(), ((Node) engine
926: .getLayer(1).iterator().next())
927: .getInboundDependencies().size());
928: assertEquals("Layer 2 size", 1, engine.getLayer(1).size());
929: assertEquals("Layer 2 content", a_A_a.getName(), ((Node) engine
930: .getLayer(2).iterator().next()).getName());
931: assertEquals("Nb inbounds from a.A.a", a_A_a
932: .getInboundDependencies().size(), ((Node) engine
933: .getLayer(2).iterator().next())
934: .getInboundDependencies().size());
935:
936: assertEquals("packages in scope: ", 3, engine.getFactory()
937: .getPackages().values().size());
938: assertEquals("classes in scope", 3, engine.getFactory()
939: .getClasses().values().size());
940: assertEquals("features in scope", 3, engine.getFactory()
941: .getFeatures().values().size());
942:
943: assertEquals("package a in scope", a, engine.getFactory()
944: .getPackages().get("a"));
945: assertEquals("class a.A in scope", a_A, engine.getFactory()
946: .getClasses().get("a.A"));
947: assertEquals("feature a.A.a in scope", a_A_a, engine
948: .getFactory().getFeatures().get("a.A.a"));
949: assertEquals("package b in scope", b, engine.getFactory()
950: .getPackages().get("b"));
951: assertEquals("class b.B in scope", b_B, engine.getFactory()
952: .getClasses().get("b.B"));
953: assertEquals("feature b.B.b in scope", b_B_b, engine
954: .getFactory().getFeatures().get("b.B.b"));
955: assertEquals("package c in scope", c, engine.getFactory()
956: .getPackages().get("c"));
957: assertEquals("class c.C in scope", c_C, engine.getFactory()
958: .getClasses().get("c.C"));
959: assertEquals("feature c.C.c in scope", c_C_c, engine
960: .getFactory().getFeatures().get("c.C.c"));
961: }
962: }
|