KickJava   Java API By Example, From Geeks To Geeks.

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


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.HashMap JavaDoc;
11
12 import org.jdom.Document;
13 import org.jdom.Element;
14
15 import com.inversoft.junit.WebTestCase;
16 import com.inversoft.verge.config.VergeConfigConstants;
17 import com.inversoft.verge.mvc.controller.form.config.Constants;
18 import com.inversoft.verge.mvc.controller.form.config.FormConfig;
19 import com.inversoft.verge.mvc.controller.form.config.FormMVCConfigBuilder;
20 import com.inversoft.verge.mvc.controller.form.config.FormMVCConfigFactory;
21 import com.inversoft.verge.mvc.controller.form.config.FormMVCConfigRegistry;
22 import com.inversoft.verge.repository.config.RepositoryConfigRegistry;
23
24
25 /**
26  * <p>
27  * This class contains the main round trip TestCase for the
28  * form mvc builder. This had to be put in a separate class
29  * because of the ThreadLocal code in the Regsitry.
30  * </p>
31  *
32  * @author Brian Pontarelli
33  * @since 1.0
34  * @version 1.0
35  */

36 public class FormMVCBuilderTest2 extends WebTestCase {
37
38     /**
39      * Constructs a new <code>FormMVCBuilderTest</code> TestCase instance
40      */

41     public FormMVCBuilderTest2(String JavaDoc name) {
42         super(name);
43         setLocal(true);
44     }
45
46
47     /**
48      * Tests the build and validate methods both work in order
49      */

50     public void testValidate() {
51         Document document = makeGoodDocument();
52
53         try {
54             FormMVCConfigRegistry newOne =
55                 (FormMVCConfigRegistry) new FormMVCConfigFactory().createRegistry();
56
57             FormMVCConfigBuilder builder = new FormMVCConfigBuilder();
58             HashMap JavaDoc map = new HashMap JavaDoc();
59             map.put(VergeConfigConstants.REPOSITORY_KEY,
60                 RepositoryConfigRegistry.getInstance(request));
61             builder.build(document, newOne);
62             builder.validate(newOne, map);
63             builder.commit(newOne, map);
64
65             assertTrue("Should have setup the singleton instance",
66                 FormMVCConfigRegistry.getInstance(request) == newOne);
67
68             assertTrue("Should have baseAction1",
69                 FormMVCConfigRegistry.getInstance(request).lookupAction("testAction") != null);
70             assertTrue("Should have baseAction2",
71                 FormMVCConfigRegistry.getInstance(request).lookupAction("testAction2") != null);
72             assertTrue("Should have baseAction3",
73                 FormMVCConfigRegistry.getInstance(request).lookupAction("testAction3") != null);
74
75             assertTrue("Should have baseMapping1",
76                 FormMVCConfigRegistry.getInstance(request).lookupMapping("baseMapping1") != null);
77             assertTrue("Should have baseMapping2",
78                 FormMVCConfigRegistry.getInstance(request).lookupMapping("baseMapping2") != null);
79             assertTrue("Should have baseMapping3",
80                 FormMVCConfigRegistry.getInstance(request).lookupMapping("baseMapping3") != null);
81
82             FormConfig form1 = (FormConfig) FormMVCConfigRegistry.getInstance(request).lookupForm("form1");
83             FormConfig form2 = (FormConfig) FormMVCConfigRegistry.getInstance(request).lookupForm("form2");
84             assertTrue("Should have form1", form1 != null);
85             assertTrue("Should have form2", form2 != null);
86             assertTrue("form1 should have testAction",
87                 form1.getActionConfig("testAction") != null);
88             assertTrue("form1 should have testAction2",
89                 form1.getActionConfig("testAction2") != null);
90             assertTrue("form1 should have form1mapping1",
91                 form1.getMappingConfig("form1mapping1") != null);
92             assertTrue("form1 should have form1mapping2",
93                 form1.getMappingConfig("form1mapping2") != null);
94
95             assertTrue("form2 should have testAction",
96                 form2.getActionConfig("testAction") != null);
97             assertTrue("form2 should have testAction2",
98                 form2.getActionConfig("testAction2") != null);
99             assertTrue("form2 should have form2mapping1",
100                 form2.getMappingConfig("form2mapping1") != null);
101             assertTrue("form2 should have form2mapping2",
102                 form2.getMappingConfig("form2mapping2") != null);
103         } catch (Exception JavaDoc e) {
104             fail(e.toString());
105         }
106     }
107
108     /**
109      * Makes a good document
110      */

111     protected Document makeGoodDocument() {
112         Document document = new Document();
113         Element root = new Element("forms");
114         document.setRootElement(root);
115
116         Element baseAction1 = new Element("action");
117         baseAction1.setAttribute(Constants.NAME_ATTRIBUTE, "testAction");
118         baseAction1.setAttribute(Constants.HANDLER_ATTRIBUTE,
119             "com.inversoft.verge.mvc.controller.form.config.test.TestActionHandler");
120         root.addContent(baseAction1);
121         Element baseAction2 = new Element("action");
122         baseAction2.setAttribute(Constants.NAME_ATTRIBUTE, "testAction2");
123         baseAction2.setAttribute(Constants.HANDLER_ATTRIBUTE,
124             "com.inversoft.verge.mvc.controller.form.config.test.TestActionHandler");
125         root.addContent(baseAction2);
126         Element baseAction3 = new Element("action");
127         baseAction3.setAttribute(Constants.NAME_ATTRIBUTE, "testAction3");
128         baseAction3.setAttribute(Constants.HANDLER_ATTRIBUTE,
129             "com.inversoft.verge.mvc.controller.form.config.test.TestActionHandler");
130         root.addContent(baseAction3);
131
132
133
134         Element baseMapping1 = new Element("mapping");
135         baseMapping1.setAttribute(Constants.NAME_ATTRIBUTE, "baseMapping1");
136         baseMapping1.setAttribute(Constants.URL_ATTRIBUTE, "testMapping.jsp");
137         baseMapping1.setAttribute(Constants.FORWARD_ATTRIBUTE, "true");
138         root.addContent(baseMapping1);
139         Element baseMapping2 = new Element("mapping");
140         baseMapping2.setAttribute(Constants.NAME_ATTRIBUTE, "baseMapping2");
141         baseMapping2.setAttribute(Constants.URL_ATTRIBUTE, "testMapping.jsp");
142         baseMapping2.setAttribute(Constants.FORWARD_ATTRIBUTE, "true");
143         root.addContent(baseMapping2);
144         Element baseMapping3 = new Element("mapping");
145         baseMapping3.setAttribute(Constants.NAME_ATTRIBUTE, "baseMapping3");
146         baseMapping3.setAttribute(Constants.URL_ATTRIBUTE, "testMapping.jsp");
147         baseMapping3.setAttribute(Constants.FORWARD_ATTRIBUTE, "true");
148         root.addContent(baseMapping3);
149
150
151
152
153         Element form1 = new Element("form");
154         form1.setAttribute(Constants.NAME_ATTRIBUTE, "form1");
155
156         Element formBean1 = new Element("formBean");
157         formBean1.setAttribute(Constants.NAME_ATTRIBUTE, "testFormBean");
158         formBean1.setAttribute(Constants.CLASS_ATTRIBUTE,
159             "com.inversoft.verge.mvc.controller.form.config.test.TestFormBean");
160         form1.addContent(formBean1);
161
162         Element form1action1 = new Element("action");
163         form1action1.setAttribute(Constants.NAME_ATTRIBUTE, "testAction");
164         form1action1.setAttribute(Constants.HANDLER_ATTRIBUTE,
165             "com.inversoft.verge.mvc.controller.form.config.test.TestActionHandler");
166         Element form1action2 = new Element("action");
167         form1action2.setAttribute(Constants.NAME_ATTRIBUTE, "testAction2");
168         form1action2.setAttribute(Constants.HANDLER_ATTRIBUTE,
169             "com.inversoft.verge.mvc.controller.form.config.test.TestActionHandler");
170         form1.addContent(form1action1);
171         form1.addContent(form1action2);
172
173         Element form1mapping1 = new Element("mapping");
174         form1mapping1.setAttribute(Constants.NAME_ATTRIBUTE, "form1mapping1");
175         form1mapping1.setAttribute(Constants.URL_ATTRIBUTE, "testMapping1.jsp");
176         form1mapping1.setAttribute(Constants.FORWARD_ATTRIBUTE, "true");
177         Element form1mapping2 = new Element("mapping");
178         form1mapping2.setAttribute(Constants.NAME_ATTRIBUTE, "form1mapping2");
179         form1mapping2.setAttribute(Constants.URL_ATTRIBUTE, "testMapping2.jsp");
180         form1mapping2.setAttribute(Constants.FORWARD_ATTRIBUTE, "true");
181         form1.addContent(form1mapping1);
182         form1.addContent(form1mapping2);
183         root.addContent(form1);
184
185
186
187         Element form2 = new Element("form");
188         form2.setAttribute(Constants.NAME_ATTRIBUTE, "form2");
189
190         Element formBean2 = new Element("formBean");
191         formBean2.setAttribute(Constants.NAME_ATTRIBUTE, "testFormBean");
192         formBean2.setAttribute(Constants.CLASS_ATTRIBUTE,
193             "com.inversoft.verge.mvc.controller.form.config.test.TestFormBean");
194         form2.addContent(formBean2);
195
196         Element form2action1 = new Element("action");
197         form2action1.setAttribute(Constants.NAME_ATTRIBUTE, "testAction");
198         form2action1.setAttribute(Constants.HANDLER_ATTRIBUTE,
199             "com.inversoft.verge.mvc.controller.form.config.test.TestActionHandler");
200         Element form2action2 = new Element("action");
201         form2action2.setAttribute(Constants.NAME_ATTRIBUTE, "testAction2");
202         form2action2.setAttribute(Constants.HANDLER_ATTRIBUTE,
203             "com.inversoft.verge.mvc.controller.form.config.test.TestActionHandler");
204         form2.addContent(form2action1);
205         form2.addContent(form2action2);
206
207         Element form2mapping1 = new Element("mapping");
208         form2mapping1.setAttribute(Constants.NAME_ATTRIBUTE, "form2mapping1");
209         form2mapping1.setAttribute(Constants.URL_ATTRIBUTE, "testMapping1.jsp");
210         form2mapping1.setAttribute(Constants.FORWARD_ATTRIBUTE, "true");
211         Element form2mapping2 = new Element("mapping");
212         form2mapping2.setAttribute(Constants.NAME_ATTRIBUTE, "form2mapping2");
213         form2mapping2.setAttribute(Constants.URL_ATTRIBUTE, "testMapping2.jsp");
214         form2mapping2.setAttribute(Constants.FORWARD_ATTRIBUTE, "true");
215         form2.addContent(form2mapping1);
216         form2.addContent(form2mapping2);
217         root.addContent(form2);
218
219         return document;
220     }
221 }
Popular Tags