KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.apache.oro.text.perl.*;
41
42 public class TestClosureStartSelector extends TestCase {
43     private NodeFactory factory;
44     private NodeFactory localFactory;
45     private RegularExpressionSelectionCriteria localCriteria;
46
47     private PackageNode a;
48     private ClassNode a_A;
49     private FeatureNode a_A_a;
50     
51     private PackageNode b;
52     private ClassNode b_B;
53     private FeatureNode b_B_b;
54     
55     private PackageNode c;
56     private ClassNode c_C;
57     private FeatureNode c_C_c;
58
59     protected void setUp() throws Exception JavaDoc {
60         factory = new NodeFactory();
61         localFactory = new NodeFactory();
62         localCriteria = new RegularExpressionSelectionCriteria();
63
64         a = factory.createPackage("a");
65         a_A = factory.createClass("a.A");
66         a_A_a = factory.createFeature("a.A.a");
67         
68         b = factory.createPackage("b");
69         b_B = factory.createClass("b.B");
70         b_B_b = factory.createFeature("b.B.b");
71         
72         c = factory.createPackage("c");
73         c_C = factory.createClass("c.C");
74         c_C_c = factory.createFeature("c.C.c");
75
76         a_A_a.addDependency(b_B_b);
77         b_B_b.addDependency(c_C_c);
78     }
79
80     public void testOneSelectedNode() {
81         localCriteria.setGlobalIncludes("/b.B.b/");
82
83         ClosureStartSelector selector = new ClosureStartSelector(localFactory, localCriteria);
84         selector.traverseNodes(factory.getPackages().values());
85
86         assertEquals("nodes in selection", 1, selector.getSelectedNodes().size());
87         assertEquals("b.B.b in selection", b_B_b, selector.getSelectedNodes().iterator().next());
88         assertSame("b.B.b in selection", b_B_b, selector.getSelectedNodes().iterator().next());
89     }
90
91     public void testOneCopiedNode() {
92         localCriteria.setGlobalIncludes("/b.B.b/");
93
94         ClosureStartSelector selector = new ClosureStartSelector(localFactory, localCriteria);
95         selector.traverseNodes(factory.getPackages().values());
96
97         assertEquals("packages in scope", 1, localFactory.getPackages().size());
98         assertEquals("classes in scope" , 1, localFactory.getClasses().size());
99         assertEquals("features in scope", 1, localFactory.getFeatures().size());
100
101         assertEquals("package b in scope" , b, localFactory.getPackages().get("b"));
102         assertEquals("class b.B in scope" , b_B, localFactory.getClasses().get("b.B"));
103         assertEquals("feature b.B.b in scope", b_B_b, localFactory.getFeatures().get("b.B.b"));
104
105         assertNotSame("package b in scope" , b, localFactory.getPackages().get("b"));
106         assertNotSame("class b.B in scope" , b_B, localFactory.getClasses().get("b.B"));
107         assertNotSame("feature b.B.b in scope", b_B_b, localFactory.getFeatures().get("b.B.b"));
108
109         assertEquals("nodes in selection", 1, selector.getCopiedNodes().size());
110         assertEquals("b.B.b in selection", b_B_b, selector.getCopiedNodes().iterator().next());
111         assertNotSame("b.B.b in selection", b_B_b, selector.getCopiedNodes().iterator().next());
112         assertSame("b.B.b in selection", localFactory.getFeatures().get("b.B.b"), selector.getCopiedNodes().iterator().next());
113     }
114
115     public void testMultipleSelectedNodes() {
116         localCriteria.setGlobalIncludes("/a.A.a/, /^b/");
117
118         ClosureStartSelector selector = new ClosureStartSelector(localFactory, localCriteria);
119         selector.traverseNodes(factory.getPackages().values());
120
121         assertEquals("nodes in selection", 4, selector.getSelectedNodes().size());
122         assertTrue("a.A.a in selection", selector.getSelectedNodes().contains(a_A_a));
123         assertTrue("b in selection", selector.getSelectedNodes().contains(b));
124         assertTrue("b.B in selection", selector.getSelectedNodes().contains(b_B));
125         assertTrue("b.B.b in selection", selector.getSelectedNodes().contains(b_B_b));
126     }
127
128     public void testMultipleCopiedNodes() {
129         localCriteria.setGlobalIncludes("/a.A.a/, /^b/");
130
131         ClosureStartSelector selector = new ClosureStartSelector(localFactory, localCriteria);
132         selector.traverseNodes(factory.getPackages().values());
133
134         assertEquals("packages in scope", 2, localFactory.getPackages().size());
135         assertEquals("classes in scope" , 2, localFactory.getClasses().size());
136         assertEquals("features in scope", 2, localFactory.getFeatures().size());
137
138         assertEquals("package a in scope" , a, localFactory.getPackages().get("a"));
139         assertEquals("class a.A in scope" , a_A, localFactory.getClasses().get("a.A"));
140         assertEquals("feature a.A.a in scope", a_A_a, localFactory.getFeatures().get("a.A.a"));
141         assertEquals("package b in scope" , b, localFactory.getPackages().get("b"));
142         assertEquals("class b.B in scope" , b_B, localFactory.getClasses().get("b.B"));
143         assertEquals("feature b.B.b in scope", b_B_b, localFactory.getFeatures().get("b.B.b"));
144
145         assertNotSame("package a in scope" , a, localFactory.getPackages().get("a"));
146         assertNotSame("class a.A in scope" , a_A, localFactory.getClasses().get("a.A"));
147         assertNotSame("feature a.A.a in scope", a_A_a, localFactory.getFeatures().get("a.A.a"));
148         assertNotSame("package b in scope" , b, localFactory.getPackages().get("b"));
149         assertNotSame("class b.B in scope" , b_B, localFactory.getClasses().get("b.B"));
150         assertNotSame("feature b.B.b in scope", b_B_b, localFactory.getFeatures().get("b.B.b"));
151
152         assertEquals("nodes in selection", 4, selector.getCopiedNodes().size());
153         assertTrue("a.A.a in selection", selector.getCopiedNodes().contains(a_A_a));
154         assertTrue("b in selection", selector.getCopiedNodes().contains(b));
155         assertTrue("b.B in selection", selector.getCopiedNodes().contains(b_B));
156         assertTrue("b.B.b in selection", selector.getCopiedNodes().contains(b_B_b));
157     }
158
159     public void testVisitInferredPackage() {
160         ClosureStartSelector selector = new ClosureStartSelector(localFactory, new ComprehensiveSelectionCriteria());
161         selector.traverseNodes(Collections.singleton(b));
162
163         assertEquals("package.isConfirmed()", b.isConfirmed(), ((Node) localFactory.getPackages().get(b.getName())).isConfirmed());
164     }
165
166     public void testVisitConfirmedPackage() {
167         b.setConfirmed(true);
168         
169         ClosureStartSelector selector = new ClosureStartSelector(localFactory, new ComprehensiveSelectionCriteria());
170         selector.traverseNodes(Collections.singleton(b));
171
172         assertEquals("package.isConfirmed()", b.isConfirmed(), ((Node) localFactory.getPackages().get(b.getName())).isConfirmed());
173     }
174
175     public void testVisitInferredClass() {
176         ClosureStartSelector selector = new ClosureStartSelector(localFactory, new ComprehensiveSelectionCriteria());
177         selector.traverseNodes(Collections.singleton(b_B));
178
179         assertEquals("class.isConfirmed()", b_B.isConfirmed(), ((Node) localFactory.getClasses().get(b_B.getName())).isConfirmed());
180     }
181
182     public void testVisitConfirmedClass() {
183         b_B.setConfirmed(true);
184         
185         ClosureStartSelector selector = new ClosureStartSelector(localFactory, new ComprehensiveSelectionCriteria());
186         selector.traverseNodes(Collections.singleton(b_B));
187
188         assertEquals("class.isConfirmed()", b_B.isConfirmed(), ((Node) localFactory.getClasses().get(b_B.getName())).isConfirmed());
189     }
190
191     public void testVisitInferredFeature() {
192         ClosureStartSelector selector = new ClosureStartSelector(localFactory, new ComprehensiveSelectionCriteria());
193         selector.traverseNodes(Collections.singleton(b_B_b));
194
195         assertEquals("feature.isConfirmed()", b_B_b.isConfirmed(), ((Node) localFactory.getFeatures().get(b_B_b.getName())).isConfirmed());
196     }
197
198     public void testVisitConfirmedFeature() {
199         b_B_b.setConfirmed(true);
200         
201         ClosureStartSelector selector = new ClosureStartSelector(localFactory, new ComprehensiveSelectionCriteria());
202         selector.traverseNodes(Collections.singleton(b_B_b));
203
204         assertEquals("feature.isConfirmed()", b_B_b.isConfirmed(), ((Node) localFactory.getFeatures().get(b_B_b.getName())).isConfirmed());
205     }
206 }
207
Popular Tags