KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > jwebunit > WebTestCase


1 /********************************************************************************
2  * Copyright (c) 2001, ThoughtWorks, Inc.
3  * Distributed open-source, see full license under licenses/jwebunit_license.txt
4 **********************************/

5
6 package net.sourceforge.jwebunit;
7
8 import net.sourceforge.jwebunit.HttpUnitDialog;
9 import junit.framework.TestCase;
10
11 import java.io.PrintStream JavaDoc;
12
13 /**
14  * Superclass for Junit TestCases which provides web application navigation and
15  * Junit assertions. This class uses {@link net.sourceforge.jwebunit.WebTester} as a mixin -
16  * See that class for method documentation.
17  *
18  * @author Jim Weaver
19  * @author Wilkes Joiner
20  */

21 public class WebTestCase extends TestCase {
22     protected WebTester tester;
23
24     public WebTestCase(String JavaDoc name) {
25         super(name);
26         tester = new WebTester();
27     }
28
29     public WebTestCase() {
30         tester = new WebTester();
31     }
32
33     protected WebTester getTester() {
34         return tester;
35     }
36
37     public HttpUnitDialog getDialog() {
38         return tester.getDialog();
39     }
40
41     public TestContext getTestContext() {
42         return tester.getTestContext();
43     }
44
45     public void beginAt(String JavaDoc relativeURL) {
46         tester.beginAt(relativeURL);
47     }
48
49     public String JavaDoc getMessage(String JavaDoc key) {
50         return tester.getMessage(key);
51     }
52
53 // Assertions
54

55     public void assertTitleEquals(String JavaDoc title) {
56         tester.assertTitleEquals(title);
57     }
58
59     public void assertTitleEqualsKey(String JavaDoc titleKey) {
60         tester.assertTitleEqualsKey(titleKey);
61     }
62
63     public void assertKeyPresent(String JavaDoc key) {
64         tester.assertKeyPresent(key);
65     }
66
67     public void assertTextPresent(String JavaDoc text) {
68         tester.assertTextPresent(text);
69     }
70
71     public void assertKeyNotPresent(String JavaDoc key) {
72         tester.assertKeyNotPresent(key);
73     }
74
75     public void assertTextNotPresent(String JavaDoc text) {
76         tester.assertTextNotPresent(text);
77     }
78
79     public void assertTablePresent(String JavaDoc tableSummaryOrId) {
80         tester.assertTablePresent(tableSummaryOrId);
81     }
82
83     public void assertTableNotPresent(String JavaDoc tableSummaryOrId) {
84         tester.assertTableNotPresent(tableSummaryOrId);
85     }
86
87     public void assertKeyInTable(String JavaDoc tableSummaryOrId, String JavaDoc key) {
88         tester.assertKeyInTable(tableSummaryOrId, key);
89     }
90
91     public void assertTextInTable(String JavaDoc tableSummaryOrId, String JavaDoc text) {
92         tester.assertTextInTable(tableSummaryOrId, text);
93     }
94
95     public void assertKeysInTable(String JavaDoc tableSummaryOrId, String JavaDoc[] keys) {
96         tester.assertKeysInTable(tableSummaryOrId, keys);
97     }
98
99     public void assertTextInTable(String JavaDoc tableSummaryOrId, String JavaDoc[] text) {
100         tester.assertTextInTable(tableSummaryOrId, text);
101     }
102
103     public void assertKeyNotInTable(String JavaDoc tableSummaryOrId, String JavaDoc key) {
104         tester.assertKeyNotInTable(tableSummaryOrId, key);
105     }
106
107     public void assertTextNotInTable(String JavaDoc tableSummaryOrId, String JavaDoc text) {
108         tester.assertTextNotInTable(tableSummaryOrId, text);
109     }
110
111     public void assertTextNotInTable(String JavaDoc tableSummaryOrId, String JavaDoc[] text) {
112         tester.assertTextNotInTable(tableSummaryOrId, text);
113     }
114
115     public void assertTableEquals(String JavaDoc tableSummaryOrId, ExpectedTable expectedTable) {
116         tester.assertTableEquals(tableSummaryOrId, expectedTable.getExpectedStrings());
117     }
118
119     public void assertTableEquals(String JavaDoc tableSummaryOrId, String JavaDoc[][] expectedCellValues) {
120         tester.assertTableEquals(tableSummaryOrId, expectedCellValues);
121     }
122
123     public void assertTableRowsEqual(String JavaDoc tableSummaryOrId, int startRow, ExpectedTable expectedTable) {
124         tester.assertTableRowsEqual(tableSummaryOrId, startRow, expectedTable);
125     }
126
127     public void assertTableRowsEqual(String JavaDoc tableSummaryOrId, int startRow, String JavaDoc[][] expectedCellValues) {
128         tester.assertTableRowsEqual(tableSummaryOrId, startRow, expectedCellValues);
129     }
130
131     public void assertFormElementPresent(String JavaDoc formElementName) {
132         tester.assertFormElementPresent(formElementName);
133     }
134
135     public void assertFormElementNotPresent(String JavaDoc formElementName) {
136         tester.assertFormElementNotPresent(formElementName);
137     }
138
139     public void assertFormElementPresentWithLabel(String JavaDoc formElementLabel) {
140         tester.assertFormElementPresentWithLabel(formElementLabel);
141     }
142
143     public void assertFormElementNotPresentWithLabel(String JavaDoc formElementLabel) {
144         tester.assertFormElementNotPresentWithLabel(formElementLabel);
145     }
146
147     public void assertFormPresent() {
148         tester.assertFormPresent();
149     }
150
151     public void assertFormPresent(String JavaDoc formName) {
152         tester.assertFormPresent(formName);
153     }
154
155     public void assertFormNotPresent() {
156         tester.assertFormNotPresent();
157     }
158
159     public void assertFormNotPresent(String JavaDoc formName) {
160         tester.assertFormNotPresent(formName);
161     }
162     
163     public void assertFormElementEquals(String JavaDoc formElementName, String JavaDoc expectedValue) {
164         tester.assertFormElementEquals(formElementName, expectedValue);
165     }
166
167     public void assertFormElementEmpty(String JavaDoc formElementName) {
168         tester.assertFormElementEmpty(formElementName);
169     }
170
171     public void assertCheckboxSelected(String JavaDoc checkBoxName) {
172         tester.assertCheckboxSelected(checkBoxName);
173     }
174
175     public void assertCheckboxNotSelected(String JavaDoc checkBoxName) {
176         tester.assertCheckboxNotSelected(checkBoxName);
177     }
178
179     public void assertRadioOptionPresent(String JavaDoc radioGroup, String JavaDoc radioOption) {
180         tester.assertRadioOptionPresent(radioGroup, radioOption);
181     }
182
183     public void assertRadioOptionNotPresent(String JavaDoc radioGroup, String JavaDoc radioOption) {
184         tester.assertRadioOptionNotPresent(radioGroup, radioOption);
185     }
186
187     public void assertRadioOptionSelected(String JavaDoc radioGroup, String JavaDoc radioOption) {
188         tester.assertRadioOptionSelected(radioGroup, radioOption);
189     }
190
191     public void assertRadioOptionNotSelected(String JavaDoc radioGroup, String JavaDoc radioOption) {
192         tester.assertRadioOptionNotSelected(radioGroup, radioOption);
193     }
194
195     public void assertOptionsEqual(String JavaDoc selectName, String JavaDoc[] options){
196         tester.assertOptionsEqual(selectName, options);
197     }
198
199     public void assertOptionsNotEqual(String JavaDoc selectName, String JavaDoc[] options){
200         tester.assertOptionsNotEqual(selectName, options);
201     }
202
203     public void assertOptionValuesEqual(String JavaDoc selectName, String JavaDoc[] options){
204         tester.assertOptionValuesEqual(selectName, options);
205     }
206
207     public void assertOptionValuesNotEqual(String JavaDoc selectName, String JavaDoc[] options){
208         tester.assertOptionValuesNotEqual(selectName, options);
209     }
210
211     public void assertOptionEquals(String JavaDoc selectName, String JavaDoc option) {
212         tester.assertOptionEquals(selectName, option);
213     }
214
215     public void assertSubmitButtonPresent(String JavaDoc buttonName) {
216         tester.assertSubmitButtonPresent(buttonName);
217     }
218
219     public void assertSubmitButtonNotPresent(String JavaDoc buttonName) {
220         tester.assertSubmitButtonNotPresent(buttonName);
221     }
222
223     public void assertSubmitButtonValue(String JavaDoc buttonName, String JavaDoc expectedValue) {
224         tester.assertSubmitButtonValue(buttonName, expectedValue);
225     }
226
227     public void assertButtonPresent(String JavaDoc buttonID) {
228         tester.assertButtonPresent(buttonID);
229     }
230
231     public void assertButtonNotPresent(String JavaDoc buttonID) {
232         tester.assertButtonNotPresent(buttonID);
233     }
234
235     public void assertLinkPresent(String JavaDoc linkId) {
236         tester.assertLinkPresent(linkId);
237     }
238
239     public void assertLinkNotPresent(String JavaDoc linkId) {
240         tester.assertLinkNotPresent(linkId);
241     }
242
243     public void assertLinkPresentWithText(String JavaDoc linkText) {
244         tester.assertLinkPresentWithText(linkText);
245     }
246
247     public void assertLinkNotPresentWithText(String JavaDoc linkText) {
248         tester.assertLinkNotPresentWithText(linkText);
249     }
250
251     public void assertLinkPresentWithText(String JavaDoc linkText, int index) {
252         tester.assertLinkPresentWithText(linkText, index);
253     }
254
255     public void assertLinkNotPresentWithText(String JavaDoc linkText, int index) {
256         tester.assertLinkNotPresentWithText(linkText, index);
257     }
258
259     public void assertLinkPresentWithImage(String JavaDoc imageFileName) {
260         tester.assertLinkPresentWithImage(imageFileName);
261     }
262
263     public void assertLinkNotPresentWithImage(String JavaDoc imageFileName) {
264         tester.assertLinkNotPresentWithImage(imageFileName);
265     }
266
267     public void assertElementPresent(String JavaDoc anID) {
268         tester.assertElementPresent(anID);
269     }
270
271     public void assertElementNotPresent(String JavaDoc anID) {
272         tester.assertElementNotPresent(anID);
273     }
274
275     public void assertTextInElement(String JavaDoc elID, String JavaDoc text) {
276         tester.assertTextInElement(elID, text);
277     }
278     
279     public void assertTextNotInElement(String JavaDoc elID, String JavaDoc text) {
280         tester.assertTextNotInElement(elID, text);
281     }
282
283     public void assertWindowPresent(String JavaDoc windowName) {
284         tester.assertWindowPresent(windowName);
285     }
286
287     public void assertFramePresent(String JavaDoc frameName) {
288         tester.assertFramePresent(frameName);
289     }
290     
291     /**
292      * Contributed by Vivek Venugopalan.
293      */

294     public void assertCookiePresent(String JavaDoc cookieName) {
295         tester.assertCookiePresent(cookieName);
296     }
297     
298     public void assertCookieValueEquals(String JavaDoc cookieName, String JavaDoc expectedValue) {
299         tester.assertCookieValueEquals(cookieName, expectedValue);
300     }
301     
302     public void dumpCookies() {
303         tester.dumpCookies();
304     }
305     
306     public void dumpCookies(PrintStream JavaDoc stream) {
307         tester.dumpCookies(stream);
308     }
309
310 // Form interaction methods
311

312     public void setWorkingForm(String JavaDoc nameOrId) {
313         tester.setWorkingForm(nameOrId);
314     }
315
316     protected void setFormElement(String JavaDoc formElementName, String JavaDoc value) {
317         tester.setFormElement(formElementName, value);
318     }
319
320     protected void setFormElementWithLabel(String JavaDoc formElementLabel, String JavaDoc value) {
321         tester.setFormElementWithLabel(formElementLabel, value);
322     }
323
324     protected void checkCheckbox(String JavaDoc checkBoxName) {
325         tester.checkCheckbox(checkBoxName);
326     }
327
328     protected void checkCheckbox(String JavaDoc checkBoxName, String JavaDoc value) {
329         tester.checkCheckbox(checkBoxName, value);
330     }
331
332     protected void uncheckCheckbox(String JavaDoc checkBoxName) {
333         tester.uncheckCheckbox(checkBoxName);
334     }
335
336     protected void uncheckCheckbox(String JavaDoc checkBoxName, String JavaDoc value) {
337         tester.uncheckCheckbox(checkBoxName, value);
338     }
339
340     public void selectOption(String JavaDoc selectName, String JavaDoc option) {
341         tester.selectOption(selectName, option);
342     }
343
344 // Form submission and link navigation methods
345

346     protected void submit() {
347         tester.submit();
348     }
349
350     public void submit(String JavaDoc buttonName) {
351         tester.submit(buttonName);
352     }
353
354     public void reset() {
355         tester.reset();
356     }
357
358     protected void clickLinkWithText(String JavaDoc linkText) {
359         tester.clickLinkWithText(linkText);
360     }
361
362     protected void clickLinkWithText(String JavaDoc linkText, int index) {
363         tester.clickLinkWithText(linkText, index);
364     }
365
366     protected void clickLinkWithTextAfterText(String JavaDoc linkText, String JavaDoc labelText) {
367         tester.clickLinkWithTextAfterText(linkText, labelText);
368     }
369
370     protected void clickLinkWithImage(String JavaDoc imageFileName) {
371         tester.clickLinkWithImage(imageFileName);
372     }
373
374     protected void clickLink(String JavaDoc linkId) {
375         tester.clickLink(linkId);
376     }
377
378     protected void clickButton(String JavaDoc buttonId) {
379         tester.clickButton(buttonId);
380     }
381
382 //Window and Frame Navigation Methods
383

384     public void gotoRootWindow() {
385         tester.gotoRootWindow();
386     }
387
388     public void gotoWindow(String JavaDoc windowName) {
389         tester.gotoWindow(windowName);
390     }
391
392     public void gotoFrame(String JavaDoc frameName) {
393         tester.gotoFrame(frameName);
394     }
395
396     /**
397      * Patch sumbitted by Alex Chaffee.
398      */

399     public void gotoPage(String JavaDoc page) {
400         tester.gotoPage(page);
401     }
402
403 // Debug methods
404

405     protected void dumpResponse(PrintStream JavaDoc stream) {
406         tester.dumpResponse(stream);
407     }
408
409     protected void dumpTable(String JavaDoc tableNameOrId, PrintStream JavaDoc stream) {
410         tester.dumpTable(tableNameOrId, stream);
411     }
412
413     protected void dumpTable(String JavaDoc tableNameOrId, String JavaDoc[][] table) {
414         tester.dumpTable(tableNameOrId, table);
415     }
416
417 }
418
Popular Tags