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: import org.apache.log4j.*;
038:
039: public class TestNodeFactory extends TestCase {
040: private NodeFactory factory;
041:
042: protected void setUp() throws Exception {
043: super .setUp();
044:
045: Logger.getLogger(getClass()).debug("Begin " + getName());
046:
047: factory = new NodeFactory();
048: }
049:
050: protected void tearDown() throws Exception {
051: Logger.getLogger(getClass()).debug("End " + getName());
052:
053: super .tearDown();
054: }
055:
056: public void testCreatePackage() {
057: PackageNode node = factory.createPackage("a");
058:
059: assertEquals("name", "a", node.getName());
060: assertEquals("classes", 0, node.getClasses().size());
061: assertEquals("inbounds", 0, node.getInboundDependencies()
062: .size());
063: assertEquals("outbounds", 0, node.getOutboundDependencies()
064: .size());
065: }
066:
067: public void testLookupPackage() {
068: Node node1 = factory.createPackage("a");
069: Node node2 = factory.createPackage("a");
070:
071: assertSame("factory returned different object for same key",
072: node1, node2);
073: }
074:
075: public void testCreateClass() {
076: ClassNode node = factory.createClass("a.A");
077:
078: assertEquals("name", "a.A", node.getName());
079: assertEquals("package name", "a", node.getPackageNode()
080: .getName());
081: assertEquals("features", 0, node.getFeatures().size());
082: assertEquals("inbounds", 0, node.getInboundDependencies()
083: .size());
084: assertEquals("outbounds", 0, node.getOutboundDependencies()
085: .size());
086: }
087:
088: public void testCreateClassInDefaultPackage() {
089: ClassNode node = factory.createClass("A");
090:
091: assertEquals("name", "A", node.getName());
092: assertEquals("package name", "", node.getPackageNode()
093: .getName());
094: }
095:
096: public void testCreateIllegalClass() {
097: ClassNode node = factory.createClass("");
098:
099: assertEquals("name", "", node.getName());
100: assertEquals("package name", "", node.getPackageNode()
101: .getName());
102: }
103:
104: public void testLookupClass() {
105: Node node1 = factory.createClass("a.A");
106: Node node2 = factory.createClass("a.A");
107:
108: assertSame("factory returned different object for same key",
109: node1, node2);
110: }
111:
112: public void testCreateFeature() {
113: FeatureNode node = factory.createFeature("a.A.a");
114:
115: assertEquals("name", "a.A.a", node.getName());
116: assertEquals("class name", "a.A", node.getClassNode().getName());
117: assertEquals("pacakge name", "a", node.getClassNode()
118: .getPackageNode().getName());
119: assertEquals("inbounds", 0, node.getInboundDependencies()
120: .size());
121: assertEquals("outbounds", 0, node.getOutboundDependencies()
122: .size());
123: }
124:
125: public void testLookupFeature() {
126: Node node1 = factory.createFeature("a.A.a");
127: Node node2 = factory.createFeature("a.A.a");
128:
129: assertSame("factory returned different object for same key",
130: node1, node2);
131: }
132:
133: public void testCreateFeatureInDefaultPackage() {
134: FeatureNode node = factory.createFeature("A.a");
135:
136: assertEquals("name", "A.a", node.getName());
137: assertEquals("class name", "A", node.getClassNode().getName());
138: assertEquals("package name", "", node.getClassNode()
139: .getPackageNode().getName());
140: }
141:
142: public void testCreateIllegalFeature() {
143: FeatureNode node = factory.createFeature("");
144:
145: assertEquals("name", "", node.getName());
146: assertEquals("class name", "", node.getClassNode().getName());
147: assertEquals("package name", "", node.getClassNode()
148: .getPackageNode().getName());
149: }
150:
151: public void testCreateReferencedPackageNode() {
152: PackageNode node = factory.createPackage("a", false);
153:
154: assertFalse("Not referenced", node.isConfirmed());
155: }
156:
157: public void testCreateConcretePackageNode() {
158: PackageNode node = factory.createPackage("a", true);
159:
160: assertTrue("Not concrete", node.isConfirmed());
161: }
162:
163: public void testCreatePackageNodeDefaultsToReferenced() {
164: PackageNode node = factory.createPackage("a");
165:
166: assertFalse("Not referenced", node.isConfirmed());
167: }
168:
169: public void testCreateReferencedClassNode() {
170: ClassNode node = factory.createClass("a.A", false);
171:
172: assertFalse("Not referenced", node.isConfirmed());
173: assertFalse("Not referenced", node.getPackageNode()
174: .isConfirmed());
175: }
176:
177: public void testCreateConcreteClassNode() {
178: ClassNode node = factory.createClass("a.A", true);
179:
180: assertTrue("Not concrete", node.isConfirmed());
181: assertTrue("Not concrete", node.getPackageNode().isConfirmed());
182: }
183:
184: public void testCreateClassNodeDefaultsToReferenced() {
185: ClassNode node = factory.createClass("a.A");
186:
187: assertFalse("Not referenced", node.isConfirmed());
188: assertFalse("Not referenced", node.getPackageNode()
189: .isConfirmed());
190: }
191:
192: public void testCreateReferencedFeatureNode() {
193: FeatureNode node = factory.createFeature("a.A.a", false);
194:
195: assertFalse("Not referenced", node.isConfirmed());
196: assertFalse("Not referenced", node.getClassNode().isConfirmed());
197: assertFalse("Not referenced", node.getClassNode()
198: .getPackageNode().isConfirmed());
199: }
200:
201: public void testCreateConcreteFeatureNode() {
202: FeatureNode node = factory.createFeature("a.A.a", true);
203:
204: assertTrue("Not concrete", node.isConfirmed());
205: assertTrue("Not concrete", node.getClassNode().isConfirmed());
206: assertTrue("Not concrete", node.getClassNode().getPackageNode()
207: .isConfirmed());
208: }
209:
210: public void testCreateFeatureNodeDefaultsToReferenced() {
211: FeatureNode node = factory.createFeature("a.A.a");
212:
213: assertFalse("Not referenced", node.isConfirmed());
214: assertFalse("Not referenced", node.getClassNode().isConfirmed());
215: assertFalse("Not referenced", node.getClassNode()
216: .getPackageNode().isConfirmed());
217: }
218:
219: public void testSwitchPackageNodeFromReferencedToConcrete() {
220: PackageNode node;
221:
222: node = factory.createPackage("a", false);
223: assertFalse("Not referenced", node.isConfirmed());
224:
225: node = factory.createPackage("a", true);
226: assertTrue("Not concrete", node.isConfirmed());
227: }
228:
229: public void testSwitchPackageNodeFromConcreteToReferenced() {
230: PackageNode node;
231:
232: node = factory.createPackage("a", true);
233: assertTrue("Not concrete", node.isConfirmed());
234:
235: node = factory.createPackage("a", false);
236: assertTrue("Not concrete", node.isConfirmed());
237: }
238:
239: public void testMakingPackageNodeConcreteDoesNotChangeItsClasses() {
240: PackageNode node;
241:
242: node = factory.createPackage("a", false);
243: factory.createClass("a.A", false);
244: assertFalse("Not referenced", node.isConfirmed());
245: assertFalse("Not referenced", ((Node) node.getClasses()
246: .iterator().next()).isConfirmed());
247:
248: node = factory.createPackage("a", true);
249: assertTrue("Not concrete", node.isConfirmed());
250: assertFalse("Not referenced", ((Node) node.getClasses()
251: .iterator().next()).isConfirmed());
252: }
253:
254: public void testSwitchClassNodeFromReferencedToConcrete() {
255: ClassNode node;
256:
257: node = factory.createClass("a.A", false);
258: assertFalse("Not referenced", node.isConfirmed());
259: assertFalse("Not referenced", node.getPackageNode()
260: .isConfirmed());
261:
262: node = factory.createClass("a.A", true);
263: assertTrue("Not concrete", node.isConfirmed());
264: assertTrue("Not concrete", node.getPackageNode().isConfirmed());
265: }
266:
267: public void testSwitchClassNodeFromConcreteToReferenced() {
268: ClassNode node;
269:
270: node = factory.createClass("a.A", true);
271: assertTrue("Not concrete", node.isConfirmed());
272: assertTrue("Not concrete", node.getPackageNode().isConfirmed());
273:
274: node = factory.createClass("a.A", false);
275: assertTrue("Not concrete", node.isConfirmed());
276: assertTrue("Not concrete", node.getPackageNode().isConfirmed());
277: }
278:
279: public void testMakingClassNodeConcreteDoesNotChangeItsFeatures() {
280: ClassNode node;
281:
282: node = factory.createClass("a.A", false);
283: factory.createFeature("a.A.a", false);
284: assertFalse("Not referenced", node.isConfirmed());
285: assertFalse("Not referenced", ((Node) node.getFeatures()
286: .iterator().next()).isConfirmed());
287:
288: node = factory.createClass("a.A", true);
289: assertTrue("Not concrete", node.isConfirmed());
290: assertFalse("Not referenced", ((Node) node.getFeatures()
291: .iterator().next()).isConfirmed());
292: }
293:
294: public void testSwitchFeatureNodeFromReferencedToConcrete() {
295: FeatureNode node;
296:
297: node = factory.createFeature("a.A.a", false);
298: assertFalse("Not referenced", node.isConfirmed());
299: assertFalse("Not referenced", node.getClassNode().isConfirmed());
300: assertFalse("Not referenced", node.getClassNode()
301: .getPackageNode().isConfirmed());
302:
303: node = factory.createFeature("a.A.a", true);
304: assertTrue("Not concrete", node.isConfirmed());
305: assertTrue("Not concrete", node.getClassNode().isConfirmed());
306: assertTrue("Not concrete", node.getClassNode().getPackageNode()
307: .isConfirmed());
308: }
309:
310: public void testSwitchFeatureNodeFromConcreteToReferenced() {
311: FeatureNode node;
312:
313: node = factory.createFeature("a.A.a", true);
314: assertTrue("Not concrete", node.isConfirmed());
315: assertTrue("Not concrete", node.getClassNode().isConfirmed());
316: assertTrue("Not concrete", node.getClassNode().getPackageNode()
317: .isConfirmed());
318:
319: node = factory.createFeature("a.A.a", false);
320: assertTrue("Not concrete", node.isConfirmed());
321: assertTrue("Not concrete", node.getClassNode().isConfirmed());
322: assertTrue("Not concrete", node.getClassNode().getPackageNode()
323: .isConfirmed());
324: }
325: }
|