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: import org.apache.log4j.*;
039:
040: public class TestTransitiveClosure extends TestCase {
041: private NodeFactory factory;
042:
043: private PackageNode a;
044: private ClassNode a_A;
045: private FeatureNode a_A_a;
046:
047: private PackageNode b;
048: private ClassNode b_B;
049: private FeatureNode b_B_b;
050:
051: private PackageNode c;
052: private ClassNode c_C;
053: private FeatureNode c_C_c;
054:
055: private RegularExpressionSelectionCriteria startCriteria;
056: private RegularExpressionSelectionCriteria stopCriteria;
057:
058: private TransitiveClosure selector;
059:
060: protected void setUp() throws Exception {
061: super .setUp();
062:
063: Logger.getLogger(getClass()).debug("Begin " + getName());
064:
065: factory = new NodeFactory();
066:
067: a = factory.createPackage("a");
068: a_A = factory.createClass("a.A");
069: a_A_a = factory.createFeature("a.A.a");
070:
071: b = factory.createPackage("b");
072: b_B = factory.createClass("b.B");
073: b_B_b = factory.createFeature("b.B.b");
074:
075: c = factory.createPackage("c");
076: c_C = factory.createClass("c.C");
077: c_C_c = factory.createFeature("c.C.c");
078:
079: a_A_a.addDependency(b_B_b);
080: b_B_b.addDependency(c_C_c);
081:
082: startCriteria = new RegularExpressionSelectionCriteria();
083: stopCriteria = new RegularExpressionSelectionCriteria();
084:
085: selector = new TransitiveClosure(startCriteria, stopCriteria);
086:
087: Logger.getLogger(getClass()).debug("Set up " + getName());
088: }
089:
090: protected void tearDown() throws Exception {
091: Logger.getLogger(getClass()).debug("Tear down " + getName());
092:
093: super .tearDown();
094: }
095:
096: public void testZeroOutbound() {
097: startCriteria.setGlobalIncludes("/a.A.a/");
098: stopCriteria.setGlobalIncludes("/c.C.c/");
099:
100: selector
101: .setMaximumInboundDepth(TransitiveClosure.DO_NOT_FOLLOW);
102: selector.setMaximumOutboundDepth(0);
103:
104: selector.traverseNodes(factory.getPackages().values());
105:
106: assertEquals("packages", 1, selector.getFactory().getPackages()
107: .size());
108: assertEquals("classes", 1, selector.getFactory().getClasses()
109: .size());
110: assertEquals("features", 1, selector.getFactory().getFeatures()
111: .size());
112: }
113:
114: public void testOneOutbound() {
115: startCriteria.setGlobalIncludes("/a.A.a/");
116: stopCriteria.setGlobalIncludes("/c.C.c/");
117:
118: selector
119: .setMaximumInboundDepth(TransitiveClosure.DO_NOT_FOLLOW);
120: selector.setMaximumOutboundDepth(1);
121:
122: selector.traverseNodes(factory.getPackages().values());
123:
124: assertEquals("packages", 2, selector.getFactory().getPackages()
125: .size());
126: assertEquals("classes", 2, selector.getFactory().getClasses()
127: .size());
128: assertEquals("features", 2, selector.getFactory().getFeatures()
129: .size());
130: }
131:
132: public void testAllOutbound() {
133: startCriteria.setGlobalIncludes("/a.A.a/");
134: stopCriteria.setGlobalIncludes("/c.C.c/");
135:
136: selector
137: .setMaximumInboundDepth(TransitiveClosure.DO_NOT_FOLLOW);
138: selector
139: .setMaximumOutboundDepth(TransitiveClosure.UNBOUNDED_DEPTH);
140:
141: selector.traverseNodes(factory.getPackages().values());
142:
143: assertEquals("packages", factory.getPackages().size(), selector
144: .getFactory().getPackages().size());
145: assertEquals("classes", factory.getClasses().size(), selector
146: .getFactory().getClasses().size());
147: assertEquals("features", factory.getFeatures().size(), selector
148: .getFactory().getFeatures().size());
149: }
150:
151: public void testZeroInbound() {
152: startCriteria.setGlobalIncludes("/c.C.c/");
153: stopCriteria.setGlobalIncludes("/a.A.a/");
154:
155: selector.setMaximumInboundDepth(0);
156: selector
157: .setMaximumOutboundDepth(TransitiveClosure.DO_NOT_FOLLOW);
158:
159: selector.traverseNodes(factory.getPackages().values());
160:
161: assertEquals("packages", 1, selector.getFactory().getPackages()
162: .size());
163: assertEquals("classes", 1, selector.getFactory().getClasses()
164: .size());
165: assertEquals("features", 1, selector.getFactory().getFeatures()
166: .size());
167: }
168:
169: public void testOneInbound() {
170: startCriteria.setGlobalIncludes("/c.C.c/");
171: stopCriteria.setGlobalIncludes("/a.A.a/");
172:
173: selector.setMaximumInboundDepth(1);
174: selector
175: .setMaximumOutboundDepth(TransitiveClosure.DO_NOT_FOLLOW);
176:
177: selector.traverseNodes(factory.getPackages().values());
178:
179: assertEquals("packages", 2, selector.getFactory().getPackages()
180: .size());
181: assertEquals("classes", 2, selector.getFactory().getClasses()
182: .size());
183: assertEquals("features", 2, selector.getFactory().getFeatures()
184: .size());
185: }
186:
187: public void testAllInbound() {
188: startCriteria.setGlobalIncludes("/c.C.c/");
189: stopCriteria.setGlobalIncludes("/a.A.a/");
190:
191: selector
192: .setMaximumInboundDepth(TransitiveClosure.UNBOUNDED_DEPTH);
193: selector
194: .setMaximumOutboundDepth(TransitiveClosure.DO_NOT_FOLLOW);
195:
196: selector.traverseNodes(factory.getPackages().values());
197:
198: assertEquals("packages", factory.getPackages().size(), selector
199: .getFactory().getPackages().size());
200: assertEquals("classes", factory.getClasses().size(), selector
201: .getFactory().getClasses().size());
202: assertEquals("features", factory.getFeatures().size(), selector
203: .getFactory().getFeatures().size());
204: }
205:
206: public void testZeroBothDirections() {
207: startCriteria.setGlobalIncludes("/b.B.b/");
208: stopCriteria.setGlobalIncludes(Collections.EMPTY_LIST);
209:
210: selector.setMaximumInboundDepth(0);
211: selector.setMaximumOutboundDepth(0);
212:
213: selector.traverseNodes(factory.getPackages().values());
214:
215: assertEquals("packages", 1, selector.getFactory().getPackages()
216: .size());
217: assertEquals("classes", 1, selector.getFactory().getClasses()
218: .size());
219: assertEquals("features", 1, selector.getFactory().getFeatures()
220: .size());
221: }
222:
223: public void testOneBothDirections() {
224: startCriteria.setGlobalIncludes("/b.B.b/");
225: stopCriteria.setGlobalIncludes(Collections.EMPTY_LIST);
226:
227: selector.setMaximumInboundDepth(1);
228: selector.setMaximumOutboundDepth(1);
229:
230: selector.traverseNodes(factory.getPackages().values());
231:
232: assertEquals("packages", factory.getPackages().size(), selector
233: .getFactory().getPackages().size());
234: assertEquals("classes", factory.getClasses().size(), selector
235: .getFactory().getClasses().size());
236: assertEquals("features", factory.getFeatures().size(), selector
237: .getFactory().getFeatures().size());
238: }
239:
240: public void testAllBothDirections() {
241: startCriteria.setGlobalIncludes("/b.B.b/");
242: stopCriteria.setGlobalIncludes(Collections.EMPTY_LIST);
243:
244: selector
245: .setMaximumInboundDepth(TransitiveClosure.UNBOUNDED_DEPTH);
246: selector
247: .setMaximumOutboundDepth(TransitiveClosure.UNBOUNDED_DEPTH);
248:
249: selector.traverseNodes(factory.getPackages().values());
250:
251: assertEquals("packages", factory.getPackages().size(), selector
252: .getFactory().getPackages().size());
253: assertEquals("classes", factory.getClasses().size(), selector
254: .getFactory().getClasses().size());
255: assertEquals("features", factory.getFeatures().size(), selector
256: .getFactory().getFeatures().size());
257: }
258: }
|