KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.*;
36 import java.util.*;
37
38 import junit.framework.*;
39
40 public class TestGraphCopierWithConfirmed extends TestCase {
41     private NodeFactory factory;
42     
43     private Node a;
44     private Node a_A;
45     private Node a_A_a;
46     
47     private Node b;
48     private Node b_B;
49     private Node b_B_b;
50     
51     private Node c;
52     private Node c_C;
53     private Node c_C_c;
54
55     private GraphCopier copier;
56
57     protected void setUp() throws Exception JavaDoc {
58         factory = new NodeFactory();
59
60         a = factory.createPackage("a");
61         a_A = factory.createClass("a.A");
62         a_A_a = factory.createFeature("a.A.a");
63         
64         b = factory.createPackage("b");
65         b_B = factory.createClass("b.B");
66         b_B_b = factory.createFeature("b.B.b");
67         
68         c = factory.createPackage("c");
69         c_C = factory.createClass("c.C");
70         c_C_c = factory.createFeature("c.C.c");
71         
72         copier = new GraphCopier(new SelectiveTraversalStrategy());
73     }
74
75     public void testConfirmedPackage2ConfirmedPackage() {
76         a.addDependency(b);
77         b.addDependency(c);
78
79         factory.createPackage("a", true);
80         factory.createPackage("b", true);
81         factory.createPackage("c", true);
82         
83         b.accept(copier);
84
85         assertTrue(((Node) copier.getFilterFactory().getPackages().get("a")).isConfirmed());
86         assertNull(copier.getFilterFactory().getClasses().get("a.A"));
87         assertNull(copier.getFilterFactory().getFeatures().get("a.A.a"));
88         assertTrue(((Node) copier.getScopeFactory().getPackages().get("b")).isConfirmed());
89         assertFalse(((Node) copier.getScopeFactory().getClasses().get("b.B")).isConfirmed());
90         assertFalse(((Node) copier.getScopeFactory().getFeatures().get("b.B.b")).isConfirmed());
91         assertTrue(((Node) copier.getFilterFactory().getPackages().get("c")).isConfirmed());
92         assertNull(copier.getFilterFactory().getClasses().get("c.C"));
93         assertNull(copier.getFilterFactory().getFeatures().get("c.C.c"));
94     }
95
96     public void testUnconfirmedPackage2UnconfirmedPackage() {
97         a.addDependency(b);
98         b.addDependency(c);
99
100         b.accept(copier);
101
102         assertFalse(((Node) copier.getFilterFactory().getPackages().get("a")).isConfirmed());
103         assertNull(copier.getFilterFactory().getClasses().get("a.A"));
104         assertNull(copier.getFilterFactory().getFeatures().get("a.A.a"));
105         assertFalse(((Node) copier.getScopeFactory().getPackages().get("b")).isConfirmed());
106         assertFalse(((Node) copier.getScopeFactory().getClasses().get("b.B")).isConfirmed());
107         assertFalse(((Node) copier.getScopeFactory().getFeatures().get("b.B.b")).isConfirmed());
108         assertFalse(((Node) copier.getFilterFactory().getPackages().get("c")).isConfirmed());
109         assertNull(copier.getFilterFactory().getClasses().get("c.C"));
110         assertNull(copier.getFilterFactory().getFeatures().get("c.C.c"));
111     }
112
113     public void testConfirmedClass2ConfirmedClass() {
114         a_A.addDependency(b_B);
115         b_B.addDependency(c_C);
116
117         factory.createClass("a.A", true);
118         factory.createClass("b.B", true);
119         factory.createClass("c.C", true);
120         
121         b.accept(copier);
122
123         assertTrue(((Node) copier.getFilterFactory().getPackages().get("a")).isConfirmed());
124         assertTrue(((Node) copier.getFilterFactory().getClasses().get("a.A")).isConfirmed());
125         assertNull(copier.getFilterFactory().getFeatures().get("a.A.a"));
126         assertTrue(((Node) copier.getScopeFactory().getPackages().get("b")).isConfirmed());
127         assertTrue(((Node) copier.getScopeFactory().getClasses().get("b.B")).isConfirmed());
128         assertFalse(((Node) copier.getScopeFactory().getFeatures().get("b.B.b")).isConfirmed());
129         assertTrue(((Node) copier.getFilterFactory().getPackages().get("c")).isConfirmed());
130         assertTrue(((Node) copier.getFilterFactory().getClasses().get("c.C")).isConfirmed());
131         assertNull(copier.getFilterFactory().getFeatures().get("c.C.c"));
132     }
133
134     public void testUnconfirmedClass2UnconfirmedClass() {
135         a_A.addDependency(b_B);
136         b_B.addDependency(c_C);
137
138         b.accept(copier);
139
140         assertFalse(((Node) copier.getFilterFactory().getPackages().get("a")).isConfirmed());
141         assertFalse(((Node) copier.getFilterFactory().getClasses().get("a.A")).isConfirmed());
142         assertNull(copier.getFilterFactory().getFeatures().get("a.A.a"));
143         assertFalse(((Node) copier.getScopeFactory().getPackages().get("b")).isConfirmed());
144         assertFalse(((Node) copier.getScopeFactory().getClasses().get("b.B")).isConfirmed());
145         assertFalse(((Node) copier.getScopeFactory().getFeatures().get("b.B.b")).isConfirmed());
146         assertFalse(((Node) copier.getFilterFactory().getPackages().get("c")).isConfirmed());
147         assertFalse(((Node) copier.getFilterFactory().getClasses().get("c.C")).isConfirmed());
148         assertNull(copier.getFilterFactory().getFeatures().get("c.C.c"));
149     }
150
151     public void testConfirmedFeature2ConfirmedFeature() {
152         a_A_a.addDependency(b_B_b);
153         b_B_b.addDependency(c_C_c);
154
155         factory.createFeature("a.A.a", true);
156         factory.createFeature("b.B.b", true);
157         factory.createFeature("c.C.c", true);
158         
159         b.accept(copier);
160
161         assertTrue(copier.getFilterFactory().createPackage("a").isConfirmed());
162         assertTrue(copier.getFilterFactory().createClass("a.A").isConfirmed());
163         assertTrue(copier.getFilterFactory().createFeature("a.A.a").isConfirmed());
164         assertTrue(copier.getScopeFactory().createPackage("b").isConfirmed());
165         assertTrue(copier.getScopeFactory().createClass("b.B").isConfirmed());
166         assertTrue(copier.getScopeFactory().createFeature("b.B.b").isConfirmed());
167         assertTrue(copier.getFilterFactory().createPackage("c").isConfirmed());
168         assertTrue(copier.getFilterFactory().createClass("c.C").isConfirmed());
169         assertTrue(copier.getFilterFactory().createFeature("c.C.c").isConfirmed());
170     }
171
172     public void testUnconfirmedFeature2UnconfirmedFeature() {
173         a_A_a.addDependency(b_B_b);
174         b_B_b.addDependency(c_C_c);
175
176         b.accept(copier);
177
178         assertFalse(copier.getFilterFactory().createPackage("a").isConfirmed());
179         assertFalse(copier.getFilterFactory().createClass("a.A").isConfirmed());
180         assertFalse(copier.getFilterFactory().createFeature("a.A.a").isConfirmed());
181         assertFalse(copier.getScopeFactory().createPackage("b").isConfirmed());
182         assertFalse(copier.getScopeFactory().createClass("b.B").isConfirmed());
183         assertFalse(copier.getScopeFactory().createFeature("b.B.b").isConfirmed());
184         assertFalse(copier.getFilterFactory().createPackage("c").isConfirmed());
185         assertFalse(copier.getFilterFactory().createClass("c.C").isConfirmed());
186         assertFalse(copier.getFilterFactory().createFeature("c.C.c").isConfirmed());
187     }
188 }
189
Popular Tags