KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > inversoft > verge > mvc > controller > form > config > test > FormMVCBuilderTest


1 /*
2  * Copyright (c) 2003, Inversoft
3  *
4  * This software is distribuable under the GNU Lesser General Public License.
5  * For more information visit gnu.org.
6  */

7 package com.inversoft.verge.mvc.controller.form.config.test;
8
9
10 import java.util.Collection JavaDoc;
11 import java.util.HashMap JavaDoc;
12 import java.util.Iterator JavaDoc;
13 import java.util.List JavaDoc;
14 import java.util.Map JavaDoc;
15
16 import org.jdom.Document;
17 import org.jdom.Element;
18
19 import com.inversoft.config.ConfigurationException;
20 import com.inversoft.junit.WebTestCase;
21 import com.inversoft.util.ReflectionException;
22 import com.inversoft.verge.mvc.config.BaseValidatorConfig;
23 import com.inversoft.verge.mvc.config.OverrideValidator;
24 import com.inversoft.verge.mvc.config.PropertyConfig;
25 import com.inversoft.verge.mvc.controller.form.config.Constants;
26 import com.inversoft.verge.mvc.controller.form.config.FormConfig;
27 import com.inversoft.verge.mvc.controller.form.config.FormMVCConfigBuilder;
28 import com.inversoft.verge.mvc.controller.form.config.FormMVCConfigRegistry;
29 import com.inversoft.verge.mvc.controller.form.config.ValidatorConfig;
30 import com.inversoft.verge.repository.config.RepositoryConfigRegistry;
31 import com.inversoft.verge.repository.test.RepositoryTest;
32 import com.inversoft.verge.util.WebBean;
33
34
35 /**
36  * <p>
37  * This class contains the TestCases for the form mvc builder
38  * </p>
39  *
40  * @author Brian Pontarelli
41  * @since 1.0
42  * @version 1.0
43  */

