KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * User: djoiner
3  * Date: Sep 9, 2002
4  * Time: 3:15:10 PM
5  */

6 package net.sourceforge.jwebunit;
7
8 public class FormAssertionsTest extends JWebUnitTest {
9
10     public void setUp() throws Exception JavaDoc {
11         super.setUp();
12         addTestPage();
13         beginAt("/testPage.html");
14     }
15
16     public void testAssertFormParameterPresent() throws Throwable JavaDoc {
17         assertPassFail("assertFormElementPresent", "testInputElement", "noSuchElement");
18         assertPass("assertFormElementPresent", "checkboxselected");
19         assertPass("assertFormElementEmpty", "testInputElement2");
20     }
21
22     public void testAssertFormParameterNotPresent() throws Throwable JavaDoc {
23         assertPassFail("assertFormElementNotPresent", "noSuchElement", "testInputElement");
24     }
25
26     public void testAssertFormParameterPresentWithLabel() throws Throwable JavaDoc {
27         assertPassFail("assertFormElementPresentWithLabel", "Test Input", "No Such Label");
28         assertFail("assertFormElementPresentWithLabel", "This is a test page");
29     }
30
31     public void testAssertFormParameterNotPresentWithLabel() throws Throwable JavaDoc {
32         assertPassFail("assertFormElementNotPresentWithLabel", "No Such Label", "Test Input");
33         assertPass("assertFormElementNotPresentWithLabel", "This is a test page");
34     }
35
36     public void testAssertHasForm() throws Throwable JavaDoc {
37         assertPass("assertFormPresent", NOARGS);
38         beginAt("/noFormPage.html");
39         assertFail("assertFormPresent", NOARGS);
40         assertPass("assertFormNotPresent", NOARGS);
41     }
42
43     public void testAssertHasNamedForm() throws Throwable JavaDoc {
44         assertPass("assertFormPresent", new String JavaDoc[]{"form2"});
45         assertFail("assertFormPresent", new String JavaDoc[]{"noform"});
46         assertPass("assertFormNotPresent", new String JavaDoc[]{"noform"});
47     }
48
49     public void testAssertFormParameterEquals() throws Throwable JavaDoc {
50         assertPass("assertFormElementEquals", new Object JavaDoc[]{"testInputElement", "testValue"});
51         assertFail("assertFormElementEquals", new Object JavaDoc[]{"testInputElement", "noSuchValue"});
52         assertFail("assertFormElementEquals", new Object JavaDoc[]{"noSuchElement", "testValue"});
53     }
54
55     public void testCheckboxSelected() throws Throwable JavaDoc {
56         assertPassFail("assertCheckboxSelected", "checkboxselected", "checkboxnotselected");
57         assertFail("assertCheckboxSelected", "nosuchbox");
58     }
59
60     public void testCheckboxNotSelected() throws Throwable JavaDoc {
61         assertPassFail("assertCheckboxNotSelected", "checkboxnotselected", "checkboxselected");
62         assertFail("assertCheckboxNotSelected", "nosuchbox");
63     }
64
65     public void testAssertSubmitButtonPresent() throws Throwable JavaDoc {
66         assertPassFail("assertSubmitButtonPresent", "submitButton", "noSuchButton");
67     }
68
69     public void testAssertSubmitButtonNotPresent() throws Throwable JavaDoc {
70         assertPassFail("assertSubmitButtonNotPresent", "noSuchButton", "submitButton");
71     }
72
73     public void testAssertSubmitButtonValue() throws Throwable JavaDoc {
74         assertPassFail("assertSubmitButtonValue",
75                 new Object JavaDoc[]{"submitButton", "buttonLabel"},
76                 new Object JavaDoc[]{"submitButton", "noSuchLabel"});
77     }
78
79     public void testAssertRadioOptionPresent() throws Throwable JavaDoc {
80         assertPassFail("assertRadioOptionPresent",
81                 new String JavaDoc[]{"cool", "cat"},
82                 new String JavaDoc[]{"cool", "fish"});
83     }
84
85     public void testAssertRadioOptionNotPresent() throws Throwable JavaDoc {
86         assertPassFail("assertRadioOptionNotPresent",
87                 new String JavaDoc[]{"cool", "fish"},
88                 new String JavaDoc[]{"cool", "cat"});
89     }
90
91     public void testAssertRadioOptionSelected() throws Throwable JavaDoc {
92         assertPassFail("assertRadioOptionSelected",
93                 new String JavaDoc[]{"cool", "dog"},
94                 new String JavaDoc[]{"cool", "cat"});
95     }
96
97     public void testAssertRadioOptionNotSelected() throws Throwable JavaDoc {
98         assertPassFail("assertRadioOptionNotSelected", new String JavaDoc[]{"cool", "cat"}, new String JavaDoc[]{"cool", "dog"});
99     }
100
101     public void testAssertOptionsEqual() throws Throwable JavaDoc {
102         assertPass("assertOptionsEqual", new Object JavaDoc[]{"select1", new String JavaDoc[]{"one", "two", "three", "four"}});
103         assertFail("assertOptionsEqual", new Object JavaDoc[]{"select1", new String JavaDoc[]{"one", "four", "three", "two"}});
104         assertFail("assertOptionsEqual", new Object JavaDoc[]{"select1", new String JavaDoc[]{"one", "two", "three", "four", "five"}});
105     }
106
107     public void testAssertOptionsNotEqual() throws Throwable JavaDoc {
108         assertFail("assertOptionsNotEqual", new Object JavaDoc[]{"select1", new String JavaDoc[]{"one", "two", "three", "four"}});
109         assertPass("assertOptionsNotEqual", new Object JavaDoc[]{"select1", new String JavaDoc[]{"one", "four", "three", "two"}});
110         assertPass("assertOptionsNotEqual", new Object JavaDoc[]{"select1", new String JavaDoc[]{"one", "two", "three", "four", "five"}});
111     }
112
113     public void testAssertOptionValuesEqual() throws Throwable JavaDoc {
114         assertPass("assertOptionValuesEqual", new Object JavaDoc[]{"select1", new String JavaDoc[]{"1", "2", "3", "4"}});
115         assertFail("assertOptionValuesEqual", new Object JavaDoc[]{"select1", new String JavaDoc[]{"1", "4", "3", "2"}});
116         assertFail("assertOptionValuesEqual", new Object JavaDoc[]{"select1", new String JavaDoc[]{"1", "2", "3", "4", "5"}});
117     }
118
119     public void testAssertOptionValuesNotEqual() throws Throwable JavaDoc {
120         assertFail("assertOptionValuesNotEqual", new Object JavaDoc[]{"select1", new String JavaDoc[]{"1", "2", "3", "4"}});
121         assertPass("assertOptionValuesNotEqual", new Object JavaDoc[]{"select1", new String JavaDoc[]{"1", "4", "3", "2"}});
122         assertPass("assertOptionValuesNotEqual", new Object JavaDoc[]{"select1", new String JavaDoc[]{"1", "2", "3", "4", "5"}});
123     }
124
125     public void testAssertSelectedOptionEquals() throws Throwable JavaDoc {
126         assertPassFail("assertOptionEquals", new String JavaDoc[]{"select1", "one"}, new String JavaDoc[]{"select1", "two"});
127     }
128
129     public void testAssertButtonPresent() throws Throwable JavaDoc {
130         assertPassFail("assertButtonPresent", "b1", "nobutton");
131     }
132
133     public void testAssertButtonNotPresent() throws Throwable JavaDoc {
134         assertPassFail("assertButtonNotPresent", "nobutton", "b1");
135     }
136     
137     private void addTestPage() {
138         defineWebPage("testPage", "This is a test page." +
139                 "<table summary=\"testTable\">" +
140                 "<tr><td>table text</td></tr>" +
141                 "<tr><td>table text row 2</td></tr>" +
142                 "<tr><td>table text row 3</td><td>row 3 col 1</td>" +
143                 "<a HREF=\"someurl.html\">test link</a>" +
144                 "<form id=\"form1\">" +
145                 "<input type=\"button\" id=\"b1\"/>" +
146                 "<select name=\"selectOption\"><option value=\"1\">One</option><option value=\"2\">Two</option><option value=\"3\">Three</option></select>" +
147                 "Test Input : <input type=\"text\" name=\"testInputElement\" value=\"testValue\"/>" +
148                 "Test Input 2: <input type=\"text\" name=\"testInputElement2\" value=\"\"/>" +
149                 "<input type=\"submit\" name=\"submitButton\" value=\"buttonLabel\"/>" +
150                 "<input type=\"checkbox\" name=\"checkboxselected\" CHECKED>" +
151                 "<input type=\"checkbox\" name=\"checkboxnotselected\">" +
152                 "<textarea name=\"text\" cols=\"44\" rows=\"3\" wrap=\"VIRTUAL\"></textarea>" +
153                 "</form>" +
154                 "<form name=\"form2\"></form>" +
155                 "<form id=\"form3\">" +
156                 "<input type=\"radio\" name=\"cool\" value=\"dog\" checked=\"checked\"/>" +
157                 "<input type=\"radio\" name=\"cool\" value=\"cat\"/>" +
158                 "<input type=\"radio\" name=\"cool\" value=\"chicken\"/>" +
159                 "</form>" +
160                 "<form id=\"form4\">" +
161                 "<select name=\"select1\">" +
162                 "<option value=\"1\">one</option>" +
163                 "<option value=\"2\">two</option>" +
164                 "<option value=\"3\">three</option>" +
165                 "<option value=\"4\">four</option>" +
166                 "</select>" +
167                 "</form>" +
168                 "</table>");
169         defineWebPage("noFormPage", "");
170     }
171
172 }
173
Popular Tags