KickJava   Java API By Example, From Geeks To Geeks.

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


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.util.*;
36
37 import junit.framework.*;
38 import org.apache.log4j.*;
39
40 public class TestTransitiveClosure extends TestCase {
41     private NodeFactory factory;
42     
43     private PackageNode a;
44     private ClassNode a_A;
45     private FeatureNode a_A_a;
46     
47     private PackageNode b;
48     private ClassNode b_B;
49     private FeatureNode b_B_b;
50     
51     private PackageNode c;
52     private ClassNode c_C;
53     private FeatureNode c_C_c;
54
55     private RegularExpressionSelectionCriteria startCriteria;
56     private RegularExpressionSelectionCriteria stopCriteria;
57
58     private TransitiveClosure selector;
59
60     protected void setUp() throws Exception JavaDoc {
61         super.setUp();
62
63         Logger.getLogger(getClass()).debug("Begin " + getName());
64         
65         factory = new NodeFactory();
66
67         a = factory.createPackage("a");
68         a_A = factory.createClass("a.A");
69         a_A_a = factory.createFeature("a.A.a");
70         
71         b = factory.createPackage("b");
72         b_B = factory.createClass("b.B");
73         b_B_b = factory.createFeature("b.B.b");
74         
75         c = factory.createPackage("c");
76         c_C = factory.createClass("c.C");
77         c_C_c = factory.createFeature("c.C.c");
78
79         a_A_a.addDependency(b_B_b);
80         b_B_b.addDependency(c_C_c);
81
82         startCriteria = new RegularExpressionSelectionCriteria();
83         stopCriteria = new RegularExpressionSelectionCriteria();
84         
85         selector = new TransitiveClosure(startCriteria, stopCriteria);
86
87         Logger.getLogger(getClass()).debug("Set up " + getName());
88     }
89     
90     protected void tearDown() throws Exception JavaDoc {
91         Logger.getLogger(getClass()).debug("Tear down " + getName());
92
93         super.tearDown();
94     }
95
96     public void testZeroOutbound() {
97         startCriteria.setGlobalIncludes("/a.A.a/");
98         stopCriteria.setGlobalIncludes("/c.C.c/");
99
100         selector.setMaximumInboundDepth(TransitiveClosure.DO_NOT_FOLLOW);
101         selector.setMaximumOutboundDepth(0);
102         
103         selector.traverseNodes(factory.getPackages().values());
104
105         assertEquals("packages", 1, selector.getFactory().getPackages().size());
106         assertEquals("classes", 1, selector.getFactory().getClasses().size());
107         assertEquals("features", 1, selector.getFactory().getFeatures().size());
108     }
109
110     public void testOneOutbound() {
111         startCriteria.setGlobalIncludes("/a.A.a/");
112         stopCriteria.setGlobalIncludes("/c.C.c/");
113
114         selector.setMaximumInboundDepth(TransitiveClosure.DO_NOT_FOLLOW);
115         selector.setMaximumOutboundDepth(1);
116         
117         selector.traverseNodes(factory.getPackages().values());
118
119         assertEquals("packages", 2, selector.getFactory().getPackages().size());
120         assertEquals("classes", 2, selector.getFactory().getClasses().size());
121         assertEquals("features", 2, selector.getFactory().getFeatures().size());
122     }
123
124     public void testAllOutbound() {
125         startCriteria.setGlobalIncludes("/a.A.a/");
126         stopCriteria.setGlobalIncludes("/c.C.c/");
127
128         selector.setMaximumInboundDepth(TransitiveClosure.DO_NOT_FOLLOW);
129         selector.setMaximumOutboundDepth(TransitiveClosure.UNBOUNDED_DEPTH);
130         
131         selector.traverseNodes(factory.getPackages().values());
132
133         assertEquals("packages", factory.getPackages().size(), selector.getFactory().getPackages().size());
134         assertEquals("classes", factory.getClasses().size(), selector.getFactory().getClasses().size());
135         assertEquals("features", factory.getFeatures().size(), selector.getFactory().getFeatures().size());
136     }
137
138     public void testZeroInbound() {
139         startCriteria.setGlobalIncludes("/c.C.c/");
140         stopCriteria.setGlobalIncludes("/a.A.a/");
141
142         selector.setMaximumInboundDepth(0);
143         selector.setMaximumOutboundDepth(TransitiveClosure.DO_NOT_FOLLOW);
144         
145         selector.traverseNodes(factory.getPackages().values());
146
147         assertEquals("packages", 1, selector.getFactory().getPackages().size());
148         assertEquals("classes", 1, selector.getFactory().getClasses().size());
149         assertEquals("features", 1, selector.getFactory().getFeatures().size());
150     }
151
152     public void testOneInbound() {
153         startCriteria.setGlobalIncludes("/c.C.c/");
154         stopCriteria.setGlobalIncludes("/a.A.a/");
155
156         selector.setMaximumInboundDepth(1);
157         selector.setMaximumOutboundDepth(TransitiveClosure.DO_NOT_FOLLOW);
158         
159         selector.traverseNodes(factory.getPackages().values());
160
161         assertEquals("packages", 2, selector.getFactory().getPackages().size());
162         assertEquals("classes", 2, selector.getFactory().getClasses().size());
163         assertEquals("features", 2, selector.getFactory().getFeatures().size());
164     }
165
166     public void testAllInbound() {
167         startCriteria.setGlobalIncludes("/c.C.c/");
168         stopCriteria.setGlobalIncludes("/a.A.a/");
169
170         selector.setMaximumInboundDepth(TransitiveClosure.UNBOUNDED_DEPTH);
171         selector.setMaximumOutboundDepth(TransitiveClosure.DO_NOT_FOLLOW);
172         
173         selector.traverseNodes(factory.getPackages().values());
174
175         assertEquals("packages", factory.getPackages().size(), selector.getFactory().getPackages().size());
176         assertEquals("classes", factory.getClasses().size(), selector.getFactory().getClasses().size());
177         assertEquals("features", factory.getFeatures().size(), selector.getFactory().getFeatures().size());
178     }
179
180     public void testZeroBothDirections() {
181         startCriteria.setGlobalIncludes("/b.B.b/");
182         stopCriteria.setGlobalIncludes(Collections.EMPTY_LIST);
183
184         selector.setMaximumInboundDepth(0);
185         selector.setMaximumOutboundDepth(0);
186         
187         selector.traverseNodes(factory.getPackages().values());
188
189         assertEquals("packages", 1, selector.getFactory().getPackages().size());
190         assertEquals("classes", 1, selector.getFactory().getClasses().size());
191         assertEquals("features", 1, selector.getFactory().getFeatures().size());
192     }
193
194     public void testOneBothDirections() {
195         startCriteria.setGlobalIncludes("/b.B.b/");
196         stopCriteria.setGlobalIncludes(Collections.EMPTY_LIST);
197
198         selector.setMaximumInboundDepth(1);
199         selector.setMaximumOutboundDepth(1);
200         
201         selector.traverseNodes(factory.getPackages().values());
202
203         assertEquals("packages", factory.getPackages().size(), selector.getFactory().getPackages().size());
204         assertEquals("classes", factory.getClasses().size(), selector.getFactory().getClasses().size());
205         assertEquals("features", factory.getFeatures().size(), selector.getFactory().getFeatures().size());
206     }
207
208     public void testAllBothDirections() {
209         startCriteria.setGlobalIncludes("/b.B.b/");
210         stopCriteria.setGlobalIncludes(Collections.EMPTY_LIST);
211
212         selector.setMaximumInboundDepth(TransitiveClosure.UNBOUNDED_DEPTH);
213         selector.setMaximumOutboundDepth(TransitiveClosure.UNBOUNDED_DEPTH);
214         
215         selector.traverseNodes(factory.getPackages().values());
216
217         assertEquals("packages", factory.getPackages().size(), selector.getFactory().getPackages().size());
218         assertEquals("classes", factory.getClasses().size(), selector.getFactory().getClasses().size());
219         assertEquals("features", factory.getFeatures().size(), selector.getFactory().getFeatures().size());
220     }
221 }
222
Popular Tags