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.dependencyfinder.web;
034:
035: import com.meterware.httpunit.*;
036:
037: public abstract class TestQueryBase extends TestBase {
038: public void testFormSubmit() throws Exception {
039: context.service();
040: WebResponse response = client.getResponse(request);
041:
042: assertEquals("Nb forms", 1, response.getForms().length);
043: WebForm form = response.getForms()[0];
044: assertEquals("Nb submit buttons", 1,
045: form.getSubmitButtons().length);
046: SubmitButton button = form.getSubmitButtons()[0];
047:
048: response = form.submit(button);
049:
050: assertNotNull("Missing link to " + fooPackageName, response
051: .getLinkWith(fooPackageName));
052: assertNull("Unwanted link to " + fooClassName, response
053: .getLinkWith(fooClassName));
054: assertNull("Unwanted link to " + fooFeatureName, response
055: .getLinkWith(fooFeatureName));
056: assertNotNull("Missing link to " + barPackageName, response
057: .getLinkWith(barPackageName));
058: assertNull("Unwanted link to " + barClassName, response
059: .getLinkWith(barClassName));
060: assertNull("Unwanted link to " + barFeatureName, response
061: .getLinkWith(barFeatureName));
062: assertNotNull("Missing link to " + bazPackageName, response
063: .getLinkWith(bazPackageName));
064: assertNull("Unwanted link to " + bazClassName, response
065: .getLinkWith(bazClassName));
066: assertNull("Unwanted link to " + bazFeatureName, response
067: .getLinkWith(bazFeatureName));
068: assertNotNull("Missing link to " + leftPackageName, response
069: .getLinkWith(leftPackageName));
070: assertNull("Unwanted link to " + leftClassName, response
071: .getLinkWith(leftClassName));
072: assertNull("Unwanted link to " + leftFeatureName, response
073: .getLinkWith(leftFeatureName));
074: assertNotNull("Missing link to " + rightPackageName, response
075: .getLinkWith(rightPackageName));
076: assertNull("Unwanted link to " + rightClassName, response
077: .getLinkWith(rightClassName));
078: assertNull("Unwanted link to " + rightFeatureName, response
079: .getLinkWith(rightFeatureName));
080: }
081:
082: public void testDirectQuery() throws Exception {
083: request.setParameter("scope-includes", "//");
084: request.setParameter("package-scope", "on");
085: request.setParameter("filter-includes", "//");
086: request.setParameter("package-filter", "on");
087: request.setParameter("show-inbounds", "on");
088: request.setParameter("show-outbounds", "on");
089: request.setParameter("show-empty-nodes", "on");
090: request.setParameter("submit", "Run Query");
091:
092: context.service();
093: WebResponse response = client.getResponse(request);
094:
095: assertNotNull("Missing link to " + fooPackageName, response
096: .getLinkWith(fooPackageName));
097: assertNull("Unwanted link to " + fooClassName, response
098: .getLinkWith(fooClassName));
099: assertNull("Unwanted link to " + fooFeatureName, response
100: .getLinkWith(fooFeatureName));
101: assertNotNull("Missing link to " + barPackageName, response
102: .getLinkWith(barPackageName));
103: assertNull("Unwanted link to " + barClassName, response
104: .getLinkWith(barClassName));
105: assertNull("Unwanted link to " + barFeatureName, response
106: .getLinkWith(barFeatureName));
107: assertNotNull("Missing link to " + bazPackageName, response
108: .getLinkWith(bazPackageName));
109: assertNull("Unwanted link to " + bazClassName, response
110: .getLinkWith(bazClassName));
111: assertNull("Unwanted link to " + bazFeatureName, response
112: .getLinkWith(bazFeatureName));
113: assertNotNull("Missing link to " + leftPackageName, response
114: .getLinkWith(leftPackageName));
115: assertNull("Unwanted link to " + leftClassName, response
116: .getLinkWith(leftClassName));
117: assertNull("Unwanted link to " + leftFeatureName, response
118: .getLinkWith(leftFeatureName));
119: assertNotNull("Missing link to " + rightPackageName, response
120: .getLinkWith(rightPackageName));
121: assertNull("Unwanted link to " + rightClassName, response
122: .getLinkWith(rightClassName));
123: assertNull("Unwanted link to " + rightFeatureName, response
124: .getLinkWith(rightFeatureName));
125:
126: assertNotNull("Missing link foo", response
127: .getLinkWithID(fooPackageName));
128: assertNotNull("Missing link foo --> bar",
129: response.getLinkWithID(fooPackageName + "_to_"
130: + barPackageName));
131: assertNotNull("Missing link bar", response
132: .getLinkWithID(barPackageName));
133: assertNotNull("Missing link bar <-- foo", response
134: .getLinkWithID(barPackageName + "_from_"
135: + fooPackageName));
136: assertNotNull("Missing link bar --> baz",
137: response.getLinkWithID(barPackageName + "_to_"
138: + bazPackageName));
139: assertNotNull("Missing link baz", response
140: .getLinkWithID(bazPackageName));
141: assertNotNull("Missing link baz <-- bar", response
142: .getLinkWithID(bazPackageName + "_from_"
143: + barPackageName));
144: assertNotNull("Missing link left", response
145: .getLinkWithID(leftPackageName));
146: assertNotNull("Missing link left <-> right", response
147: .getLinkWithID(leftPackageName + "_bidirectional_"
148: + rightPackageName));
149: assertNotNull("Missing link right", response
150: .getLinkWithID(rightPackageName));
151: assertNotNull("Missing link right <-> left", response
152: .getLinkWithID(rightPackageName + "_bidirectional_"
153: + leftPackageName));
154: }
155:
156: public void testFollowDependencyLink() throws Exception {
157: context.service();
158: WebResponse response = client.getResponse(request);
159:
160: WebForm form = response.getForms()[0];
161: form.setCheckbox("package-scope", false);
162: form.setCheckbox("feature-scope", true);
163: form.setCheckbox("package-filter", false);
164: form.setCheckbox("feature-filter", true);
165:
166: response = form.submit(form.getSubmitButtons()[0]);
167: response = response.getLinkWithID(
168: fooFeatureName + "_to_" + barFeatureName).click();
169:
170: assertNull("Unwanted link foo", response
171: .getLinkWithID(fooPackageName));
172: assertNotNull("Missing link bar", response
173: .getLinkWithID(barPackageName));
174: assertNotNull("Missing link bar.Bar", response
175: .getLinkWithID(barClassName));
176: assertNotNull("Missing link bar.Bar.bar()", response
177: .getLinkWithID(barFeatureName));
178: assertNotNull("Missing link bar.Bar.bar() <-- foo.Foo.foo()",
179: response.getLinkWithID(barFeatureName + "_from_"
180: + fooFeatureName));
181: assertNotNull("Missing link bar.Bar.bar() --> baz.Baz.baz()",
182: response.getLinkWithID(barFeatureName + "_to_"
183: + bazFeatureName));
184: assertNull("Unwanted link baz", response
185: .getLinkWithID(bazPackageName));
186: assertNull("Unwanted link left", response
187: .getLinkWithID(leftPackageName));
188: assertNull("Unwanted link right", response
189: .getLinkWithID(rightPackageName));
190: }
191:
192: public void testNarrowScope() throws Exception {
193: factory.createFeature(foo2FeatureName);
194:
195: context.service();
196: WebResponse response = client.getResponse(request);
197:
198: WebForm form = response.getForms()[0];
199: form.setCheckbox("package-scope", false);
200: form.setCheckbox("feature-scope", true);
201: form.setCheckbox("package-filter", false);
202: form.setCheckbox("feature-filter", true);
203:
204: response = form.submit(form.getSubmitButtons()[0]);
205: response = response.getLinkWithID(fooFeatureName).click();
206:
207: assertNotNull("Missing link foo", response
208: .getLinkWithID(fooPackageName));
209: assertNotNull("Missing link foo.Foo", response
210: .getLinkWithID(fooClassName));
211: assertNotNull("Missing link foo.Foo.foo()", response
212: .getLinkWithID(fooFeatureName));
213: assertNotNull("Missing link foo.Foo.foo() --> bar.Bar.bar()",
214: response.getLinkWithID(fooFeatureName + "_to_"
215: + barFeatureName));
216: assertNull("Unwanted link foo.Foo2", response
217: .getLinkWithID(foo2ClassName));
218: assertNull("Unwanted link bar", response
219: .getLinkWithID(barPackageName));
220: assertNull("Unwanted link baz", response
221: .getLinkWithID(bazPackageName));
222: assertNull("Unwanted link left", response
223: .getLinkWithID(leftPackageName));
224: assertNull("Unwanted link right", response
225: .getLinkWithID(rightPackageName));
226: }
227:
228: public void testNarrowThanWidenScope() throws Exception {
229: factory.createFeature(foo2FeatureName);
230:
231: context.service();
232: WebResponse response = client.getResponse(request);
233:
234: WebForm form = response.getForms()[0];
235: form.setCheckbox("package-scope", false);
236: form.setCheckbox("feature-scope", true);
237: form.setCheckbox("package-filter", false);
238: form.setCheckbox("feature-filter", true);
239:
240: response = form.submit(form.getSubmitButtons()[0]);
241: response = response.getLinkWithID(fooFeatureName).click();
242: response = response.getLinkWithID(fooPackageName).click();
243:
244: assertNotNull("Missing link foo", response
245: .getLinkWithID(fooPackageName));
246: assertNotNull("Missing link foo.Foo", response
247: .getLinkWithID(fooClassName));
248: assertNotNull("Missing link foo.Foo.foo()", response
249: .getLinkWithID(fooFeatureName));
250: assertNotNull("Missing link foo.Foo.foo() --> bar.Bar.bar()",
251: response.getLinkWithID(fooFeatureName + "_to_"
252: + barFeatureName));
253: assertNotNull("Missing link foo.Foo2", response
254: .getLinkWithID(foo2ClassName));
255: assertNotNull("Missing link foo.Foo2.foo2()", response
256: .getLinkWithID(foo2FeatureName));
257: assertNull("Unwanted link bar", response
258: .getLinkWithID(barPackageName));
259: assertNull("Unwanted link baz", response
260: .getLinkWithID(bazPackageName));
261: assertNull("Unwanted link left", response
262: .getLinkWithID(leftPackageName));
263: assertNull("Unwanted link right", response
264: .getLinkWithID(rightPackageName));
265: }
266: }
|