KickJava   Java API By Example, From Geeks To Geeks.

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


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
39 public class TestTransitiveClosureSlice extends TestCase {
40     private NodeFactory factory;
41     
42     private Node in3;
43     private Node in2;
44     private Node in1;
45     private Node base;
46     private Node out1;
47     private Node out2;
48     private Node out3;
49     
50     private TransitiveClosure selector;
51
52     protected void setUp() throws Exception JavaDoc {
53         factory = new NodeFactory();
54
55         in3 = factory.createPackage("in3");
56         in2 = factory.createPackage("in2");
57         in1 = factory.createPackage("in1");
58         base = factory.createPackage("base");
59         out1 = factory.createPackage("out1");
60         out2 = factory.createPackage("out2");
61         out3 = factory.createPackage("out3");
62
63         in3.addDependency(in2);
64         in2.addDependency(in1);
65         in1.addDependency(base);
66         base.addDependency(out1);
67         out1.addDependency(out2);
68         out2.addDependency(out3);
69         
70         selector = new TransitiveClosure(new RegularExpressionSelectionCriteria(), new NullSelectionCriteria());
71     }
72
73     public void testDefaultDepth() {
74         selector.traverseNodes(Collections.singleton(base));
75
76         assertEquals("number of packages", 4, selector.getFactory().getPackages().size());
77         assertEquals("base.Inbound()", 0, ((Node) selector.getFactory().getPackages().get("base")).getInboundDependencies().size());
78         assertEquals("base.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("base")).getOutboundDependencies().size());
79         assertEquals("out1.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("out1")).getInboundDependencies().size());
80         assertEquals("out1.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("out1")).getOutboundDependencies().size());
81         assertEquals("out2.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("out2")).getInboundDependencies().size());
82         assertEquals("out2.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("out2")).getOutboundDependencies().size());
83         assertEquals("out3.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("out3")).getInboundDependencies().size());
84         assertEquals("out3.Outbound()", 0, ((Node) selector.getFactory().getPackages().get("out3")).getOutboundDependencies().size());
85     }
86
87     public void testUnboundedDepthInboundOutbound() {
88         selector.setMaximumInboundDepth(TransitiveClosure.UNBOUNDED_DEPTH);
89         selector.setMaximumOutboundDepth(TransitiveClosure.UNBOUNDED_DEPTH);
90         
91         selector.traverseNodes(Collections.singleton(base));
92
93         assertEquals("number of packages", 7, selector.getFactory().getPackages().size());
94         assertEquals("in3.Inbound()", 0, ((Node) selector.getFactory().getPackages().get("in3")).getInboundDependencies().size());
95         assertEquals("in3.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("in3")).getOutboundDependencies().size());
96         assertEquals("in2.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("in2")).getInboundDependencies().size());
97         assertEquals("in2.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("in2")).getOutboundDependencies().size());
98         assertEquals("in1.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("in1")).getInboundDependencies().size());
99         assertEquals("in1.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("in1")).getOutboundDependencies().size());
100         assertEquals("base.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("base")).getInboundDependencies().size());
101         assertEquals("base.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("base")).getOutboundDependencies().size());
102         assertEquals("out1.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("out1")).getInboundDependencies().size());
103         assertEquals("out1.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("out1")).getOutboundDependencies().size());
104         assertEquals("out2.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("out2")).getInboundDependencies().size());
105         assertEquals("out2.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("out2")).getOutboundDependencies().size());
106         assertEquals("out3.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("out3")).getInboundDependencies().size());
107         assertEquals("out3.Outbound()", 0, ((Node) selector.getFactory().getPackages().get("out3")).getOutboundDependencies().size());
108     }
109
110     public void testUnboundedDepthInbound() {
111         selector.setMaximumInboundDepth(TransitiveClosure.UNBOUNDED_DEPTH);
112         selector.setMaximumOutboundDepth(TransitiveClosure.DO_NOT_FOLLOW);
113         
114         selector.traverseNodes(Collections.singleton(base));
115
116         assertEquals("number of packages", 4, selector.getFactory().getPackages().size());
117         assertEquals("in3.Inbound()", 0, ((Node) selector.getFactory().getPackages().get("in3")).getInboundDependencies().size());
118         assertEquals("in3.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("in3")).getOutboundDependencies().size());
119         assertEquals("in2.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("in2")).getInboundDependencies().size());
120         assertEquals("in2.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("in2")).getOutboundDependencies().size());
121         assertEquals("in1.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("in1")).getInboundDependencies().size());
122         assertEquals("in1.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("in1")).getOutboundDependencies().size());
123         assertEquals("base.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("base")).getInboundDependencies().size());
124         assertEquals("base.Outbound()", 0, ((Node) selector.getFactory().getPackages().get("base")).getOutboundDependencies().size());
125     }
126
127     public void testUnboundedDepthOutbound() {
128         selector.setMaximumInboundDepth(TransitiveClosure.DO_NOT_FOLLOW);
129         selector.setMaximumOutboundDepth(TransitiveClosure.UNBOUNDED_DEPTH);
130
131         selector.traverseNodes(Collections.singleton(base));
132
133         assertEquals("number of packages", 4, selector.getFactory().getPackages().size());
134         assertEquals("base.Inbound()", 0, ((Node) selector.getFactory().getPackages().get("base")).getInboundDependencies().size());
135         assertEquals("base.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("base")).getOutboundDependencies().size());
136         assertEquals("out1.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("out1")).getInboundDependencies().size());
137         assertEquals("out1.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("out1")).getOutboundDependencies().size());
138         assertEquals("out2.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("out2")).getInboundDependencies().size());
139         assertEquals("out2.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("out2")).getOutboundDependencies().size());
140         assertEquals("out3.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("out3")).getInboundDependencies().size());
141         assertEquals("out3.Outbound()", 0, ((Node) selector.getFactory().getPackages().get("out3")).getOutboundDependencies().size());
142     }
143
144     public void testZeroDepthInboundOutbound() {
145         selector.setMaximumInboundDepth(0);
146         selector.setMaximumOutboundDepth(0);
147         
148         selector.traverseNodes(Collections.singleton(base));
149
150         assertEquals("number of packages", 1, selector.getFactory().getPackages().size());
151         assertEquals("base.Inbound()", 0, ((Node) selector.getFactory().getPackages().get("base")).getInboundDependencies().size());
152         assertEquals("base.Outbound()", 0, ((Node) selector.getFactory().getPackages().get("base")).getOutboundDependencies().size());
153     }
154
155     public void testSingleDepthInboundOutbound() {
156         selector.setMaximumInboundDepth(1);
157         selector.setMaximumOutboundDepth(1);
158         
159         selector.traverseNodes(Collections.singleton(base));
160
161         assertEquals("number of packages", 3, selector.getFactory().getPackages().size());
162         assertEquals("in1.Inbound()", 0, ((Node) selector.getFactory().getPackages().get("in1")).getInboundDependencies().size());
163         assertEquals("in1.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("in1")).getOutboundDependencies().size());
164         assertEquals("base.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("base")).getInboundDependencies().size());
165         assertEquals("base.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("base")).getOutboundDependencies().size());
166         assertEquals("out1.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("out1")).getInboundDependencies().size());
167         assertEquals("out1.Outbound()", 0, ((Node) selector.getFactory().getPackages().get("out1")).getOutboundDependencies().size());
168     }
169
170     public void testDoubleDepthInboundOutbound() {
171         selector.setMaximumInboundDepth(2);
172         selector.setMaximumOutboundDepth(2);
173         
174         selector.traverseNodes(Collections.singleton(base));
175
176         assertEquals("number of packages", 5, selector.getFactory().getPackages().size());
177         assertEquals("in2.Inbound()", 0, ((Node) selector.getFactory().getPackages().get("in2")).getInboundDependencies().size());
178         assertEquals("in2.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("in2")).getOutboundDependencies().size());
179         assertEquals("in1.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("in1")).getInboundDependencies().size());
180         assertEquals("in1.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("in1")).getOutboundDependencies().size());
181         assertEquals("base.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("base")).getInboundDependencies().size());
182         assertEquals("base.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("base")).getOutboundDependencies().size());
183         assertEquals("out1.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("out1")).getInboundDependencies().size());
184         assertEquals("out1.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("out1")).getOutboundDependencies().size());
185         assertEquals("out2.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("out2")).getInboundDependencies().size());
186         assertEquals("out2.Outbound()", 0, ((Node) selector.getFactory().getPackages().get("out2")).getOutboundDependencies().size());
187     }
188
189     public void testExactDepthInboundOutbound() {
190         selector.setMaximumInboundDepth(3);
191         selector.setMaximumOutboundDepth(3);
192         
193         selector.traverseNodes(Collections.singleton(base));
194
195         assertEquals("number of packages", 7, selector.getFactory().getPackages().size());
196         assertEquals("in3.Inbound()", 0, ((Node) selector.getFactory().getPackages().get("in3")).getInboundDependencies().size());
197         assertEquals("in3.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("in3")).getOutboundDependencies().size());
198         assertEquals("in2.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("in2")).getInboundDependencies().size());
199         assertEquals("in2.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("in2")).getOutboundDependencies().size());
200         assertEquals("in1.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("in1")).getInboundDependencies().size());
201         assertEquals("in1.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("in1")).getOutboundDependencies().size());
202         assertEquals("base.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("base")).getInboundDependencies().size());
203         assertEquals("base.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("base")).getOutboundDependencies().size());
204         assertEquals("out1.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("out1")).getInboundDependencies().size());
205         assertEquals("out1.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("out1")).getOutboundDependencies().size());
206         assertEquals("out2.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("out2")).getInboundDependencies().size());
207         assertEquals("out2.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("out2")).getOutboundDependencies().size());
208         assertEquals("out3.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("out3")).getInboundDependencies().size());
209         assertEquals("out3.Outbound()", 0, ((Node) selector.getFactory().getPackages().get("out3")).getOutboundDependencies().size());
210     }
211
212     public void testOverDepthInboundOutbound() {
213         selector.setMaximumInboundDepth(4);
214         selector.setMaximumOutboundDepth(4);
215         
216         selector.traverseNodes(Collections.singleton(base));
217
218         assertEquals("number of packages", 7, selector.getFactory().getPackages().size());
219         assertEquals("in3.Inbound()", 0, ((Node) selector.getFactory().getPackages().get("in3")).getInboundDependencies().size());
220         assertEquals("in3.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("in3")).getOutboundDependencies().size());
221         assertEquals("in2.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("in2")).getInboundDependencies().size());
222         assertEquals("in2.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("in2")).getOutboundDependencies().size());
223         assertEquals("in1.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("in1")).getInboundDependencies().size());
224         assertEquals("in1.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("in1")).getOutboundDependencies().size());
225         assertEquals("base.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("base")).getInboundDependencies().size());
226         assertEquals("base.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("base")).getOutboundDependencies().size());
227         assertEquals("out1.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("out1")).getInboundDependencies().size());
228         assertEquals("out1.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("out1")).getOutboundDependencies().size());
229         assertEquals("out2.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("out2")).getInboundDependencies().size());
230         assertEquals("out2.Outbound()", 1, ((Node) selector.getFactory().getPackages().get("out2")).getOutboundDependencies().size());
231         assertEquals("out3.Inbound()", 1, ((Node) selector.getFactory().getPackages().get("out3")).getInboundDependencies().size());
232         assertEquals("out3.Outbound()", 0, ((Node) selector.getFactory().getPackages().get("out3")).getOutboundDependencies().size());
233     }
234 }
235
Popular Tags