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 junit.framework.*;
036:
037: public class TestGraphSummarizerWithConfirmed extends TestCase {
038: private NodeFactory factory;
039:
040: private Node a;
041: private Node a_A;
042: private Node a_A_a;
043:
044: private Node b;
045: private Node b_B;
046: private Node b_B_b;
047:
048: private Node c;
049: private Node c_C;
050: private Node c_C_c;
051:
052: private CollectionSelectionCriteria scopeSelector;
053: private CollectionSelectionCriteria filterSelector;
054: private GraphSummarizer summarizer;
055:
056: protected void setUp() throws Exception {
057: factory = new NodeFactory();
058:
059: a = factory.createPackage("a");
060: a_A = factory.createClass("a.A");
061: a_A_a = factory.createFeature("a.A.a");
062:
063: b = factory.createPackage("b");
064: b_B = factory.createClass("b.B");
065: b_B_b = factory.createFeature("b.B.b");
066:
067: c = factory.createPackage("c");
068: c_C = factory.createClass("c.C");
069: c_C_c = factory.createFeature("c.C.c");
070:
071: scopeSelector = new CollectionSelectionCriteria(null, null);
072: filterSelector = new CollectionSelectionCriteria(null, null);
073: summarizer = new GraphSummarizer(scopeSelector, filterSelector);
074: }
075:
076: public void testConfirmedPackage2ConfirmedPackage() {
077: a.addDependency(b);
078: b.addDependency(c);
079:
080: factory.createPackage("a", true);
081: factory.createPackage("b", true);
082: factory.createPackage("c", true);
083:
084: b.accept(summarizer);
085:
086: assertTrue(summarizer.getFilterFactory().getPackages().get("a")
087: .isConfirmed());
088: assertNull(summarizer.getFilterFactory().getClasses()
089: .get("a.A"));
090: assertNull(summarizer.getFilterFactory().getFeatures().get(
091: "a.A.a"));
092: assertTrue(summarizer.getScopeFactory().getPackages().get("b")
093: .isConfirmed());
094: assertFalse(summarizer.getScopeFactory().getClasses()
095: .get("b.B").isConfirmed());
096: assertFalse(summarizer.getScopeFactory().getFeatures().get(
097: "b.B.b").isConfirmed());
098: assertTrue(summarizer.getFilterFactory().getPackages().get("c")
099: .isConfirmed());
100: assertNull(summarizer.getFilterFactory().getClasses()
101: .get("c.C"));
102: assertNull(summarizer.getFilterFactory().getFeatures().get(
103: "c.C.c"));
104: }
105:
106: public void testUnconfirmedPackage2UnconfirmedPackage() {
107: a.addDependency(b);
108: b.addDependency(c);
109:
110: b.accept(summarizer);
111:
112: assertFalse(summarizer.getFilterFactory().getPackages()
113: .get("a").isConfirmed());
114: assertNull(summarizer.getFilterFactory().getClasses()
115: .get("a.A"));
116: assertNull(summarizer.getFilterFactory().getFeatures().get(
117: "a.A.a"));
118: assertFalse(summarizer.getScopeFactory().getPackages().get("b")
119: .isConfirmed());
120: assertFalse(summarizer.getScopeFactory().getClasses()
121: .get("b.B").isConfirmed());
122: assertFalse(summarizer.getScopeFactory().getFeatures().get(
123: "b.B.b").isConfirmed());
124: assertFalse(summarizer.getFilterFactory().getPackages()
125: .get("c").isConfirmed());
126: assertNull(summarizer.getFilterFactory().getClasses()
127: .get("c.C"));
128: assertNull(summarizer.getFilterFactory().getFeatures().get(
129: "c.C.c"));
130: }
131:
132: public void testConfirmedClass2ConfirmedClass() {
133: a_A.addDependency(b_B);
134: b_B.addDependency(c_C);
135:
136: factory.createClass("a.A", true);
137: factory.createClass("b.B", true);
138: factory.createClass("c.C", true);
139:
140: b.accept(summarizer);
141:
142: assertTrue(summarizer.getFilterFactory().getPackages().get("a")
143: .isConfirmed());
144: assertTrue(summarizer.getFilterFactory().getClasses()
145: .get("a.A").isConfirmed());
146: assertNull(summarizer.getFilterFactory().getFeatures().get(
147: "a.A.a"));
148: assertTrue(summarizer.getScopeFactory().getPackages().get("b")
149: .isConfirmed());
150: assertTrue(summarizer.getScopeFactory().getClasses().get("b.B")
151: .isConfirmed());
152: assertFalse(summarizer.getScopeFactory().getFeatures().get(
153: "b.B.b").isConfirmed());
154: assertTrue(summarizer.getFilterFactory().getPackages().get("c")
155: .isConfirmed());
156: assertTrue(summarizer.getFilterFactory().getClasses()
157: .get("c.C").isConfirmed());
158: assertNull(summarizer.getFilterFactory().getFeatures().get(
159: "c.C.c"));
160: }
161:
162: public void testUnconfirmedClass2UnconfirmedClass() {
163: a_A.addDependency(b_B);
164: b_B.addDependency(c_C);
165:
166: b.accept(summarizer);
167:
168: assertFalse(summarizer.getFilterFactory().getPackages()
169: .get("a").isConfirmed());
170: assertFalse(summarizer.getFilterFactory().getClasses().get(
171: "a.A").isConfirmed());
172: assertNull(summarizer.getFilterFactory().getFeatures().get(
173: "a.A.a"));
174: assertFalse(summarizer.getScopeFactory().getPackages().get("b")
175: .isConfirmed());
176: assertFalse(summarizer.getScopeFactory().getClasses()
177: .get("b.B").isConfirmed());
178: assertFalse(summarizer.getScopeFactory().getFeatures().get(
179: "b.B.b").isConfirmed());
180: assertFalse(summarizer.getFilterFactory().getPackages()
181: .get("c").isConfirmed());
182: assertFalse(summarizer.getFilterFactory().getClasses().get(
183: "c.C").isConfirmed());
184: assertNull(summarizer.getFilterFactory().getFeatures().get(
185: "c.C.c"));
186: }
187:
188: public void testConfirmedPackage2ConfirmedPackageFromClasses() {
189: scopeSelector.setMatchingPackages(true);
190: scopeSelector.setMatchingClasses(false);
191: scopeSelector.setMatchingFeatures(false);
192: filterSelector.setMatchingPackages(true);
193: filterSelector.setMatchingClasses(false);
194: filterSelector.setMatchingFeatures(false);
195:
196: a_A.addDependency(b_B);
197: b_B.addDependency(c_C);
198:
199: factory.createClass("a.A", true);
200: factory.createClass("b.B", true);
201: factory.createClass("c.C", true);
202:
203: b.accept(summarizer);
204:
205: assertTrue(summarizer.getFilterFactory().getPackages().get("a")
206: .isConfirmed());
207: assertNull(summarizer.getFilterFactory().getClasses()
208: .get("a.A"));
209: assertNull(summarizer.getFilterFactory().getFeatures().get(
210: "a.A.a"));
211: assertTrue(summarizer.getScopeFactory().getPackages().get("b")
212: .isConfirmed());
213: assertNull(summarizer.getScopeFactory().getClasses().get("b.B"));
214: assertNull(summarizer.getScopeFactory().getFeatures().get(
215: "b.B.b"));
216: assertTrue(summarizer.getFilterFactory().getPackages().get("c")
217: .isConfirmed());
218: assertNull(summarizer.getFilterFactory().getClasses()
219: .get("c.C"));
220: assertNull(summarizer.getFilterFactory().getFeatures().get(
221: "c.C.c"));
222: }
223:
224: public void testUnconfirmedPackage2UnconfirmedPackageFromClasses() {
225: scopeSelector.setMatchingPackages(true);
226: scopeSelector.setMatchingClasses(false);
227: scopeSelector.setMatchingFeatures(false);
228: filterSelector.setMatchingPackages(true);
229: filterSelector.setMatchingClasses(false);
230: filterSelector.setMatchingFeatures(false);
231:
232: a_A.addDependency(b_B);
233: b_B.addDependency(c_C);
234:
235: b.accept(summarizer);
236:
237: assertFalse(summarizer.getFilterFactory().getPackages()
238: .get("a").isConfirmed());
239: assertNull(summarizer.getFilterFactory().getClasses()
240: .get("a.A"));
241: assertNull(summarizer.getFilterFactory().getFeatures().get(
242: "a.A.a"));
243: assertFalse(summarizer.getScopeFactory().getPackages().get("b")
244: .isConfirmed());
245: assertNull(summarizer.getScopeFactory().getClasses().get("b.B"));
246: assertNull(summarizer.getScopeFactory().getFeatures().get(
247: "b.B.b"));
248: assertFalse(summarizer.getFilterFactory().getPackages()
249: .get("c").isConfirmed());
250: assertNull(summarizer.getFilterFactory().getClasses()
251: .get("c.C"));
252: assertNull(summarizer.getFilterFactory().getFeatures().get(
253: "c.C.c"));
254: }
255:
256: public void testConfirmedFeature2ConfirmedFeature() {
257: a_A_a.addDependency(b_B_b);
258: b_B_b.addDependency(c_C_c);
259:
260: factory.createFeature("a.A.a", true);
261: factory.createFeature("b.B.b", true);
262: factory.createFeature("c.C.c", true);
263:
264: b.accept(summarizer);
265:
266: assertTrue(summarizer.getFilterFactory().createPackage("a")
267: .isConfirmed());
268: assertTrue(summarizer.getFilterFactory().createClass("a.A")
269: .isConfirmed());
270: assertTrue(summarizer.getFilterFactory().createFeature("a.A.a")
271: .isConfirmed());
272: assertTrue(summarizer.getScopeFactory().createPackage("b")
273: .isConfirmed());
274: assertTrue(summarizer.getScopeFactory().createClass("b.B")
275: .isConfirmed());
276: assertTrue(summarizer.getScopeFactory().createFeature("b.B.b")
277: .isConfirmed());
278: assertTrue(summarizer.getFilterFactory().createPackage("c")
279: .isConfirmed());
280: assertTrue(summarizer.getFilterFactory().createClass("c.C")
281: .isConfirmed());
282: assertTrue(summarizer.getFilterFactory().createFeature("c.C.c")
283: .isConfirmed());
284: }
285:
286: public void testUnconfirmedFeature2UnconfirmedFeature() {
287: a_A_a.addDependency(b_B_b);
288: b_B_b.addDependency(c_C_c);
289:
290: b.accept(summarizer);
291:
292: assertFalse(summarizer.getFilterFactory().createPackage("a")
293: .isConfirmed());
294: assertFalse(summarizer.getFilterFactory().createClass("a.A")
295: .isConfirmed());
296: assertFalse(summarizer.getFilterFactory()
297: .createFeature("a.A.a").isConfirmed());
298: assertFalse(summarizer.getScopeFactory().createPackage("b")
299: .isConfirmed());
300: assertFalse(summarizer.getScopeFactory().createClass("b.B")
301: .isConfirmed());
302: assertFalse(summarizer.getScopeFactory().createFeature("b.B.b")
303: .isConfirmed());
304: assertFalse(summarizer.getFilterFactory().createPackage("c")
305: .isConfirmed());
306: assertFalse(summarizer.getFilterFactory().createClass("c.C")
307: .isConfirmed());
308: assertFalse(summarizer.getFilterFactory()
309: .createFeature("c.C.c").isConfirmed());
310: }
311:
312: public void testConfirmedClass2ConfirmedClassFromFeature() {
313: scopeSelector.setMatchingPackages(false);
314: scopeSelector.setMatchingClasses(true);
315: scopeSelector.setMatchingFeatures(false);
316: filterSelector.setMatchingPackages(false);
317: filterSelector.setMatchingClasses(true);
318: filterSelector.setMatchingFeatures(false);
319:
320: a_A_a.addDependency(b_B_b);
321: b_B_b.addDependency(c_C_c);
322:
323: factory.createFeature("a.A.a", true);
324: factory.createFeature("b.B.b", true);
325: factory.createFeature("c.C.c", true);
326:
327: b.accept(summarizer);
328:
329: assertTrue(summarizer.getFilterFactory().getPackages().get("a")
330: .isConfirmed());
331: assertTrue(summarizer.getFilterFactory().getClasses()
332: .get("a.A").isConfirmed());
333: assertNull(summarizer.getFilterFactory().getFeatures().get(
334: "a.A.a"));
335: assertTrue(summarizer.getScopeFactory().getPackages().get("b")
336: .isConfirmed());
337: assertTrue(summarizer.getScopeFactory().getClasses().get("b.B")
338: .isConfirmed());
339: assertNull(summarizer.getScopeFactory().getFeatures().get(
340: "b.B.b"));
341: assertTrue(summarizer.getFilterFactory().getPackages().get("c")
342: .isConfirmed());
343: assertTrue(summarizer.getFilterFactory().getClasses()
344: .get("c.C").isConfirmed());
345: assertNull(summarizer.getFilterFactory().getFeatures().get(
346: "c.C.c"));
347: }
348:
349: public void testUnconfirmedClass2UnconfirmedClassFromFeature() {
350: scopeSelector.setMatchingPackages(false);
351: scopeSelector.setMatchingClasses(true);
352: scopeSelector.setMatchingFeatures(false);
353: filterSelector.setMatchingPackages(false);
354: filterSelector.setMatchingClasses(true);
355: filterSelector.setMatchingFeatures(false);
356:
357: a_A_a.addDependency(b_B_b);
358: b_B_b.addDependency(c_C_c);
359:
360: b.accept(summarizer);
361:
362: assertFalse(summarizer.getFilterFactory().getPackages()
363: .get("a").isConfirmed());
364: assertFalse(summarizer.getFilterFactory().getClasses().get(
365: "a.A").isConfirmed());
366: assertNull(summarizer.getFilterFactory().getFeatures().get(
367: "a.A.a"));
368: assertFalse(summarizer.getScopeFactory().getPackages().get("b")
369: .isConfirmed());
370: assertFalse(summarizer.getScopeFactory().getClasses()
371: .get("b.B").isConfirmed());
372: assertNull(summarizer.getScopeFactory().getFeatures().get(
373: "b.B.b"));
374: assertFalse(summarizer.getFilterFactory().getPackages()
375: .get("c").isConfirmed());
376: assertFalse(summarizer.getFilterFactory().getClasses().get(
377: "c.C").isConfirmed());
378: assertNull(summarizer.getFilterFactory().getFeatures().get(
379: "c.C.c"));
380: }
381:
382: public void testConfirmedPackage2ConfirmedPackageFromFeature() {
383: scopeSelector.setMatchingPackages(true);
384: scopeSelector.setMatchingClasses(false);
385: scopeSelector.setMatchingFeatures(false);
386: filterSelector.setMatchingPackages(true);
387: filterSelector.setMatchingClasses(false);
388: filterSelector.setMatchingFeatures(false);
389:
390: a_A_a.addDependency(b_B_b);
391: b_B_b.addDependency(c_C_c);
392:
393: factory.createFeature("a.A.a", true);
394: factory.createFeature("b.B.b", true);
395: factory.createFeature("c.C.c", true);
396:
397: b.accept(summarizer);
398:
399: assertTrue(summarizer.getFilterFactory().getPackages().get("a")
400: .isConfirmed());
401: assertNull(summarizer.getFilterFactory().getClasses()
402: .get("a.A"));
403: assertNull(summarizer.getFilterFactory().getFeatures().get(
404: "a.A.a"));
405: assertTrue(summarizer.getScopeFactory().getPackages().get("b")
406: .isConfirmed());
407: assertNull(summarizer.getScopeFactory().getClasses().get("b.B"));
408: assertNull(summarizer.getScopeFactory().getFeatures().get(
409: "b.B.b"));
410: assertTrue(summarizer.getFilterFactory().getPackages().get("c")
411: .isConfirmed());
412: assertNull(summarizer.getFilterFactory().getClasses()
413: .get("c.C"));
414: assertNull(summarizer.getFilterFactory().getFeatures().get(
415: "c.C.c"));
416: }
417:
418: public void testUnconfirmedPackage2UnconfirmedPackageFromFeature() {
419: scopeSelector.setMatchingPackages(true);
420: scopeSelector.setMatchingClasses(false);
421: scopeSelector.setMatchingFeatures(false);
422: filterSelector.setMatchingPackages(true);
423: filterSelector.setMatchingClasses(false);
424: filterSelector.setMatchingFeatures(false);
425:
426: a_A_a.addDependency(b_B_b);
427: b_B_b.addDependency(c_C_c);
428:
429: b.accept(summarizer);
430:
431: assertFalse(summarizer.getFilterFactory().getPackages()
432: .get("a").isConfirmed());
433: assertNull(summarizer.getFilterFactory().getClasses()
434: .get("a.A"));
435: assertNull(summarizer.getFilterFactory().getFeatures().get(
436: "a.A.a"));
437: assertFalse(summarizer.getScopeFactory().getPackages().get("b")
438: .isConfirmed());
439: assertNull(summarizer.getScopeFactory().getClasses().get("b.B"));
440: assertNull(summarizer.getScopeFactory().getFeatures().get(
441: "b.B.b"));
442: assertFalse(summarizer.getFilterFactory().getPackages()
443: .get("c").isConfirmed());
444: assertNull(summarizer.getFilterFactory().getClasses()
445: .get("c.C"));
446: assertNull(summarizer.getFilterFactory().getFeatures().get(
447: "c.C.c"));
448: }
449:
450: public void testUnconfirmedFeatureInConfirmedClass2UnconfirmedFeature() {
451: scopeSelector.setMatchingPackages(false);
452: scopeSelector.setMatchingClasses(false);
453: scopeSelector.setMatchingFeatures(true);
454: filterSelector.setMatchingPackages(false);
455: filterSelector.setMatchingClasses(false);
456: filterSelector.setMatchingFeatures(true);
457:
458: a_A_a.addDependency(b_B_b);
459: b_B_b.addDependency(c_C_c);
460:
461: factory.createClass("a.A", true);
462: factory.createClass("b.B", true);
463: factory.createClass("c.C", true);
464:
465: b.accept(summarizer);
466:
467: assertTrue(summarizer.getFilterFactory().createPackage("a")
468: .isConfirmed());
469: assertTrue(summarizer.getFilterFactory().createClass("a.A")
470: .isConfirmed());
471: assertFalse(summarizer.getFilterFactory()
472: .createFeature("a.A.a").isConfirmed());
473: assertTrue(summarizer.getScopeFactory().createPackage("b")
474: .isConfirmed());
475: assertTrue(summarizer.getScopeFactory().createClass("b.B")
476: .isConfirmed());
477: assertFalse(summarizer.getScopeFactory().createFeature("b.B.b")
478: .isConfirmed());
479: assertTrue(summarizer.getFilterFactory().createPackage("c")
480: .isConfirmed());
481: assertTrue(summarizer.getFilterFactory().createClass("c.C")
482: .isConfirmed());
483: assertFalse(summarizer.getFilterFactory()
484: .createFeature("c.C.c").isConfirmed());
485: }
486: }
|