44 public class FormMVCBuilderTest extends WebTestCase {
45
46     /**
47      * Constructs a new <code>FormMVCBuilderTest</code> TestCase instance
48      */

49     public FormMVCBuilderTest(String JavaDoc name) {
50         super(name);
51         setLocal(true);
52     }
53
54
55     /**
56      * Tests the build method correctly builds an action config object
57      */

58     public void testBuild() {
59         Document document = makeGoodDocument();
60
61         try {
62             FormMVCConfigBuilder builder = new FormMVCConfigBuilder();
63             builder.build(document, FormMVCConfigRegistry.getInstance(request));
64
65             assertTrue("Should have baseAction1",
66                 FormMVCConfigRegistry.getInstance(request).lookupAction("testAction") != null);
67             assertTrue("Should have baseAction2",
68                 FormMVCConfigRegistry.getInstance(request).lookupAction("testAction2") != null);
69             assertTrue("Should have baseAction3",
70                 FormMVCConfigRegistry.getInstance(request).lookupAction("testAction3") != null);
71
72             assertTrue("Should have baseMapping1",
73                 FormMVCConfigRegistry.getInstance(request).lookupMapping("baseMapping1") != null);
74             assertTrue("Should have baseMapping2",
75                 FormMVCConfigRegistry.getInstance(request).lookupMapping("baseMapping2") != null);
76             assertTrue("Should have baseMapping3",
77                 FormMVCConfigRegistry.getInstance(request).lookupMapping("baseMapping3") != null);
78
79             FormConfig form1 = (FormConfig) FormMVCConfigRegistry.getInstance(request).lookupForm("form1");
80             FormConfig form2 = (FormConfig) FormMVCConfigRegistry.getInstance(request).lookupForm("form2");
81             assertTrue("Should have form1", form1 != null);
82             assertTrue("Should have form2", form2 != null);
83             assertTrue("form1 should have testAction",
84                 form1.getActionConfig("testAction") != null);
85             assertTrue("form1 should have testAction2",
86                 form1.getActionConfig("testAction2") != null);
87             assertTrue("form1 should have form1mapping1",
88                 form1.getMappingConfig("form1mapping1") != null);
89             assertTrue("form1 should have form1mapping2",
90                 form1.getMappingConfig("form1mapping2") != null);
91
92             assertTrue("form2 should have testAction",
93                 form2.getActionConfig("testAction") != null);
94             assertTrue("form2 should have testAction2",
95                 form2.getActionConfig("testAction2") != null);
96             assertTrue("form2 should have form2mapping1",
97                 form2.getMappingConfig("form2mapping1") != null);
98             assertTrue("form2 should have form2mapping2",
99                 form2.getMappingConfig("form2mapping2") != null);
100
101             FormConfig form3 = (FormConfig) FormMVCConfigRegistry.getInstance(request).lookupForm("validatingForm");
102             assertTrue("Should have form3", form3 != null);
103             assertTrue("form3 should have form3mapping1",
104                 form3.getMappingConfig("form3mapping1") != null);
105             assertTrue("form1 should have 2 validators",
106                 form3.getValidators().size() == 2);
107
108             List JavaDoc validators = form3.getValidators();
109             ValidatorConfig validatorConfig = (ValidatorConfig) validators.get(1);
110             assertNotNull("second validator should have mapping",
111                 validatorConfig.getFailureDefinition());
112             assertEquals("second validator should have mapping", "form3mapping1",
113                 validatorConfig.getFailureDefinition());
114
115             assertTrue("form2 should have testAction",
116                 form2.getActionConfig("testAction") != null);
117             assertTrue("form2 should have testAction2",
118                 form2.getActionConfig("testAction2") != null);
119             assertTrue("form2 should have form2mapping1",
120                 form2.getMappingConfig("form2mapping1") != null);
121             assertTrue("form2 should have form2mapping2",
122                 form2.getMappingConfig("form2mapping2") != null);
123
124             FormConfig form4 = (FormConfig) FormMVCConfigRegistry.getInstance(request).lookupForm("autoValidatingForm");
125             validators = form4.getValidators();
126             validatorConfig = (ValidatorConfig) validators.get(0);
127             assertTrue("validator should have a class", validatorConfig.isValidating());
128             PropertyConfig prop = (PropertyConfig) validatorConfig.getProperties().get(0);
129             assertEquals("validator should have string1 property", "string1",
130                 prop.getProperty());
131             assertEquals("validator should have phone type", "phone",
132                 prop.getType());
133             assertEquals("validator should have errorKey", "errorKey",
134                 prop.getKey());
135             assertEquals("validator should have errorBundle", "errorBundle",
136                 prop.getBundleName());
137             assertEquals("validator should have errorMessage", "errorMessage",
138                 prop.getErrorMsg());
139             assertEquals("validator should have param1", "paramValue1",
140                 prop.getParameters().get("param1"));
141             assertEquals("validator should have param2", "paramValue2",
142                 prop.getParameters().get("param2"));
143         } catch (ConfigurationException e) {
144             fail(e.toString());
145         }
146     }
147
148     public void testValidate() {
149         RepositoryTest test = new RepositoryTest("testInitialize");
150         test.setRequest(request);
151         test.setResponse(response);
152         test.setContext(context);
153         test.testInitialization();
154
155         Document document = makeMultiDocument();
156
157         try {
158             FormMVCConfigBuilder builder = new FormMVCConfigBuilder();
159             builder.build(document, FormMVCConfigRegistry.getInstance(request));
160             Map JavaDoc registries = new HashMap JavaDoc();
161             registries.put("repository", RepositoryConfigRegistry.getInstance(request));
162             builder.validate(FormMVCConfigRegistry.getInstance(request), registries);
163
164             FormConfig form = (FormConfig) FormMVCConfigRegistry.getInstance(request).lookupForm("multiFormBeanForm");
165             Collection JavaDoc formBeans = form.getFormBeans();
166             Map JavaDoc map = new HashMap JavaDoc();
167             Iterator JavaDoc iter = formBeans.iterator();
168             Object JavaDoc obj;
169             while (iter.hasNext()) {
170                 obj = iter.next();
171                 map.put(((WebBean) obj).getID(), obj);
172             }
173             assertNotNull("should have a fb1", map.get("formBean"));
174             assertNotNull("should have a fb2", map.get("formBean2"));
175             assertNotNull("should have a fb3", map.get("item1"));
176             assertNotNull("should have a fb4", map.get("item2"));
177             assertSame(TestFormBean.class, ((WebBean) map.get("formBean")).getBeanClass());
178             assertSame(TestFormBean2.class, ((WebBean) map.get("formBean2")).getBeanClass());
179
180             // Test that the primitive handling is setup correctly
181
form = (FormConfig) FormMVCConfigRegistry.getInstance(request).lookupForm("primitiveForm");
182             List JavaDoc validators = form.getValidators();
183             assertEquals(2, validators.size());
184
185             BaseValidatorConfig config = (BaseValidatorConfig) validators.get(1);
186             assertTrue(config instanceof ValidatorConfig);
187             assertSame(OverrideValidator.class, config.newValidator().getClass());
188         } catch (ConfigurationException e) {
189             fail(e.toString());
190         } catch (ReflectionException re) {
191             fail(re.toString());
192         }
193     }
194
195     /**
196      * Tests the build method correctly builds an action config object
197      */

198     public void testFailure() {
199         Document document = makeBadDocument();
200
201         try {
202             FormMVCConfigBuilder builder = new FormMVCConfigBuilder();
203             builder.build(document, FormMVCConfigRegistry.getInstance(request));
204             fail("Should have majorly failed");
205         } catch (Exception JavaDoc e) {
206             assertTrue("Should be a ConfigurationException",
207                 e instanceof ConfigurationException);
208             assertTrue("Should have errorlist",
209                 ((ConfigurationException) e).getErrors() != null &&
210                 !((ConfigurationException) e).getErrors().isEmpty());
211             System.out.println(e.toString());
212         }
213     }
214
215     /**
216      * Makes a good document
217      */

218     protected Document makeGoodDocument() {
219         Document document = new Document();
220         Element root = new Element("forms");
221         document.setRootElement(root);
222
223         Element baseAction1 = new Element("action");
224         baseAction1.setAttribute(Constants.NAME_ATTRIBUTE, "testAction");
225         baseAction1.setAttribute(Constants.HANDLER_ATTRIBUTE,
226             "com.inversoft.verge.mvc.controller.form.config.test.TestActionHandler");
227         root.addContent(baseAction1);
228         Element baseAction2 = new Element("action");
229         baseAction2.setAttribute(Constants.NAME_ATTRIBUTE, "testAction2");
230         baseAction2.setAttribute(Constants.HANDLER_ATTRIBUTE,
231             "com.inversoft.verge.mvc.controller.form.config.test.TestActionHandler");
232         root.addContent(baseAction2);
233         Element baseAction3 = new Element("action");
234         baseAction3.setAttribute(Constants.NAME_ATTRIBUTE, "testAction3");
235         baseAction3.setAttribute(Constants.HANDLER_ATTRIBUTE,
236             "com.inversoft.verge.mvc.controller.form.config.test.TestActionHandler");
237         root.addContent(baseAction3);
238
239
240
241         Element baseMapping1 = new Element("mapping");
242         baseMapping1.setAttribute(Constants.NAME_ATTRIBUTE, "baseMapping1");
243         baseMapping1.setAttribute(Constants.URL_ATTRIBUTE, "testMapping.jsp");
244         baseMapping1.setAttribute(Constants.FORWARD_ATTRIBUTE, "true");
245         root.addContent(baseMapping1);
246         Element baseMapping2 = new Element("mapping");
247         baseMapping2.setAttribute(Constants.NAME_ATTRIBUTE, "baseMapping2");
248         baseMapping2.setAttribute(Constants.URL_ATTRIBUTE, "testMapping.jsp");
249         baseMapping2.setAttribute(Constants.FORWARD_ATTRIBUTE, "true");
250         root.addContent(baseMapping2);
251         Element baseMapping3 = new Element("mapping");
252         baseMapping3.setAttribute(Constants.NAME_ATTRIBUTE, "baseMapping3");
253         baseMapping3.setAttribute(Constants.URL_ATTRIBUTE, "testMapping.jsp");
254         baseMapping3.setAttribute(Constants.FORWARD_ATTRIBUTE, "true");
255         root.addContent(baseMapping3);
256
257
258
259
260         Element form1 = new Element("form");
261         form1.setAttribute(Constants.NAME_ATTRIBUTE, "form1");
262
263         Element formBean1 = new Element("formBean");
264         formBean1.setAttribute(Constants.NAME_ATTRIBUTE, "testFormBean");
265         formBean1.setAttribute(Constants.CLASS_ATTRIBUTE,
266             "com.inversoft.verge.mvc.controller.form.config.test.TestFormBean");
267         form1.addContent(formBean1);
268
269         Element form1action1 = new Element("action");
270         form1action1.setAttribute(Constants.NAME_ATTRIBUTE, "testAction");
271         form1action1.setAttribute(Constants.HANDLER_ATTRIBUTE,
272             "com.inversoft.verge.mvc.controller.form.config.test.TestActionHandler");
273         Element form1action2 = new Element("action");
274         form1action2.setAttribute(Constants.NAME_ATTRIBUTE, "testAction2");
275         form1action2.setAttribute(Constants.HANDLER_ATTRIBUTE,
276             "com.inversoft.verge.mvc.controller.form.config.test.TestActionHandler");
277         form1.addContent(form1action1);
278         form1.addContent(form1action2);
279
280         Element form1mapping1 = new Element("mapping");
281         form1mapping1.setAttribute(Constants.NAME_ATTRIBUTE, "form1mapping1");
282         form1mapping1.setAttribute(Constants.URL_ATTRIBUTE, "testMapping1.jsp");
283         form1mapping1.setAttribute(Constants.FORWARD_ATTRIBUTE, "true");
284         Element form1mapping2 = new Element("mapping");
285         form1mapping2.setAttribute(Constants.NAME_ATTRIBUTE, "form1mapping2");
286         form1mapping2.setAttribute(Constants.URL_ATTRIBUTE, "testMapping2.jsp");
287         form1mapping2.setAttribute(Constants.FORWARD_ATTRIBUTE, "true");
288         form1.addContent(form1mapping1);
289         form1.addContent(form1mapping2);
290         root.addContent(form1);
291
292
293
294         Element form2 = new Element("form");
295         form2.setAttribute(Constants.NAME_ATTRIBUTE, "form2");
296
297         Element formBean2 = new Element("formBean");
298         formBean2.setAttribute(Constants.NAME_ATTRIBUTE, "testFormBean");
299         formBean2.setAttribute(Constants.CLASS_ATTRIBUTE,
300             "com.inversoft.verge.mvc.controller.form.config.test.TestFormBean");
301         form2.addContent(formBean2);
302
303         Element form2action1 = new Element("action");
304         form2action1.setAttribute(Constants.NAME_ATTRIBUTE, "testAction");
305         form2action1.setAttribute(Constants.HANDLER_ATTRIBUTE,
306             "com.inversoft.verge.mvc.controller.form.config.test.TestActionHandler");
307         Element form2action2 = new Element("action");
308         form2action2.setAttribute(Constants.NAME_ATTRIBUTE, "testAction2");
309         form2action2.setAttribute(Constants.HANDLER_ATTRIBUTE,
310             "com.inversoft.verge.mvc.controller.form.config.test.TestActionHandler");
311         form2.addContent(form2action1);
312         form2.addContent(form2action2);
313
314         Element form2mapping1 = new Element("mapping");
315         form2mapping1.setAttribute(Constants.NAME_ATTRIBUTE, "form2mapping1");
316         form2mapping1.setAttribute(Constants.URL_ATTRIBUTE, "testMapping1.jsp");
317         form2mapping1.setAttribute(Constants.FORWARD_ATTRIBUTE, "true");
318         Element form2mapping2 = new Element("mapping");
319         form2mapping2.setAttribute(Constants.NAME_ATTRIBUTE, "form2mapping2");
320         form2mapping2.setAttribute(Constants.URL_ATTRIBUTE, "testMapping2.jsp");
321         form2mapping2.setAttribute(Constants.FORWARD_ATTRIBUTE, "true");
322         form2.addContent(form2mapping1);
323         form2.addContent(form2mapping2);
324         root.addContent(form2);
325
326         Element form3 = new Element("form");
327         form3.setAttribute(Constants.NAME_ATTRIBUTE, "validatingForm");
328
329         Element form3mapping1 = new Element("mapping");
330         form3mapping1.setAttribute(Constants.NAME_ATTRIBUTE, "form3mapping1");
331         form3mapping1.setAttribute(Constants.URL_ATTRIBUTE, "testMapping1.jsp");
332         form3mapping1.setAttribute(Constants.FORWARD_ATTRIBUTE, "true");
333         form3.addContent(form3mapping1);
334
335         Element form3validator1 = new Element("validator");
336         form3validator1.setAttribute(Constants.CLASS_ATTRIBUTE,
337             "com.inversoft.verge.mvc.validator.test.TestValidator1");
338         Element form3validator2 = new Element("validator");
339         form3validator2.setAttribute(Constants.CLASS_ATTRIBUTE,
340             "com.inversoft.verge.mvc.validator.test.TestValidator1");
341         form3validator2.setAttribute(Constants.FAILURE_MAPPING_ATTRIBUTE, "form3mapping1");
342         form3.addContent(form3validator1);
343         form3.addContent(form3validator2);
344         root.addContent(form3);
345
346         Element form4 = new Element("form");
347         form4.setAttribute(Constants.NAME_ATTRIBUTE, "autoValidatingForm");
348         Element form4formbean = new Element("formBean");
349         form4formbean.setAttribute("name", "formBean");
350         form4formbean.setAttribute("class", "com.inversoft.verge.mvc.controller.form.config.test.TestFormBean");
351         form4.addContent(form4formbean);
352
353         Element form4validator1 = new Element("validator");
354         form4validator1.setAttribute(Constants.CLASS_ATTRIBUTE,
355             "com.inversoft.verge.mvc.validator.test.TestValidator1");
356         Element form4validator1prop1 = new Element("property");
357         form4validator1prop1.setAttribute("name", "formBean.string1");
358         form4validator1prop1.setAttribute("type", "phone");
359         form4validator1prop1.setAttribute("key", "errorKey");
360         form4validator1prop1.setAttribute("bundleName", "errorBundle");
361         form4validator1prop1.setAttribute("errorMsg", "errorMessage");
362         form4validator1prop1.setAttribute("param1", "paramValue1");
363         form4validator1prop1.setAttribute("param2", "paramValue2");
364         form4validator1.addContent(form4validator1prop1);
365         form4.addContent(form4validator1);
366         root.addContent(form4);
367
368         return document;
369     }
370
371     /**
372      * Makes a good document
373      */

374     protected Document makeMultiDocument() {
375         Document document = new Document();
376         Element root = new Element("forms");
377         document.setRootElement(root);
378
379         Element form1 = new Element("form");
380         form1.setAttribute(Constants.NAME_ATTRIBUTE, "multiFormBeanForm");
381         Element form1formbean1 = new Element("formBean");
382         form1formbean1.setAttribute("name", "formBean");
383         form1formbean1.setAttribute("class", "com.inversoft.verge.mvc.controller.form.config.test.TestFormBean");
384         Element form1formbean2 = new Element("formBean");
385         form1formbean2.setAttribute("name", "formBean2");
386         form1formbean2.setAttribute("class", "com.inversoft.verge.mvc.controller.form.config.test.TestFormBean2");
387         Element form1formbean3 = new Element("formBean");
388         form1formbean3.setAttribute("name", "item1");
389         form1formbean3.setAttribute("isRepository", "true");
390         Element form1formbean4 = new Element("formBean");
391         form1formbean4.setAttribute("name", "item2");
392         form1formbean4.setAttribute("isRepository", "true");
393         form1.addContent(form1formbean1);
394         form1.addContent(form1formbean2);
395         form1.addContent(form1formbean3);
396         form1.addContent(form1formbean4);
397         root.addContent(form1);
398
399         Element form2 = new Element("form");
400         form2.setAttribute(Constants.NAME_ATTRIBUTE, "primitiveForm");
401         Element form2formbean = new Element("formBean");
402         form2formbean.setAttribute("name", "formBean");
403         form2formbean.setAttribute("class", "com.inversoft.verge.mvc.controller.form.config.test.TestFormBean");
404         form2.addContent(form2formbean);
405
406         Element form2validator1 = new Element("validator");
407         Element form2validator1prop1 = new Element("property");
408         form2validator1prop1.setAttribute("name", "formBean.age");
409         form2validator1prop1.setAttribute("type", "int");
410         form2validator1prop1.setAttribute("key", "errorKey");
411         form2validator1prop1.setAttribute("bundleName", "errorBundle");
412         form2validator1prop1.setAttribute("errorMsg", "errorMessage");
413         form2validator1prop1.setAttribute("param1", "paramValue1");
414         form2validator1prop1.setAttribute("param2", "paramValue2");
415         form2validator1.addContent(form2validator1prop1);
416         form2.addContent(form2validator1);
417         root.addContent(form2);
418
419         return document;
420     }
421
422     /**
423      * Makes a bad document
424      */

425     protected Document makeBadDocument() {
426         Document document = new Document();
427         Element root = new Element("forms");
428         document.setRootElement(root);
429
430         Element baseAction1 = new Element("action");
431         //baseAction1.setAttribute(Constants.NAME_ATTRIBUTE, "testAction");
432
baseAction1.setAttribute(Constants.HANDLER_ATTRIBUTE,
433             "com.inversoft.verge.mvc.controller.form.config.test.TestActionHandler");
434         root.addContent(baseAction1);
435         Element baseAction2 = new Element("action");
436         baseAction2.setAttribute(Constants.NAME_ATTRIBUTE, "testAction2");
437         //baseAction2.setAttribute(Constants.HANDLER_ATTRIBUTE,
438
//"com.inversoft.verge.mvc.controller.form.config.test.TestActionHandler");
439
root.addContent(baseAction2);
440         Element baseAction3 = new Element("action");
441         baseAction3.setAttribute(Constants.NAME_ATTRIBUTE, "testAction3");
442         baseAction3.setAttribute(Constants.HANDLER_ATTRIBUTE,
443             "com.inversoft.verge.mvc.controller.form.config.test.NotAClass");
444         root.addContent(baseAction3);
445
446
447
448         Element baseMapping1 = new Element("mapping");
449         //baseMapping1.setAttribute(Constants.NAME_ATTRIBUTE, "baseMapping1");
450
baseMapping1.setAttribute(Constants.URL_ATTRIBUTE, "testMapping.jsp");
451         baseMapping1.setAttribute(Constants.FORWARD_ATTRIBUTE, "true");
452         root.addContent(baseMapping1);
453         Element baseMapping2 = new Element("mapping");
454         baseMapping2.setAttribute(Constants.NAME_ATTRIBUTE, "baseMapping2");
455         //baseMapping2.setAttribute(Constants.URL_ATTRIBUTE, "testMapping.jsp");
456
baseMapping2.setAttribute(Constants.FORWARD_ATTRIBUTE, "true");
457         root.addContent(baseMapping2);
458         Element baseMapping3 = new Element("mapping");
459         baseMapping3.setAttribute(Constants.NAME_ATTRIBUTE, "baseMapping3");
460         baseMapping3.setAttribute(Constants.URL_ATTRIBUTE, "testMapping.jsp");
461         baseMapping3.setAttribute(Constants.FORWARD_ATTRIBUTE, "bad");
462         root.addContent(baseMapping3);
463
464
465
466
467         Element form1 = new Element("form");
468         form1.setAttribute(Constants.NAME_ATTRIBUTE, "form1");
469
470         Element formBean1 = new Element("formBean");
471         //formBean1.setAttribute(Constants.NAME_ATTRIBUTE, "testFormBean");
472
formBean1.setAttribute(Constants.CLASS_ATTRIBUTE,
473             "com.inversoft.verge.mvc.controller.form.config.test.TestFormBean");
474         form1.addContent(formBean1);
475
476         Element form1action1 = new Element("action");
477         //form1action1.setAttribute(Constants.NAME_ATTRIBUTE, "testAction");
478
form1action1.setAttribute(Constants.HANDLER_ATTRIBUTE,
479             "com.inversoft.verge.mvc.controller.form.config.test.TestActionHandler");
480         Element form1action2 = new Element("action");
481         form1action2.setAttribute(Constants.NAME_ATTRIBUTE, "testAction2");
482         //form1action2.setAttribute(Constants.HANDLER_ATTRIBUTE,
483
//"com.inversoft.verge.mvc.controller.form.config.test.TestActionHandler");
484
form1.addContent(form1action1);
485         form1.addContent(form1action2);
486
487         Element form1mapping1 = new Element("mapping");
488         //form1mapping1.setAttribute(Constants.NAME_ATTRIBUTE, "form1mapping1");
489
form1mapping1.setAttribute(Constants.URL_ATTRIBUTE, "testMapping1.jsp");
490         form1mapping1.setAttribute(Constants.FORWARD_ATTRIBUTE, "true");
491         Element form1mapping2 = new Element("mapping");
492         form1mapping2.setAttribute(Constants.NAME_ATTRIBUTE, "form1mapping2");
493         //form1mapping2.setAttribute(Constants.URL_ATTRIBUTE, "testMapping2.jsp");
494
form1mapping2.setAttribute(Constants.FORWARD_ATTRIBUTE, "true");
495         form1.addContent(form1mapping1);
496         form1.addContent(form1mapping2);
497         root.addContent(form1);
498
499
500
501         Element form2 = new Element("form");
502         //form2.setAttribute(Constants.NAME_ATTRIBUTE, "form2");
503

504         Element formBean2 = new Element("formBean");
505         formBean2.setAttribute(Constants.NAME_ATTRIBUTE, "testFormBean");
506         formBean2.setAttribute(Constants.CLASS_ATTRIBUTE,
507             "com.inversoft.verge.mvc.controller.form.config.test.TestFormBean");
508         //form2.addContent(formBean2);
509

510         Element form2action1 = new Element("action");
511         form2action1.setAttribute(Constants.NAME_ATTRIBUTE, "testAction");
512         form2action1.setAttribute(Constants.HANDLER_ATTRIBUTE,
513             "com.inversoft.verge.mvc.controller.form.config.test.TestActionHandler");
514         Element form2action2 = new Element("action");
515         form2action2.setAttribute(Constants.NAME_ATTRIBUTE, "testAction2");
516         form2action2.setAttribute(Constants.HANDLER_ATTRIBUTE,
517             "com.inversoft.verge.mvc.controller.form.config.test.NotAClass");
518         form2.addContent(form2action1);
519         form2.addContent(form2action2);
520
521         Element form2mapping1 = new Element("mapping");
522         form2mapping1.setAttribute(Constants.NAME_ATTRIBUTE, "form2mapping1");
523         form2mapping1.setAttribute(Constants.URL_ATTRIBUTE, "testMapping1.jsp");
524         form2mapping1.setAttribute(Constants.FORWARD_ATTRIBUTE, "true");
525         Element form2mapping2 = new Element("mapping");
526         form2mapping2.setAttribute(Constants.NAME_ATTRIBUTE, "form2mapping2");
527         form2mapping2.setAttribute(Constants.URL_ATTRIBUTE, "testMapping2.jsp");
528         form2mapping2.setAttribute(Constants.FORWARD_ATTRIBUTE, "bad");
529         form2.addContent(form2mapping1);
530         form2.addContent(form2mapping2);
531         root.addContent(form2);
532
533         Element form3 = new Element("form");
534         form3.setAttribute(Constants.NAME_ATTRIBUTE, "autoValidatingForm");
535         Element form3formbean = new Element("formBean");
536         form3formbean.setAttribute("name", "formBean");
537         form3formbean.setAttribute("class", "com.inversoft.verge.mvc.controller.form.config.test.TestFormBean");
538         form3.addContent(form3formbean);
539
540         Element form3validator1 = new Element("validator");
541         form3validator1.setAttribute(Constants.CLASS_ATTRIBUTE,
542             "com.inversoft.verge.mvc.validator.test.TestValidator1");
543         Element form3validator1prop1 = new Element("property");
544         form3validator1prop1.setAttribute("name", "string1");
545         form3validator1prop1.setAttribute("type", "phone");
546         form3validator1prop1.setAttribute("key", "errorKey");
547         form3validator1prop1.setAttribute("bundleName", "errorBundle");
548         form3validator1prop1.setAttribute("errorMsg", "errorMessage");
549         form3validator1prop1.setAttribute("param1", "paramValue1");
550         form3validator1prop1.setAttribute("param2", "paramValue2");
551         form3validator1.addContent(form3validator1prop1);
552         form3.addContent(form3validator1);
553         root.addContent(form3);
554
555         Element form4 = new Element("form");
556         form4.setAttribute(Constants.NAME_ATTRIBUTE, "autoValidatingForm");
557         Element form4formbean = new Element("formBean");
558         form4formbean.setAttribute("name", "formBean");
559         form4formbean.setAttribute("class", "com.inversoft.verge.mvc.controller.form.config.test.TestFormBean");
560         form4.addContent(form4formbean);
561
562         Element form4validator1 = new Element("validator");
563         form4validator1.setAttribute(Constants.CLASS_ATTRIBUTE,
564             "com.inversoft.verge.mvc.validator.test.TestValidator1");
565         Element form4validator1prop1 = new Element("property");
566         form4validator1prop1.setAttribute("name", "badFormBean.string1");
567         form4validator1prop1.setAttribute("type", "phone");
568         form4validator1prop1.setAttribute("key", "errorKey");
569         form4validator1prop1.setAttribute("bundleName", "errorBundle");
570         form4validator1prop1.setAttribute("errorMsg", "errorMessage");
571         form4validator1prop1.setAttribute("param1", "paramValue1");
572         form4validator1prop1.setAttribute("param2", "paramValue2");
573         form4validator1.addContent(form4validator1prop1);
574         form4.addContent(form4validator1);
575         root.addContent(form4);
576
577         return document;
578     }
579 }
580
581
Popular Tags