KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: TestELErrorsTag.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 junit.framework.Test;
22 import junit.framework.TestSuite;
23 import org.apache.commons.logging.Log;
24 import org.apache.commons.logging.LogFactory;
25 import org.apache.strutsel.taglib.utils.JspTagTestCase;
26
27
28 public class TestELErrorsTag
29     extends JspTagTestCase {
30     protected static final String JavaDoc FOOTER_VALUE = "zzz";
31     protected static final String JavaDoc HEADER_VALUE = "aaa";
32     protected static final String JavaDoc PREFIX_VALUE = "[[[";
33     protected static final String JavaDoc PROPERTY_KEY = "property";
34     protected static final String JavaDoc REQUIRED_TEXT_VALUE_KEY =
35             "RequiredTextValue";
36     protected static final String JavaDoc SUFFIX_VALUE = "]]]";
37     protected static final String JavaDoc XXX_VALUE = "xxx";
38     protected static final String JavaDoc YYY_VALUE = "yyy";
39     protected ELErrorsTag elErrorsTag = null;
40     private static Log log =
41             LogFactory.getLog(TestELErrorsTag.class);
42
43     public TestELErrorsTag(String JavaDoc theName) {
44         super(theName);
45     }
46
47     public static void main(String JavaDoc[] args) {
48         junit.awtui.TestRunner.main(
49                 new String JavaDoc[] { TestELErrorsTag.class.getName() });
50     }
51
52     public static Test suite() {
53         return new TestSuite(TestELErrorsTag.class);
54     }
55
56     public void setUp() {
57         elErrorsTag = new ELErrorsTag();
58         elErrorsTag.setPageContext(pageContext);
59     }
60
61     public void testDummy()
62     {
63     }
64
65 // /**
66
// * Tests simple global error with all tag attributes set to default, and no
67
// * header, footer, prefix or suffix.
68
// */
69
// public void testPlain()
70
// throws ServletException, JspException {
71
// HashMapMessageResources messageResources = new HashMapMessageResources(
72
// null, null, true);
73
// messageResources.addMessage("error.misc", XXX_VALUE);
74
// String bundle = elErrorsTag.getBundle();
75
// if (bundle == null)
76
// bundle = Action.MESSAGES_KEY;
77
// pageContext.setAttribute(bundle, messageResources,
78
// PageContext.APPLICATION_SCOPE);
79

80 // ActionErrors errors = new ActionErrors();
81
// ActionError error = new ActionError("error.misc");
82
// errors.add(ActionErrors.GLOBAL_ERROR, error);
83
// pageContext.setAttribute(elErrorsTag.getName(), errors,
84
// PageContext.REQUEST_SCOPE);
85

86 // HttpServletResponse response = (HttpServletResponse)pageContext.getResponse();
87
// String requiredText = XXX_VALUE;
88
// response.addHeader(REQUIRED_TEXT_VALUE_KEY, requiredText);
89

90 // System.out.println("pageContext[" + pageContext + "]");
91
// System.out.println("name[" + elErrorsTag.getName() + "]");
92
// System.out.println("request[" + pageContext.getRequest() + "]");
93
// System.out.println("session[" + pageContext.getSession() + "]");
94
// int startTagReturn = elErrorsTag.doStartTag();
95
// int afterBodyReturn = elErrorsTag.doAfterBody();
96
// int endTagReturn = elErrorsTag.doEndTag();
97
// }
98

99 // public void endPlain(com.meterware.httpunit.WebResponse testResponse) {
100
// try {
101
// TestHelper.printResponse(testResponse);
102

103 // org.w3c.dom.Document document = testResponse.getDOM();
104
// DOMHelper.printNode(document.getDocumentElement());
105

106 // String nodeText = DOMHelper.getNodeText(document, "/html/body");
107
// log.debug("nodeText[" + nodeText + "]");
108

109 // String requiredTextValue = (String)testResponse.getHeaderField(
110
// REQUIRED_TEXT_VALUE_KEY);
111

112 // if (!nodeText.equals(requiredTextValue)) {
113
// fail("The <errors> tag instance should have resulted " +
114
// "in the text " + "\"" + requiredTextValue +
115
// "\", but instead had the value \"" + nodeText + "\".");
116
// }
117
// } catch (Exception ex) {
118
// ex.printStackTrace();
119
// fail();
120
// }
121
// }
122

123 // /**
124
// * Tests multiple errors put in errors list, with two different property
125
// * names, but referring to the same error, but still using the default
126
// * value of "property", which will cause both errors to be retrieved.
127
// */
128
// public void testMultiProperties()
129
// throws ServletException, JspException {
130
// HashMapMessageResources messageResources = new HashMapMessageResources(
131
// null, null, true);
132
// messageResources.addMessage("error.misc", XXX_VALUE);
133
// String bundle = elErrorsTag.getBundle();
134
// if (bundle == null)
135
// bundle = Action.MESSAGES_KEY;
136
// pageContext.setAttribute(bundle, messageResources,
137
// PageContext.APPLICATION_SCOPE);
138

139 // ActionErrors errors = new ActionErrors();
140
// ActionError error = new ActionError("error.misc");
141
// errors.add(PROPERTY_KEY + "1", error);
142
// errors.add(PROPERTY_KEY + "2", error);
143
// pageContext.setAttribute(elErrorsTag.getName(), errors,
144
// PageContext.REQUEST_SCOPE);
145

146 // HttpServletResponse response = (HttpServletResponse)pageContext.getResponse();
147
// String requiredText = XXX_VALUE + " " + XXX_VALUE;
148
// response.addHeader(REQUIRED_TEXT_VALUE_KEY, requiredText);
149

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

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

159 // org.w3c.dom.Document document = testResponse.getDOM();
160
// DOMHelper.printNode(document.getDocumentElement());
161

162 // String nodeText = DOMHelper.getNodeText(document, "/html/body");
163
// log.debug("nodeText[" + nodeText + "]");
164

165 // String requiredTextValue = (String)testResponse.getHeaderField(
166
// REQUIRED_TEXT_VALUE_KEY);
167

168 // if (!nodeText.equals(requiredTextValue)) {
169
// fail("The <errors> tag instance should have resulted " +
170
// "in the text " + "\"" + requiredTextValue +
171
// "\", but instead had the value \"" + nodeText + "\".");
172
// }
173
// } catch (Exception ex) {
174
// ex.printStackTrace();
175
// fail();
176
// }
177
// }
178

179 // /**
180
// * Tests putting in two errors in errors list, with two different property
181
// * names, and referring to two different error keys, and the "property"
182
// * attribute set to only one of them.
183
// */
184
// public void testOnlyWantOneProperty()
185
// throws ServletException, JspException {
186
// elErrorsTag.setPropertyExpr(PROPERTY_KEY + "2");
187

188 // HashMapMessageResources messageResources = new HashMapMessageResources(
189
// null, null, true);
190
// messageResources.addMessage("error1.misc", XXX_VALUE);
191
// messageResources.addMessage("error2.misc", YYY_VALUE);
192
// String bundle = elErrorsTag.getBundle();
193
// if (bundle == null)
194
// bundle = Action.MESSAGES_KEY;
195
// pageContext.setAttribute(bundle, messageResources,
196
// PageContext.APPLICATION_SCOPE);
197

198 // ActionErrors errors = new ActionErrors();
199
// errors.add(PROPERTY_KEY + "1", new ActionError("error1.misc"));
200
// errors.add(PROPERTY_KEY + "2", new ActionError("error2.misc"));
201
// pageContext.setAttribute(elErrorsTag.getName(), errors,
202
// PageContext.REQUEST_SCOPE);
203

204 // HttpServletResponse response = (HttpServletResponse)pageContext.getResponse();
205
// String requiredText = YYY_VALUE;
206
// response.addHeader(REQUIRED_TEXT_VALUE_KEY, requiredText);
207

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

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

217 // org.w3c.dom.Document document = testResponse.getDOM();
218
// DOMHelper.printNode(document.getDocumentElement());
219

220 // String nodeText = DOMHelper.getNodeText(document, "/html/body");
221
// log.debug("nodeText[" + nodeText + "]");
222

223 // String requiredTextValue = (String)testResponse.getHeaderField(
224
// REQUIRED_TEXT_VALUE_KEY);
225

226 // if (!nodeText.equals(requiredTextValue)) {
227
// fail("The <errors> tag instance should have resulted " +
228
// "in the text " + "\"" + requiredTextValue +
229
// "\", but instead had the value \"" + nodeText + "\".");
230
// }
231
// } catch (Exception ex) {
232
// ex.printStackTrace();
233
// fail();
234
// }
235
// }
236

237 // /**
238
// * Tests one error on a specific property, with "property" attribute set to
239
// * default.
240
// */
241
// public void testProperty()
242
// throws ServletException, JspException {
243
// HashMapMessageResources messageResources = new HashMapMessageResources(
244
// null, null, true);
245
// messageResources.addMessage("error.misc", XXX_VALUE);
246
// String bundle = elErrorsTag.getBundle();
247
// if (bundle == null)
248
// bundle = Action.MESSAGES_KEY;
249
// pageContext.setAttribute(bundle, messageResources,
250
// PageContext.APPLICATION_SCOPE);
251

252 // ActionErrors errors = new ActionErrors();
253
// ActionError error = new ActionError("error.misc");
254
// errors.add(PROPERTY_KEY, error);
255
// pageContext.setAttribute(elErrorsTag.getName(), errors,
256
// PageContext.REQUEST_SCOPE);
257

258 // HttpServletResponse response = (HttpServletResponse)pageContext.getResponse();
259
// String requiredText = XXX_VALUE;
260
// response.addHeader(REQUIRED_TEXT_VALUE_KEY, requiredText);
261

262 // int startTagReturn = elErrorsTag.doStartTag();
263
// int afterBodyReturn = elErrorsTag.doAfterBody();
264
// int endTagReturn = elErrorsTag.doEndTag();
265
// }
266

267 // public void endProperty(com.meterware.httpunit.WebResponse testResponse) {
268
// try {
269
// TestHelper.printResponse(testResponse);
270

271 // org.w3c.dom.Document document = testResponse.getDOM();
272
// DOMHelper.printNode(document.getDocumentElement());
273

274 // String nodeText = DOMHelper.getNodeText(document, "/html/body");
275
// log.debug("nodeText[" + nodeText + "]");
276

277 // String requiredTextValue = (String)testResponse.getHeaderField(
278
// REQUIRED_TEXT_VALUE_KEY);
279

280 // if (!nodeText.equals(requiredTextValue)) {
281
// fail("The <errors> tag instance should have resulted " +
282
// "in the text " + "\"" + requiredTextValue +
283
// "\", but instead had the value \"" + nodeText + "\".");
284
// }
285
// } catch (Exception ex) {
286
// ex.printStackTrace();
287
// fail();
288
// }
289
// }
290

291 // /**
292
// * Just like "testPropertySpecified", but the "property" value is an EL
293
// * expression, evaluating to the same value as in the other test.
294
// */
295
// public void testPropertySpecifiedEL()
296
// throws ServletException, JspException {
297
// String varName = "targetVar";
298
// pageContext.setAttribute(varName, PROPERTY_KEY);
299
// elErrorsTag.setPropertyExpr("${" + varName + "}");
300
// testPropertySpecified();
301
// }
302

303 // public void endPropertySpecifiedEL(com.meterware.httpunit.WebResponse testResponse) {
304
// endPropertySpecified(testResponse);
305
// }
306

307 // /**
308
// * Tests one error in errors list, set to a property, and the "property"
309
// * attribute set to that property key.
310
// */
311
// public void testPropertySpecified()
312
// throws ServletException, JspException {
313
// elErrorsTag.setPropertyExpr(PROPERTY_KEY);
314

315 // HashMapMessageResources messageResources = new HashMapMessageResources(
316
// null, null, true);
317
// messageResources.addMessage("error.misc", XXX_VALUE);
318
// String bundle = elErrorsTag.getBundle();
319
// if (bundle == null)
320
// bundle = Action.MESSAGES_KEY;
321
// pageContext.setAttribute(bundle, messageResources,
322
// PageContext.APPLICATION_SCOPE);
323

324 // ActionErrors errors = new ActionErrors();
325
// ActionError error = new ActionError("error.misc");
326
// errors.add(PROPERTY_KEY, error);
327
// pageContext.setAttribute(elErrorsTag.getName(), errors,
328
// PageContext.REQUEST_SCOPE);
329

330 // HttpServletResponse response = (HttpServletResponse)pageContext.getResponse();
331
// String requiredText = XXX_VALUE;
332
// response.addHeader(REQUIRED_TEXT_VALUE_KEY, requiredText);
333

334 // int startTagReturn = elErrorsTag.doStartTag();
335
// int afterBodyReturn = elErrorsTag.doAfterBody();
336
// int endTagReturn = elErrorsTag.doEndTag();
337
// }
338

339 // public void endPropertySpecified(com.meterware.httpunit.WebResponse testResponse) {
340
// try {
341
// TestHelper.printResponse(testResponse);
342

343 // org.w3c.dom.Document document = testResponse.getDOM();
344
// DOMHelper.printNode(document.getDocumentElement());
345

346 // String nodeText = DOMHelper.getNodeText(document, "/html/body");
347
// log.debug("nodeText[" + nodeText + "]");
348

349 // String requiredTextValue = (String)testResponse.getHeaderField(
350
// REQUIRED_TEXT_VALUE_KEY);
351

352 // if (!nodeText.equals(requiredTextValue)) {
353
// fail("The <errors> tag instance should have resulted " +
354
// "in the text " + "\"" + requiredTextValue +
355
// "\", but instead had the value \"" + nodeText + "\".");
356
// }
357
// } catch (Exception ex) {
358
// ex.printStackTrace();
359
// fail();
360
// }
361
// }
362

363 // /**
364
// * Tests one error in the errors list, set to a property, and the
365
// * "property" attribute set to a different property key.
366
// */
367
// public void testPropertySpecifiedWrong()
368
// throws ServletException, JspException {
369
// elErrorsTag.setPropertyExpr(PROPERTY_KEY + "x");
370

371 // HashMapMessageResources messageResources = new HashMapMessageResources(
372
// null, null, true);
373
// messageResources.addMessage("error.misc", XXX_VALUE);
374
// String bundle = elErrorsTag.getBundle();
375
// if (bundle == null)
376
// bundle = Action.MESSAGES_KEY;
377
// pageContext.setAttribute(bundle, messageResources,
378
// PageContext.APPLICATION_SCOPE);
379

380 // ActionErrors errors = new ActionErrors();
381
// ActionError error = new ActionError("error.misc");
382
// errors.add(PROPERTY_KEY, error);
383
// pageContext.setAttribute(elErrorsTag.getName(), errors,
384
// PageContext.REQUEST_SCOPE);
385

386 // HttpServletResponse response = (HttpServletResponse)pageContext.getResponse();
387
// String requiredText = "";
388
// response.addHeader(REQUIRED_TEXT_VALUE_KEY, requiredText);
389

390 // int startTagReturn = elErrorsTag.doStartTag();
391
// int afterBodyReturn = elErrorsTag.doAfterBody();
392
// int endTagReturn = elErrorsTag.doEndTag();
393
// }
394

395 // public void endPropertySpecifiedWrong(com.meterware.httpunit.WebResponse testResponse) {
396
// try {
397
// TestHelper.printResponse(testResponse);
398

399 // org.w3c.dom.Document document = testResponse.getDOM();
400
// DOMHelper.printNode(document.getDocumentElement());
401

402 // String nodeText = DOMHelper.getNodeText(document, "/html/body");
403
// log.debug("nodeText[" + nodeText + "]");
404

405 // String requiredTextValue = (String)testResponse.getHeaderField(
406
// REQUIRED_TEXT_VALUE_KEY);
407

408 // if (!nodeText.equals(requiredTextValue)) {
409
// fail("The <errors> tag instance should have resulted " +
410
// "in the text " + "\"" + requiredTextValue +
411
// "\", but instead had the value \"" + nodeText + "\".");
412
// }
413
// } catch (Exception ex) {
414
// ex.printStackTrace();
415
// fail();
416
// }
417
// }
418

419 // public void tearDown() {
420
// elErrorsTag = null;
421
// }
422

423 // /**
424
// * Tests a single error in errors list, with the "header" and "footer"
425
// * resource set to non-empty strings.
426
// */
427
// public void testHeaderFooter()
428
// throws ServletException, JspException {
429
// HashMapMessageResources messageResources = new HashMapMessageResources(
430
// null, null, true);
431
// messageResources.addMessage("error.misc", XXX_VALUE);
432
// messageResources.addMessage("errors.header", HEADER_VALUE);
433
// messageResources.addMessage("errors.footer", FOOTER_VALUE);
434
// String bundle = elErrorsTag.getBundle();
435
// if (bundle == null)
436
// bundle = Action.MESSAGES_KEY;
437
// pageContext.setAttribute(bundle, messageResources,
438
// PageContext.APPLICATION_SCOPE);
439

440 // ActionErrors errors = new ActionErrors();
441
// ActionError error = new ActionError("error.misc");
442
// errors.add(ActionErrors.GLOBAL_ERROR, error);
443
// pageContext.setAttribute(elErrorsTag.getName(), errors,
444
// PageContext.REQUEST_SCOPE);
445

446 // HttpServletResponse response = (HttpServletResponse)pageContext.getResponse();
447
// String requiredText = HEADER_VALUE + " " + XXX_VALUE +
448
// " " + FOOTER_VALUE;
449
// response.addHeader(REQUIRED_TEXT_VALUE_KEY, requiredText);
450

451 // int startTagReturn = elErrorsTag.doStartTag();
452
// int afterBodyReturn = elErrorsTag.doAfterBody();
453
// int endTagReturn = elErrorsTag.doEndTag();
454
// }
455

456 // public void endHeaderFooter(com.meterware.httpunit.WebResponse testResponse) {
457
// try {
458
// TestHelper.printResponse(testResponse);
459

460 // org.w3c.dom.Document document = testResponse.getDOM();
461
// DOMHelper.printNode(document.getDocumentElement());
462

463 // String nodeText = DOMHelper.getNodeText(document, "/html/body");
464
// log.debug("nodeText[" + nodeText + "]");
465

466 // String requiredTextValue = (String)testResponse.getHeaderField(
467
// REQUIRED_TEXT_VALUE_KEY);
468

469 // if (!nodeText.equals(requiredTextValue)) {
470
// fail("The <errors> tag instance should have resulted " +
471
// "in the text " + "\"" + requiredTextValue +
472
// "\", but instead had the value \"" + nodeText + "\".");
473
// }
474
// } catch (Exception ex) {
475
// ex.printStackTrace();
476
// fail();
477
// }
478
// }
479
}
480
Popular Tags