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.io.*;
036: import java.util.*;
037:
038: import junit.framework.*;
039:
040: import org.apache.oro.text.perl.*;
041:
042: public class TestClosureStartSelector extends TestCase {
043: private NodeFactory factory;
044: private NodeFactory localFactory;
045: private RegularExpressionSelectionCriteria localCriteria;
046:
047: private PackageNode a;
048: private ClassNode a_A;
049: private FeatureNode a_A_a;
050:
051: private PackageNode b;
052: private ClassNode b_B;
053: private FeatureNode b_B_b;
054:
055: private PackageNode c;
056: private ClassNode c_C;
057: private FeatureNode c_C_c;
058:
059: protected void setUp() throws Exception {
060: factory = new NodeFactory();
061: localFactory = new NodeFactory();
062: localCriteria = new RegularExpressionSelectionCriteria();
063:
064: a = factory.createPackage("a");
065: a_A = factory.createClass("a.A");
066: a_A_a = factory.createFeature("a.A.a");
067:
068: b = factory.createPackage("b");
069: b_B = factory.createClass("b.B");
070: b_B_b = factory.createFeature("b.B.b");
071:
072: c = factory.createPackage("c");
073: c_C = factory.createClass("c.C");
074: c_C_c = factory.createFeature("c.C.c");
075:
076: a_A_a.addDependency(b_B_b);
077: b_B_b.addDependency(c_C_c);
078: }
079:
080: public void testOneSelectedNode() {
081: localCriteria.setGlobalIncludes("/b.B.b/");
082:
083: ClosureStartSelector selector = new ClosureStartSelector(
084: localFactory, localCriteria);
085: selector.traverseNodes(factory.getPackages().values());
086:
087: assertEquals("nodes in selection", 1, selector
088: .getSelectedNodes().size());
089: assertEquals("b.B.b in selection", b_B_b, selector
090: .getSelectedNodes().iterator().next());
091: assertSame("b.B.b in selection", b_B_b, selector
092: .getSelectedNodes().iterator().next());
093: }
094:
095: public void testOneCopiedNode() {
096: localCriteria.setGlobalIncludes("/b.B.b/");
097:
098: ClosureStartSelector selector = new ClosureStartSelector(
099: localFactory, localCriteria);
100: selector.traverseNodes(factory.getPackages().values());
101:
102: assertEquals("packages in scope", 1, localFactory.getPackages()
103: .size());
104: assertEquals("classes in scope", 1, localFactory.getClasses()
105: .size());
106: assertEquals("features in scope", 1, localFactory.getFeatures()
107: .size());
108:
109: assertEquals("package b in scope", b, localFactory
110: .getPackages().get("b"));
111: assertEquals("class b.B in scope", b_B, localFactory
112: .getClasses().get("b.B"));
113: assertEquals("feature b.B.b in scope", b_B_b, localFactory
114: .getFeatures().get("b.B.b"));
115:
116: assertNotSame("package b in scope", b, localFactory
117: .getPackages().get("b"));
118: assertNotSame("class b.B in scope", b_B, localFactory
119: .getClasses().get("b.B"));
120: assertNotSame("feature b.B.b in scope", b_B_b, localFactory
121: .getFeatures().get("b.B.b"));
122:
123: assertEquals("nodes in selection", 1, selector.getCopiedNodes()
124: .size());
125: assertEquals("b.B.b in selection", b_B_b, selector
126: .getCopiedNodes().iterator().next());
127: assertNotSame("b.B.b in selection", b_B_b, selector
128: .getCopiedNodes().iterator().next());
129: assertSame("b.B.b in selection", localFactory.getFeatures()
130: .get("b.B.b"), selector.getCopiedNodes().iterator()
131: .next());
132: }
133:
134: public void testMultipleSelectedNodes() {
135: localCriteria.setGlobalIncludes("/a.A.a/, /^b/");
136:
137: ClosureStartSelector selector = new ClosureStartSelector(
138: localFactory, localCriteria);
139: selector.traverseNodes(factory.getPackages().values());
140:
141: assertEquals("nodes in selection", 4, selector
142: .getSelectedNodes().size());
143: assertTrue("a.A.a in selection", selector.getSelectedNodes()
144: .contains(a_A_a));
145: assertTrue("b in selection", selector.getSelectedNodes()
146: .contains(b));
147: assertTrue("b.B in selection", selector.getSelectedNodes()
148: .contains(b_B));
149: assertTrue("b.B.b in selection", selector.getSelectedNodes()
150: .contains(b_B_b));
151: }
152:
153: public void testMultipleCopiedNodes() {
154: localCriteria.setGlobalIncludes("/a.A.a/, /^b/");
155:
156: ClosureStartSelector selector = new ClosureStartSelector(
157: localFactory, localCriteria);
158: selector.traverseNodes(factory.getPackages().values());
159:
160: assertEquals("packages in scope", 2, localFactory.getPackages()
161: .size());
162: assertEquals("classes in scope", 2, localFactory.getClasses()
163: .size());
164: assertEquals("features in scope", 2, localFactory.getFeatures()
165: .size());
166:
167: assertEquals("package a in scope", a, localFactory
168: .getPackages().get("a"));
169: assertEquals("class a.A in scope", a_A, localFactory
170: .getClasses().get("a.A"));
171: assertEquals("feature a.A.a in scope", a_A_a, localFactory
172: .getFeatures().get("a.A.a"));
173: assertEquals("package b in scope", b, localFactory
174: .getPackages().get("b"));
175: assertEquals("class b.B in scope", b_B, localFactory
176: .getClasses().get("b.B"));
177: assertEquals("feature b.B.b in scope", b_B_b, localFactory
178: .getFeatures().get("b.B.b"));
179:
180: assertNotSame("package a in scope", a, localFactory
181: .getPackages().get("a"));
182: assertNotSame("class a.A in scope", a_A, localFactory
183: .getClasses().get("a.A"));
184: assertNotSame("feature a.A.a in scope", a_A_a, localFactory
185: .getFeatures().get("a.A.a"));
186: assertNotSame("package b in scope", b, localFactory
187: .getPackages().get("b"));
188: assertNotSame("class b.B in scope", b_B, localFactory
189: .getClasses().get("b.B"));
190: assertNotSame("feature b.B.b in scope", b_B_b, localFactory
191: .getFeatures().get("b.B.b"));
192:
193: assertEquals("nodes in selection", 4, selector.getCopiedNodes()
194: .size());
195: assertTrue("a.A.a in selection", selector.getCopiedNodes()
196: .contains(a_A_a));
197: assertTrue("b in selection", selector.getCopiedNodes()
198: .contains(b));
199: assertTrue("b.B in selection", selector.getCopiedNodes()
200: .contains(b_B));
201: assertTrue("b.B.b in selection", selector.getCopiedNodes()
202: .contains(b_B_b));
203: }
204:
205: public void testVisitInferredPackage() {
206: ClosureStartSelector selector = new ClosureStartSelector(
207: localFactory, new ComprehensiveSelectionCriteria());
208: selector.traverseNodes(Collections.singleton(b));
209:
210: assertEquals("package.isConfirmed()", b.isConfirmed(),
211: ((Node) localFactory.getPackages().get(b.getName()))
212: .isConfirmed());
213: }
214:
215: public void testVisitConfirmedPackage() {
216: b.setConfirmed(true);
217:
218: ClosureStartSelector selector = new ClosureStartSelector(
219: localFactory, new ComprehensiveSelectionCriteria());
220: selector.traverseNodes(Collections.singleton(b));
221:
222: assertEquals("package.isConfirmed()", b.isConfirmed(),
223: ((Node) localFactory.getPackages().get(b.getName()))
224: .isConfirmed());
225: }
226:
227: public void testVisitInferredClass() {
228: ClosureStartSelector selector = new ClosureStartSelector(
229: localFactory, new ComprehensiveSelectionCriteria());
230: selector.traverseNodes(Collections.singleton(b_B));
231:
232: assertEquals("class.isConfirmed()", b_B.isConfirmed(),
233: ((Node) localFactory.getClasses().get(b_B.getName()))
234: .isConfirmed());
235: }
236:
237: public void testVisitConfirmedClass() {
238: b_B.setConfirmed(true);
239:
240: ClosureStartSelector selector = new ClosureStartSelector(
241: localFactory, new ComprehensiveSelectionCriteria());
242: selector.traverseNodes(Collections.singleton(b_B));
243:
244: assertEquals("class.isConfirmed()", b_B.isConfirmed(),
245: ((Node) localFactory.getClasses().get(b_B.getName()))
246: .isConfirmed());
247: }
248:
249: public void testVisitInferredFeature() {
250: ClosureStartSelector selector = new ClosureStartSelector(
251: localFactory, new ComprehensiveSelectionCriteria());
252: selector.traverseNodes(Collections.singleton(b_B_b));
253:
254: assertEquals(
255: "feature.isConfirmed()",
256: b_B_b.isConfirmed(),
257: ((Node) localFactory.getFeatures().get(b_B_b.getName()))
258: .isConfirmed());
259: }
260:
261: public void testVisitConfirmedFeature() {
262: b_B_b.setConfirmed(true);
263:
264: ClosureStartSelector selector = new ClosureStartSelector(
265: localFactory, new ComprehensiveSelectionCriteria());
266: selector.traverseNodes(Collections.singleton(b_B_b));
267:
268: assertEquals(
269: "feature.isConfirmed()",
270: b_B_b.isConfirmed(),
271: ((Node) localFactory.getFeatures().get(b_B_b.getName()))
272: .isConfirmed());
273: }
274: }
|