KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > strutsel > taglib > html > TestELCheckboxTag


1 /*
2  * $Id: TestELCheckboxTag.java 54933 2004-10-16 17:04:52Z germuska $
3  *
4  * Copyright 1999-2004 The Apache Software Foundation.
5  *
6  * Licensed under the Apache License, Version 2.0 (the "License");
7  * you may not use this file except in compliance with the License.
8  * You may obtain a copy of the License at
9  *
10  * http://www.apache.org/licenses/LICENSE-2.0
11  *
12  * Unless required by applicable law or agreed to in writing, software
13  * distributed under the License is distributed on an "AS IS" BASIS,
14  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15  * See the License for the specific language governing permissions and
16  * limitations under the License.
17  */

18
19 package org.apache.strutsel.taglib.html;
20
21 import java.util.HashMap JavaDoc;
22
23 import javax.servlet.ServletException JavaDoc;
24 import javax.servlet.http.HttpServletResponse JavaDoc;
25 import javax.servlet.jsp.JspException JavaDoc;
26 import junit.framework.Test;
27 import junit.framework.TestSuite;
28
29 import org.apache.strutsel.taglib.utils.DOMHelper;
30 import org.apache.strutsel.taglib.utils.JspTagTestCase;
31 import org.apache.strutsel.taglib.utils.TestFormBean;
32 import org.apache.strutsel.taglib.utils.TestHelper;
33
34 public class TestELCheckboxTag
35     extends JspTagTestCase {
36     protected static final String JavaDoc PROPERTY_ATTR_VALUE =
37         "stringProperty";
38     protected static final String JavaDoc REQUIRED_CHECKED_VALUE_KEY =
39             "RequiredCheckedValue";
40     protected static final String JavaDoc REQUIRED_DISABLED_VALUE_KEY =
41             "RequiredDisabledValue";
42     protected static final String JavaDoc REQUIRED_NAME_VALUE_KEY =
43             "RequiredNameValue";
44     protected static final String JavaDoc REQUIRED_TYPE_VALUE_KEY =
45             "RequiredTypeValue";
46     protected static final String JavaDoc REQUIRED_VALUE_VALUE_KEY =
47             "RequiredValueValue";
48     protected ELCheckboxTag elCheckboxTag = null;
49
50     public TestELCheckboxTag(String JavaDoc theName) {
51         super(theName);
52     }
53
54     public static void main(String JavaDoc[] args) {
55         junit.awtui.TestRunner.main(
56                 new String JavaDoc[] { TestELCheckboxTag.class.getName() });
57     }
58
59     public static Test suite() {
60         return new TestSuite(TestELCheckboxTag.class);
61     }
62
63     public void setUp() {
64         elCheckboxTag = new ELCheckboxTag();
65         elCheckboxTag.setPageContext(pageContext);
66         elCheckboxTag.setPropertyExpr(PROPERTY_ATTR_VALUE);
67     }
68
69     public void tearDown() {
70         elCheckboxTag = null;
71     }
72
73     /**
74      * Tests a plain "checkbox" tag, with the "property" attribute set to a
75      * plain value.
76      */

77     public void testPlain()
78                    throws ServletException JavaDoc, JspException JavaDoc {
79         HttpServletResponse JavaDoc response = (HttpServletResponse JavaDoc)pageContext.getResponse();
80         String JavaDoc requiredNameValue = PROPERTY_ATTR_VALUE;
81         response.addHeader(REQUIRED_NAME_VALUE_KEY, requiredNameValue);
82
83         String JavaDoc requiredTypeValue = "checkbox";
84         response.addHeader(REQUIRED_TYPE_VALUE_KEY, requiredTypeValue);
85
86         String JavaDoc requiredValueValue = "on";
87         response.addHeader(REQUIRED_VALUE_VALUE_KEY, requiredValueValue);
88
89         TestFormBean formBean = new TestFormBean();
90         pageContext.setAttribute("testFormBean", formBean);
91
92         elCheckboxTag.setNameExpr("testFormBean");
93
94         int startTagReturn = elCheckboxTag.doStartTag();
95         int afterBodyReturn = elCheckboxTag.doAfterBody();
96         int endTagReturn = elCheckboxTag.doEndTag();
97     }
98
99     public void endPlain(com.meterware.httpunit.WebResponse testResponse) {
100         try {
101             TestHelper.printResponse(testResponse);
102             DOMHelper.printNode(testResponse.getDOM().getDocumentElement());
103
104             HashMap JavaDoc attrMap = new HashMap JavaDoc();
105             DOMHelper.recordFoundAttributes(testResponse.getDOM(),
106                                             "/html/body/input", attrMap);
107             DOMHelper.verifyAttributesPresent(attrMap,
108                                               new String JavaDoc[] {
109                 "name", "type", "value"
110             }, false);
111             checkAttrValue(attrMap, testResponse, REQUIRED_NAME_VALUE_KEY,
112                            "checkbox", "name");
113             checkAttrValue(attrMap, testResponse, REQUIRED_TYPE_VALUE_KEY,
114                            "checkbox", "type");
115             checkAttrValue(attrMap, testResponse, REQUIRED_VALUE_VALUE_KEY,
116                            "checkbox", "value");
117         } catch (Exception JavaDoc ex) {
118             ex.printStackTrace();
119             fail();
120         }
121     }
122
123 // /**
124
// * Tests the "property" attribute referencing an indexed value, verifying
125
// * it emits the "checked" attribute.
126
// */
127
// public void testCollectionProperty()
128
// throws ServletException, JspException {
129
// HttpServletResponse response = (HttpServletResponse)pageContext.getResponse();
130
// elCheckboxTag.setName(PROPERTY_ATTR_VALUE + "[1]");
131

132 // String requiredNameValue = PROPERTY_ATTR_VALUE + "[1]";
133
// response.addHeader(REQUIRED_NAME_VALUE_KEY, requiredNameValue);
134

135 // String requiredTypeValue = "checkbox";
136
// response.addHeader(REQUIRED_TYPE_VALUE_KEY, requiredTypeValue);
137

138 // String requiredValueValue = "on";
139
// response.addHeader(REQUIRED_VALUE_VALUE_KEY, requiredValueValue);
140

141 // String requiredCheckedValue = "checked";
142
// response.addHeader(REQUIRED_CHECKED_VALUE_KEY, requiredCheckedValue);
143

144 // ArrayList list = new ArrayList();
145
// list.add("off");
146
// list.add("on");
147
// pageContext.setAttribute(PROPERTY_ATTR_VALUE, list,
148
// PageContext.PAGE_SCOPE);
149

150 // int startTagReturn = elCheckboxTag.doStartTag();
151
// int afterBodyReturn = elCheckboxTag.doAfterBody();
152
// int endTagReturn = elCheckboxTag.doEndTag();
153
// }
154

155 // public void endCollectionProperty(com.meterware.httpunit.WebResponse testResponse) {
156
// try {
157
// TestHelper.printResponse(testResponse);
158

159 // Element docElement = testResponse.getDOM().getDocumentElement();
160
// DOMHelper.printNode(docElement);
161

162 // HashMap attrMap = new HashMap();
163
// DOMHelper.recordFoundAttributes(testResponse.getDOM(),
164
// "/html/body/input", attrMap);
165
// DOMHelper.verifyAttributesPresent(attrMap,
166
// new String[] {
167
// "name", "type", "value", "checked"
168
// }, false);
169
// checkAttrValue(attrMap, testResponse, REQUIRED_NAME_VALUE_KEY,
170
// "checkbox", "name");
171
// checkAttrValue(attrMap, testResponse, REQUIRED_TYPE_VALUE_KEY,
172
// "checkbox", "type");
173
// checkAttrValue(attrMap, testResponse, REQUIRED_VALUE_VALUE_KEY,
174
// "checkbox", "value");
175
// checkAttrValue(attrMap, testResponse, REQUIRED_CHECKED_VALUE_KEY,
176
// "checkbox", "checked");
177
// } catch (Exception ex) {
178
// ex.printStackTrace();
179
// fail();
180
// }
181
// }
182

183 // /**
184
// * Tests the "property" attribute referencing an indexed value, verifying
185
// * it does not emit the "checked" attribute.
186
// */
187
// public void testCollectionPropertyNotChecked()
188
// throws ServletException,
189
// JspException {
190
// HttpServletResponse response = (HttpServletResponse)pageContext.getResponse();
191
// elCheckboxTag.setName(PROPERTY_ATTR_VALUE + "[0]");
192

193 // String requiredNameValue = PROPERTY_ATTR_VALUE + "[0]";
194
// response.addHeader(REQUIRED_NAME_VALUE_KEY, requiredNameValue);
195

196 // String requiredTypeValue = "checkbox";
197
// response.addHeader(REQUIRED_TYPE_VALUE_KEY, requiredTypeValue);
198

199 // String requiredValueValue = "on";
200
// response.addHeader(REQUIRED_VALUE_VALUE_KEY, requiredValueValue);
201

202 // ArrayList list = new ArrayList();
203
// list.add("off");
204
// list.add("on");
205
// pageContext.setAttribute(PROPERTY_ATTR_VALUE, list,
206
// PageContext.PAGE_SCOPE);
207

208 // int startTagReturn = elCheckboxTag.doStartTag();
209
// int afterBodyReturn = elCheckboxTag.doAfterBody();
210
// int endTagReturn = elCheckboxTag.doEndTag();
211
// }
212

213 // public void endCollectionPropertyNotChecked(com.meterware.httpunit.WebResponse testResponse) {
214
// try {
215
// TestHelper.printResponse(testResponse);
216

217 // Element docElement = testResponse.getDOM().getDocumentElement();
218
// DOMHelper.printNode(docElement);
219

220 // HashMap attrMap = new HashMap();
221
// DOMHelper.recordFoundAttributes(testResponse.getDOM(),
222
// "/html/body/input", attrMap);
223
// DOMHelper.verifyAttributesPresent(attrMap,
224
// new String[] {
225
// "name", "type", "value"
226
// }, false);
227
// DOMHelper.verifyAttributesNotPresent(attrMap,
228
// new String[] { "checked" });
229
// checkAttrValue(attrMap, testResponse, REQUIRED_NAME_VALUE_KEY,
230
// "checkbox", "name");
231
// checkAttrValue(attrMap, testResponse, REQUIRED_TYPE_VALUE_KEY,
232
// "checkbox", "type");
233
// checkAttrValue(attrMap, testResponse, REQUIRED_VALUE_VALUE_KEY,
234
// "checkbox", "value");
235
// } catch (Exception ex) {
236
// ex.printStackTrace();
237
// fail();
238
// }
239
// }
240

241 // /**
242
// * Tests the "disabled" attribute.
243
// */
244
// public void testDisabled()
245
// throws ServletException, JspException {
246

247 // elCheckboxTag.setDisabled(true);
248

249 // String requiredDisabledValue = "disabled";
250
// response.addHeader(REQUIRED_DISABLED_VALUE_KEY, requiredDisabledValue);
251
// elCheckboxTag.setName("flork");
252

253 // int startTagReturn = elCheckboxTag.doStartTag();
254
// int afterBodyReturn = elCheckboxTag.doAfterBody();
255
// int endTagReturn = elCheckboxTag.doEndTag();
256
// }
257

258 // public void endDisabled(com.meterware.httpunit.WebResponse testResponse) {
259
// try {
260
// TestHelper.printResponse(testResponse);
261

262 // Element docElement = testResponse.getDOM().getDocumentElement();
263
// DOMHelper.printNode(docElement);
264

265 // HashMap attrMap = new HashMap();
266
// DOMHelper.recordFoundAttributes(testResponse.getDOM(),
267
// "/html/body/input", attrMap);
268
// DOMHelper.verifyAttributesPresent(attrMap,
269
// new String[] { "disabled" },
270
// true);
271
// checkAttrValue(attrMap, testResponse, REQUIRED_DISABLED_VALUE_KEY,
272
// "checkbox", "disabled");
273
// } catch (Exception ex) {
274
// ex.printStackTrace();
275
// fail();
276
// }
277
// }
278

279 // /**
280
// * Tests the "property" and "checked" attributes, using a simple value in
281
// * page scope.
282
// */
283
// public void testProperty()
284
// throws ServletException, JspException {
285
// HttpServletResponse response = (HttpServletResponse)pageContext.getResponse();
286
// String requiredNameValue = PROPERTY_ATTR_VALUE;
287
// response.addHeader(REQUIRED_NAME_VALUE_KEY, requiredNameValue);
288

289 // String requiredTypeValue = "checkbox";
290
// response.addHeader(REQUIRED_TYPE_VALUE_KEY, requiredTypeValue);
291

292 // String requiredValueValue = "on";
293
// response.addHeader(REQUIRED_VALUE_VALUE_KEY, requiredValueValue);
294

295 // String requiredCheckedValue = "checked";
296
// response.addHeader(REQUIRED_CHECKED_VALUE_KEY, requiredCheckedValue);
297
// pageContext.setAttribute(PROPERTY_ATTR_VALUE, "on",
298
// PageContext.PAGE_SCOPE);
299

300 // int startTagReturn = elCheckboxTag.doStartTag();
301
// int afterBodyReturn = elCheckboxTag.doAfterBody();
302
// int endTagReturn = elCheckboxTag.doEndTag();
303
// }
304

305 // public void endProperty(com.meterware.httpunit.WebResponse testResponse) {
306
// try {
307
// TestHelper.printResponse(testResponse);
308

309 // Element docElement = testResponse.getDOM().getDocumentElement();
310
// DOMHelper.printNode(docElement);
311

312 // HashMap attrMap = new HashMap();
313
// DOMHelper.recordFoundAttributes(testResponse.getDOM(),
314
// "/html/body/input", attrMap);
315
// DOMHelper.verifyAttributesPresent(attrMap,
316
// new String[] {
317
// "name", "type", "value", "checked"
318
// }, false);
319

320 // checkAttrValue(attrMap, testResponse, REQUIRED_NAME_VALUE_KEY,
321
// "checkbox", "name");
322
// checkAttrValue(attrMap, testResponse, REQUIRED_TYPE_VALUE_KEY,
323
// "checkbox", "type");
324
// checkAttrValue(attrMap, testResponse, REQUIRED_VALUE_VALUE_KEY,
325
// "checkbox", "value");
326
// checkAttrValue(attrMap, testResponse, REQUIRED_CHECKED_VALUE_KEY,
327
// "checkbox", "checked");
328
// } catch (Exception ex) {
329
// ex.printStackTrace();
330
// fail();
331
// }
332
// }
333
}
334
Popular Tags