KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jeantessier > dependency > TestGraphSummarizerWithConfirmed


1 /*
2  * Copyright (c) 2001-2005, Jean Tessier
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Jean Tessier nor the names of his contributors
17  * may be used to endorse or promote products derived from this software
18  * without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */

32
33 package com.jeantessier.dependency;
34
35 import java.io.*;
36 import java.util.*;
37
38 import junit.framework.*;
39
40 public class TestGraphSummarizerWithConfirmed extends TestCase {
41     private NodeFactory factory;
42     
43     private Node a;
44     private Node a_A;
45     private Node a_A_a;
46     
47     private Node b;
48     private Node b_B;
49     private Node b_B_b;
50     
51     private Node c;
52     private Node c_C;
53     private Node c_C_c;
54
55     private CollectionSelectionCriteria scopeSelector;
56     private CollectionSelectionCriteria filterSelector;
57     private GraphSummarizer summarizer;
58
59     protected void setUp() throws Exception JavaDoc {
60         factory = new NodeFactory();
61
62         a = factory.createPackage("a");
63         a_A = factory.createClass("a.A");
64         a_A_a = factory.createFeature("a.A.a");
65         
66         b = factory.createPackage("b");
67         b_B = factory.createClass("b.B");
68         b_B_b = factory.createFeature("b.B.b");
69         
70         c = factory.createPackage("c");
71         c_C = factory.createClass("c.C");
72         c_C_c = factory.createFeature("c.C.c");
73
74         scopeSelector = new CollectionSelectionCriteria(null, null);
75         filterSelector = new CollectionSelectionCriteria(null, null);
76         summarizer = new GraphSummarizer(scopeSelector, filterSelector);
77     }
78
79     public void testConfirmedPackage2ConfirmedPackage() {
80         a.addDependency(b);
81         b.addDependency(c);
82
83         factory.createPackage("a", true);
84         factory.createPackage("b", true);
85         factory.createPackage("c", true);
86         
87         b.accept(summarizer);
88
89         assertTrue(((Node) summarizer.getFilterFactory().getPackages().get("a")).isConfirmed());
90         assertNull(summarizer.getFilterFactory().getClasses().get("a.A"));
91         assertNull(summarizer.getFilterFactory().getFeatures().get("a.A.a"));
92         assertTrue(((Node) summarizer.getScopeFactory().getPackages().get("b")).isConfirmed());
93         assertFalse(((Node) summarizer.getScopeFactory().getClasses().get("b.B")).isConfirmed());
94         assertFalse(((Node) summarizer.getScopeFactory().getFeatures().get("b.B.b")).isConfirmed());
95         assertTrue(((Node) summarizer.getFilterFactory().getPackages().get("c")).isConfirmed());
96         assertNull(summarizer.getFilterFactory().getClasses().get("c.C"));
97         assertNull(summarizer.getFilterFactory().getFeatures().get("c.C.c"));
98     }
99
100     public void testUnconfirmedPackage2UnconfirmedPackage() {
101         a.addDependency(b);
102         b.addDependency(c);
103
104         b.accept(summarizer);
105
106         assertFalse(((Node) summarizer.getFilterFactory().getPackages().get("a")).isConfirmed());
107         assertNull(summarizer.getFilterFactory().getClasses().get("a.A"));
108         assertNull(summarizer.getFilterFactory().getFeatures().get("a.A.a"));
109         assertFalse(((Node) summarizer.getScopeFactory().getPackages().get("b")).isConfirmed());
110         assertFalse(((Node) summarizer.getScopeFactory().getClasses().get("b.B")).isConfirmed());
111         assertFalse(((Node) summarizer.getScopeFactory().getFeatures().get("b.B.b")).isConfirmed());
112         assertFalse(((Node) summarizer.getFilterFactory().getPackages().get("c")).isConfirmed());
113         assertNull(summarizer.getFilterFactory().getClasses().get("c.C"));
114         assertNull(summarizer.getFilterFactory().getFeatures().get("c.C.c"));
115     }
116
117     public void testConfirmedClass2ConfirmedClass() {
118         a_A.addDependency(b_B);
119         b_B.addDependency(c_C);
120
121         factory.createClass("a.A", true);
122         factory.createClass("b.B", true);
123         factory.createClass("c.C", true);
124         
125         b.accept(summarizer);
126
127         assertTrue(((Node) summarizer.getFilterFactory().getPackages().get("a")).isConfirmed());
128         assertTrue(((Node) summarizer.getFilterFactory().getClasses().get("a.A")).isConfirmed());
129         assertNull(summarizer.getFilterFactory().getFeatures().get("a.A.a"));
130         assertTrue(((Node) summarizer.getScopeFactory().getPackages().get("b")).isConfirmed());
131         assertTrue(((Node) summarizer.getScopeFactory().getClasses().get("b.B")).isConfirmed());
132         assertFalse(((Node) summarizer.getScopeFactory().getFeatures().get("b.B.b")).isConfirmed());
133         assertTrue(((Node) summarizer.getFilterFactory().getPackages().get("c")).isConfirmed());
134         assertTrue(((Node) summarizer.getFilterFactory().getClasses().get("c.C")).isConfirmed());
135         assertNull(summarizer.getFilterFactory().getFeatures().get("c.C.c"));
136     }
137
138     public void testUnconfirmedClass2UnconfirmedClass() {
139         a_A.addDependency(b_B);
140         b_B.addDependency(c_C);
141
142         b.accept(summarizer);
143
144         assertFalse(((Node) summarizer.getFilterFactory().getPackages().get("a")).isConfirmed());
145         assertFalse(((Node) summarizer.getFilterFactory().getClasses().get("a.A")).isConfirmed());
146         assertNull(summarizer.getFilterFactory().getFeatures().get("a.A.a"));
147         assertFalse(((Node) summarizer.getScopeFactory().getPackages().get("b")).isConfirmed());
148         assertFalse(((Node) summarizer.getScopeFactory().getClasses().get("b.B")).isConfirmed());
149         assertFalse(((Node) summarizer.getScopeFactory().getFeatures().get("b.B.b")).isConfirmed());
150         assertFalse(((Node) summarizer.getFilterFactory().getPackages().get("c")).isConfirmed());
151         assertFalse(((Node) summarizer.getFilterFactory().getClasses().get("c.C")).isConfirmed());
152         assertNull(summarizer.getFilterFactory().getFeatures().get("c.C.c"));
153     }
154
155     public void testConfirmedPackage2ConfirmedPackageFromClasses() {
156         scopeSelector.setMatchingPackages(true);
157         scopeSelector.setMatchingClasses(false);
158         scopeSelector.setMatchingFeatures(false);
159         filterSelector.setMatchingPackages(true);
160         filterSelector.setMatchingClasses(false);
161         filterSelector.setMatchingFeatures(false);
162         
163         a_A.addDependency(b_B);
164         b_B.addDependency(c_C);
165
166         factory.createClass("a.A", true);
167         factory.createClass("b.B", true);
168         factory.createClass("c.C", true);
169         
170         b.accept(summarizer);
171
172         assertTrue(((Node) summarizer.getFilterFactory().getPackages().get("a")).isConfirmed());
173         assertNull(summarizer.getFilterFactory().getClasses().get("a.A"));
174         assertNull(summarizer.getFilterFactory().getFeatures().get("a.A.a"));
175         assertTrue(((Node) summarizer.getScopeFactory().getPackages().get("b")).isConfirmed());
176         assertNull(summarizer.getScopeFactory().getClasses().get("b.B"));
177         assertNull(summarizer.getScopeFactory().getFeatures().get("b.B.b"));
178         assertTrue(((Node) summarizer.getFilterFactory().getPackages().get("c")).isConfirmed());
179         assertNull(summarizer.getFilterFactory().getClasses().get("c.C"));
180         assertNull(summarizer.getFilterFactory().getFeatures().get("c.C.c"));
181     }
182
183     public void testUnconfirmedPackage2UnconfirmedPackageFromClasses() {
184         scopeSelector.setMatchingPackages(true);
185         scopeSelector.setMatchingClasses(false);
186         scopeSelector.setMatchingFeatures(false);
187         filterSelector.setMatchingPackages(true);
188         filterSelector.setMatchingClasses(false);
189         filterSelector.setMatchingFeatures(false);
190         
191         a_A.addDependency(b_B);
192         b_B.addDependency(c_C);
193
194         b.accept(summarizer);
195
196         assertFalse(((Node) summarizer.getFilterFactory().getPackages().get("a")).isConfirmed());
197         assertNull(summarizer.getFilterFactory().getClasses().get("a.A"));
198         assertNull(summarizer.getFilterFactory().getFeatures().get("a.A.a"));
199         assertFalse(((Node) summarizer.getScopeFactory().getPackages().get("b")).isConfirmed());
200         assertNull(summarizer.getScopeFactory().getClasses().get("b.B"));
201         assertNull(summarizer.getScopeFactory().getFeatures().get("b.B.b"));
202         assertFalse(((Node) summarizer.getFilterFactory().getPackages().get("c")).isConfirmed());
203         assertNull(summarizer.getFilterFactory().getClasses().get("c.C"));
204         assertNull(summarizer.getFilterFactory().getFeatures().get("c.C.c"));
205     }
206
207     public void testConfirmedFeature2ConfirmedFeature() {
208         a_A_a.addDependency(b_B_b);
209         b_B_b.addDependency(c_C_c);
210
211         factory.createFeature("a.A.a", true);
212         factory.createFeature("b.B.b", true);
213         factory.createFeature("c.C.c", true);
214         
215         b.accept(summarizer);
216
217         assertTrue(summarizer.getFilterFactory().createPackage("a").isConfirmed());
218         assertTrue(summarizer.getFilterFactory().createClass("a.A").isConfirmed());
219         assertTrue(summarizer.getFilterFactory().createFeature("a.A.a").isConfirmed());
220         assertTrue(summarizer.getScopeFactory().createPackage("b").isConfirmed());
221         assertTrue(summarizer.getScopeFactory().createClass("b.B").isConfirmed());
222         assertTrue(summarizer.getScopeFactory().createFeature("b.B.b").isConfirmed());
223         assertTrue(summarizer.getFilterFactory().createPackage("c").isConfirmed());
224         assertTrue(summarizer.getFilterFactory().createClass("c.C").isConfirmed());
225         assertTrue(summarizer.getFilterFactory().createFeature("c.C.c").isConfirmed());
226     }
227
228     public void testUnconfirmedFeature2UnconfirmedFeature() {
229         a_A_a.addDependency(b_B_b);
230         b_B_b.addDependency(c_C_c);
231
232         b.accept(summarizer);
233
234         assertFalse(summarizer.getFilterFactory().createPackage("a").isConfirmed());
235         assertFalse(summarizer.getFilterFactory().createClass("a.A").isConfirmed());
236         assertFalse(summarizer.getFilterFactory().createFeature("a.A.a").isConfirmed());
237         assertFalse(summarizer.getScopeFactory().createPackage("b").isConfirmed());
238         assertFalse(summarizer.getScopeFactory().createClass("b.B").isConfirmed());
239         assertFalse(summarizer.getScopeFactory().createFeature("b.B.b").isConfirmed());
240         assertFalse(summarizer.getFilterFactory().createPackage("c").isConfirmed());
241         assertFalse(summarizer.getFilterFactory().createClass("c.C").isConfirmed());
242         assertFalse(summarizer.getFilterFactory().createFeature("c.C.c").isConfirmed());
243     }
244
245     public void testConfirmedClass2ConfirmedClassFromFeature() {
246         scopeSelector.setMatchingPackages(false);
247         scopeSelector.setMatchingClasses(true);
248         scopeSelector.setMatchingFeatures(false);
249         filterSelector.setMatchingPackages(false);
250         filterSelector.setMatchingClasses(true);
251         filterSelector.setMatchingFeatures(false);
252         
253         a_A_a.addDependency(b_B_b);
254         b_B_b.addDependency(c_C_c);
255
256         factory.createFeature("a.A.a", true);
257         factory.createFeature("b.B.b", true);
258         factory.createFeature("c.C.c", true);
259         
260         b.accept(summarizer);
261
262         assertTrue(((Node) summarizer.getFilterFactory().getPackages().get("a")).isConfirmed());
263         assertTrue(((Node) summarizer.getFilterFactory().getClasses().get("a.A")).isConfirmed());
264         assertNull(summarizer.getFilterFactory().getFeatures().get("a.A.a"));
265         assertTrue(((Node) summarizer.getScopeFactory().getPackages().get("b")).isConfirmed());
266         assertTrue(((Node) summarizer.getScopeFactory().getClasses().get("b.B")).isConfirmed());
267         assertNull(summarizer.getScopeFactory().getFeatures().get("b.B.b"));
268         assertTrue(((Node) summarizer.getFilterFactory().getPackages().get("c")).isConfirmed());
269         assertTrue(((Node) summarizer.getFilterFactory().getClasses().get("c.C")).isConfirmed());
270         assertNull(summarizer.getFilterFactory().getFeatures().get("c.C.c"));
271     }
272
273     public void testUnconfirmedClass2UnconfirmedClassFromFeature() {
274         scopeSelector.setMatchingPackages(false);
275         scopeSelector.setMatchingClasses(true);
276         scopeSelector.setMatchingFeatures(false);
277         filterSelector.setMatchingPackages(false);
278         filterSelector.setMatchingClasses(true);
279         filterSelector.setMatchingFeatures(false);
280         
281         a_A_a.addDependency(b_B_b);
282         b_B_b.addDependency(c_C_c);
283
284         b.accept(summarizer);
285
286         assertFalse(((Node) summarizer.getFilterFactory().getPackages().get("a")).isConfirmed());
287         assertFalse(((Node) summarizer.getFilterFactory().getClasses().get("a.A")).isConfirmed());
288         assertNull(summarizer.getFilterFactory().getFeatures().get("a.A.a"));
289         assertFalse(((Node) summarizer.getScopeFactory().getPackages().get("b")).isConfirmed());
290         assertFalse(((Node) summarizer.getScopeFactory().getClasses().get("b.B")).isConfirmed());
291         assertNull(summarizer.getScopeFactory().getFeatures().get("b.B.b"));
292         assertFalse(((Node) summarizer.getFilterFactory().getPackages().get("c")).isConfirmed());
293         assertFalse(((Node) summarizer.getFilterFactory().getClasses().get("c.C")).isConfirmed());
294         assertNull(summarizer.getFilterFactory().getFeatures().get("c.C.c"));
295     }
296
297     public void testConfirmedPackage2ConfirmedPackageFromFeature() {
298         scopeSelector.setMatchingPackages(true);
299         scopeSelector.setMatchingClasses(false);
300         scopeSelector.setMatchingFeatures(false);
301         filterSelector.setMatchingPackages(true);
302         filterSelector.setMatchingClasses(false);
303         filterSelector.setMatchingFeatures(false);
304         
305         a_A_a.addDependency(b_B_b);
306         b_B_b.addDependency(c_C_c);
307
308         factory.createFeature("a.A.a", true);
309         factory.createFeature("b.B.b", true);
310         factory.createFeature("c.C.c", true);
311         
312         b.accept(summarizer);
313
314         assertTrue(((Node) summarizer.getFilterFactory().getPackages().get("a")).isConfirmed());
315         assertNull(summarizer.getFilterFactory().getClasses().get("a.A"));
316         assertNull(summarizer.getFilterFactory().getFeatures().get("a.A.a"));
317         assertTrue(((Node) summarizer.getScopeFactory().getPackages().get("b")).isConfirmed());
318         assertNull(summarizer.getScopeFactory().getClasses().get("b.B"));
319         assertNull(summarizer.getScopeFactory().getFeatures().get("b.B.b"));
320         assertTrue(((Node) summarizer.getFilterFactory().getPackages().get("c")).isConfirmed());
321         assertNull(summarizer.getFilterFactory().getClasses().get("c.C"));
322         assertNull(summarizer.getFilterFactory().getFeatures().get("c.C.c"));
323     }
324
325     public void testUnconfirmedPackage2UnconfirmedPackageFromFeature() {
326         scopeSelector.setMatchingPackages(true);
327         scopeSelector.setMatchingClasses(false);
328         scopeSelector.setMatchingFeatures(false);
329         filterSelector.setMatchingPackages(true);
330         filterSelector.setMatchingClasses(false);
331         filterSelector.setMatchingFeatures(false);
332         
333         a_A_a.addDependency(b_B_b);
334         b_B_b.addDependency(c_C_c);
335
336         b.accept(summarizer);
337
338         assertFalse(((Node) summarizer.getFilterFactory().getPackages().get("a")).isConfirmed());
339         assertNull(summarizer.getFilterFactory().getClasses().get("a.A"));
340         assertNull(summarizer.getFilterFactory().getFeatures().get("a.A.a"));
341         assertFalse(((Node) summarizer.getScopeFactory().getPackages().get("b")).isConfirmed());
342         assertNull(summarizer.getScopeFactory().getClasses().get("b.B"));
343         assertNull(summarizer.getScopeFactory().getFeatures().get("b.B.b"));
344         assertFalse(((Node) summarizer.getFilterFactory().getPackages().get("c")).isConfirmed());
345         assertNull(summarizer.getFilterFactory().getClasses().get("c.C"));
346         assertNull(summarizer.getFilterFactory().getFeatures().get("c.C.c"));
347     }
348 }
349
Popular Tags