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 junit.framework.*;
036:
037: public class TestGraphCopierWithConfirmed extends TestCase {
038: private NodeFactory factory;
039:
040: private Node a;
041: private Node a_A;
042: private Node a_A_a;
043:
044: private Node b;
045: private Node b_B;
046: private Node b_B_b;
047:
048: private Node c;
049: private Node c_C;
050: private Node c_C_c;
051:
052: private GraphCopier copier;
053:
054: protected void setUp() throws Exception {
055: factory = new NodeFactory();
056:
057: a = factory.createPackage("a");
058: a_A = factory.createClass("a.A");
059: a_A_a = factory.createFeature("a.A.a");
060:
061: b = factory.createPackage("b");
062: b_B = factory.createClass("b.B");
063: b_B_b = factory.createFeature("b.B.b");
064:
065: c = factory.createPackage("c");
066: c_C = factory.createClass("c.C");
067: c_C_c = factory.createFeature("c.C.c");
068:
069: copier = new GraphCopier(new SelectiveTraversalStrategy());
070: }
071:
072: public void testConfirmedPackage2ConfirmedPackage() {
073: a.addDependency(b);
074: b.addDependency(c);
075:
076: factory.createPackage("a", true);
077: factory.createPackage("b", true);
078: factory.createPackage("c", true);
079:
080: b.accept(copier);
081:
082: assertTrue(copier.getFilterFactory().getPackages().get("a")
083: .isConfirmed());
084: assertNull(copier.getFilterFactory().getClasses().get("a.A"));
085: assertNull(copier.getFilterFactory().getFeatures().get("a.A.a"));
086: assertTrue(copier.getScopeFactory().getPackages().get("b")
087: .isConfirmed());
088: assertFalse(copier.getScopeFactory().getClasses().get("b.B")
089: .isConfirmed());
090: assertFalse(copier.getScopeFactory().getFeatures().get("b.B.b")
091: .isConfirmed());
092: assertTrue(copier.getFilterFactory().getPackages().get("c")
093: .isConfirmed());
094: assertNull(copier.getFilterFactory().getClasses().get("c.C"));
095: assertNull(copier.getFilterFactory().getFeatures().get("c.C.c"));
096: }
097:
098: public void testUnconfirmedPackage2UnconfirmedPackage() {
099: a.addDependency(b);
100: b.addDependency(c);
101:
102: b.accept(copier);
103:
104: assertFalse(copier.getFilterFactory().getPackages().get("a")
105: .isConfirmed());
106: assertNull(copier.getFilterFactory().getClasses().get("a.A"));
107: assertNull(copier.getFilterFactory().getFeatures().get("a.A.a"));
108: assertFalse(copier.getScopeFactory().getPackages().get("b")
109: .isConfirmed());
110: assertFalse(copier.getScopeFactory().getClasses().get("b.B")
111: .isConfirmed());
112: assertFalse(copier.getScopeFactory().getFeatures().get("b.B.b")
113: .isConfirmed());
114: assertFalse(copier.getFilterFactory().getPackages().get("c")
115: .isConfirmed());
116: assertNull(copier.getFilterFactory().getClasses().get("c.C"));
117: assertNull(copier.getFilterFactory().getFeatures().get("c.C.c"));
118: }
119:
120: public void testConfirmedClass2ConfirmedClass() {
121: a_A.addDependency(b_B);
122: b_B.addDependency(c_C);
123:
124: factory.createClass("a.A", true);
125: factory.createClass("b.B", true);
126: factory.createClass("c.C", true);
127:
128: b.accept(copier);
129:
130: assertTrue(copier.getFilterFactory().getPackages().get("a")
131: .isConfirmed());
132: assertTrue(copier.getFilterFactory().getClasses().get("a.A")
133: .isConfirmed());
134: assertNull(copier.getFilterFactory().getFeatures().get("a.A.a"));
135: assertTrue(copier.getScopeFactory().getPackages().get("b")
136: .isConfirmed());
137: assertTrue(copier.getScopeFactory().getClasses().get("b.B")
138: .isConfirmed());
139: assertFalse(copier.getScopeFactory().getFeatures().get("b.B.b")
140: .isConfirmed());
141: assertTrue(copier.getFilterFactory().getPackages().get("c")
142: .isConfirmed());
143: assertTrue(copier.getFilterFactory().getClasses().get("c.C")
144: .isConfirmed());
145: assertNull(copier.getFilterFactory().getFeatures().get("c.C.c"));
146: }
147:
148: public void testUnconfirmedClass2UnconfirmedClass() {
149: a_A.addDependency(b_B);
150: b_B.addDependency(c_C);
151:
152: b.accept(copier);
153:
154: assertFalse(copier.getFilterFactory().getPackages().get("a")
155: .isConfirmed());
156: assertFalse(copier.getFilterFactory().getClasses().get("a.A")
157: .isConfirmed());
158: assertNull(copier.getFilterFactory().getFeatures().get("a.A.a"));
159: assertFalse(copier.getScopeFactory().getPackages().get("b")
160: .isConfirmed());
161: assertFalse(copier.getScopeFactory().getClasses().get("b.B")
162: .isConfirmed());
163: assertFalse(copier.getScopeFactory().getFeatures().get("b.B.b")
164: .isConfirmed());
165: assertFalse(copier.getFilterFactory().getPackages().get("c")
166: .isConfirmed());
167: assertFalse(copier.getFilterFactory().getClasses().get("c.C")
168: .isConfirmed());
169: assertNull(copier.getFilterFactory().getFeatures().get("c.C.c"));
170: }
171:
172: public void testConfirmedFeature2ConfirmedFeature() {
173: a_A_a.addDependency(b_B_b);
174: b_B_b.addDependency(c_C_c);
175:
176: factory.createFeature("a.A.a", true);
177: factory.createFeature("b.B.b", true);
178: factory.createFeature("c.C.c", true);
179:
180: b.accept(copier);
181:
182: assertTrue(copier.getFilterFactory().createPackage("a")
183: .isConfirmed());
184: assertTrue(copier.getFilterFactory().createClass("a.A")
185: .isConfirmed());
186: assertTrue(copier.getFilterFactory().createFeature("a.A.a")
187: .isConfirmed());
188: assertTrue(copier.getScopeFactory().createPackage("b")
189: .isConfirmed());
190: assertTrue(copier.getScopeFactory().createClass("b.B")
191: .isConfirmed());
192: assertTrue(copier.getScopeFactory().createFeature("b.B.b")
193: .isConfirmed());
194: assertTrue(copier.getFilterFactory().createPackage("c")
195: .isConfirmed());
196: assertTrue(copier.getFilterFactory().createClass("c.C")
197: .isConfirmed());
198: assertTrue(copier.getFilterFactory().createFeature("c.C.c")
199: .isConfirmed());
200: }
201:
202: public void testUnconfirmedFeature2UnconfirmedFeature() {
203: a_A_a.addDependency(b_B_b);
204: b_B_b.addDependency(c_C_c);
205:
206: b.accept(copier);
207:
208: assertFalse(copier.getFilterFactory().createPackage("a")
209: .isConfirmed());
210: assertFalse(copier.getFilterFactory().createClass("a.A")
211: .isConfirmed());
212: assertFalse(copier.getFilterFactory().createFeature("a.A.a")
213: .isConfirmed());
214: assertFalse(copier.getScopeFactory().createPackage("b")
215: .isConfirmed());
216: assertFalse(copier.getScopeFactory().createClass("b.B")
217: .isConfirmed());
218: assertFalse(copier.getScopeFactory().createFeature("b.B.b")
219: .isConfirmed());
220: assertFalse(copier.getFilterFactory().createPackage("c")
221: .isConfirmed());
222: assertFalse(copier.getFilterFactory().createClass("c.C")
223: .isConfirmed());
224: assertFalse(copier.getFilterFactory().createFeature("c.C.c")
225: .isConfirmed());
226: }
227:
228: public void testUnconfirmedFeatureInConfirmedClass2UnconfirmedFeature() {
229: a_A_a.addDependency(b_B_b);
230: b_B_b.addDependency(c_C_c);
231:
232: factory.createClass("a.A", true);
233: factory.createClass("b.B", true);
234: factory.createClass("c.C", true);
235:
236: b.accept(copier);
237:
238: assertTrue(copier.getFilterFactory().createPackage("a")
239: .isConfirmed());
240: assertTrue(copier.getFilterFactory().createClass("a.A")
241: .isConfirmed());
242: assertFalse(copier.getFilterFactory().createFeature("a.A.a")
243: .isConfirmed());
244: assertTrue(copier.getScopeFactory().createPackage("b")
245: .isConfirmed());
246: assertTrue(copier.getScopeFactory().createClass("b.B")
247: .isConfirmed());
248: assertFalse(copier.getScopeFactory().createFeature("b.B.b")
249: .isConfirmed());
250: assertTrue(copier.getFilterFactory().createPackage("c")
251: .isConfirmed());
252: assertTrue(copier.getFilterFactory().createClass("c.C")
253: .isConfirmed());
254: assertFalse(copier.getFilterFactory().createFeature("c.C.c")
255: .isConfirmed());
256: }
257: }
|