KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: TestELFormTag.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 public class TestELFormTag extends JspTagTestCase
28 {
29
30     protected static final String JavaDoc ACTION_NAME = "stuff";
31     protected static final String JavaDoc FORM_BEAN_CLASS =
32         "org.apache.strutsel.taglib.utils.TestFormBean";
33
34     protected static final String JavaDoc REQUIRED_NAME_VALUE_KEY =
35             "RequiredNameValue";
36     protected static final String JavaDoc REQUIRED_METHOD_VALUE_KEY =
37             "RequiredMethodValue";
38     protected static final String JavaDoc REQUIRED_ACTION_VALUE_KEY =
39             "RequiredActionValue";
40
41     protected ELFormTag elFormTag = null;
42
43     private static Log log = LogFactory.getLog(TestELFormTag.class);
44
45     public TestELFormTag(String JavaDoc theName) {
46         super(theName);
47     }
48
49     public static void main(String JavaDoc[] args) {
50         junit.awtui.TestRunner.main(
51                 new String JavaDoc[] { TestELFormTag.class.getName() });
52     }
53
54     public static Test suite() {
55         return new TestSuite(TestELFormTag.class);
56     }
57
58     public void setUp() {
59         elFormTag = new ELFormTag();
60         elFormTag.setPageContext(pageContext);
61     }
62
63     /**
64      * Converts an action name into the path associated with it. The basic
65      * contents of this function was copied from
66      * "FormTag.getActionMappingName()".
67      */

68     protected String JavaDoc convertActionNameToPath(String JavaDoc actionName)
69     {
70         String JavaDoc value = actionName;
71
72         int questionLoc = actionName.indexOf("?");
73         if (questionLoc >= 0)
74             value = value.substring(0, questionLoc);
75
76         int slashLoc = value.lastIndexOf("/");
77         int periodLoc = value.lastIndexOf(".");
78
79         if ((periodLoc >= 0) && (periodLoc > slashLoc))
80             value = value.substring(0, periodLoc);
81
82         if (!value.startsWith("/"))
83             value = "/" + value;
84
85         return (value);
86     }
87
88 // /**
89
// * Return the form action converted into a server-relative URL.
90
// * <p>
91
// * This is copied from FormTag, with the small change of passing the action
92
// * name as a parameter, and calling
93
// * <code>convertActionNameToPath(actionName)</code> instead of the
94
// * original's <code>getActionMappingName()</code>.
95
// */
96
// protected String getActionMappingURL(String actionName) {
97

98 // HttpServletRequest request =
99
// (HttpServletRequest) pageContext.getRequest();
100
// StringBuffer value = new StringBuffer(request.getContextPath());
101
// ApplicationConfig config = (ApplicationConfig)
102
// pageContext.getRequest().getAttribute(Action.APPLICATION_KEY);
103
// if (config != null) {
104
// value.append(config.getPrefix());
105
// }
106

107 // // Use our servlet mapping, if one is specified
108
// String servletMapping = (String)
109
// pageContext.getAttribute(Action.SERVLET_KEY,
110
// PageContext.APPLICATION_SCOPE);
111
// if (servletMapping != null) {
112
// String queryString = null;
113
// int question = actionName.indexOf("?");
114
// if (question >= 0) {
115
// queryString = actionName.substring(question);
116
// }
117
// String actionMapping = convertActionNameToPath(actionName);
118
// if (servletMapping.startsWith("*.")) {
119
// value.append(actionMapping);
120
// value.append(servletMapping.substring(1));
121
// } else if (servletMapping.endsWith("/*")) {
122
// value.append(servletMapping.substring
123
// (0, servletMapping.length() - 2));
124
// value.append(actionMapping);
125
// } else if (servletMapping.equals("/")) {
126
// value.append(actionMapping);
127
// }
128
// if (queryString != null) {
129
// value.append(queryString);
130
// }
131
// }
132

133 // // Otherwise, assume extension mapping is in use and extension is
134
// // already included in the action property
135
// else {
136
// if (!actionName.startsWith("/")) {
137
// value.append("/");
138
// }
139
// value.append(actionName);
140
// }
141

142 // // Return the completed value
143
// return (value.toString());
144
// }
145

146 // protected void setupServletEnvironment()
147
// throws ServletException
148
// {
149
// ActionServlet actionServlet = new ActionServlet();
150
// actionServlet.init(pageContext.getServletConfig());
151
// actionServlet.init();
152

153 // ApplicationConfig appConfig = new ApplicationConfig("");
154

155 // pageContext.setAttribute(Action.APPLICATION_KEY, appConfig,
156
// PageContext.APPLICATION_SCOPE);
157
// }
158

159     public void testDummy()
160     {
161     }
162
163 // public void testPlain()
164
// throws ServletException, JspException
165
// {
166
// ActionServlet actionServlet = new ActionServlet();
167
// actionServlet.init(pageContext.getServletConfig());
168
// actionServlet.init();
169

170 // // ApplicationConfig appConfig = new ApplicationConfig("");
171

172 // // pageContext.setAttribute(Action.APPLICATION_KEY, appConfig,
173
// // PageContext.APPLICATION_SCOPE);
174

175 // ActionMapping mapping = new ActionMapping();
176
// mapping.setName(ACTION_NAME);
177
// mapping.setPath(convertActionNameToPath(mapping.getName()));
178

179 // ActionFormBean formBean =
180
// new ActionFormBean(mapping.getName(), FORM_BEAN_CLASS);
181

182 // appConfig.addActionConfig(mapping);
183
// appConfig.addFormBeanConfig(formBean);
184

185 // HttpServletResponse response =
186
// (HttpServletResponse)pageContext.getResponse();
187

188 // String encodedURL =
189
// response.encodeURL(RequestUtils.
190
// getActionMappingURL(mapping.getName(),
191
// pageContext));
192

193 // response.addHeader(REQUIRED_NAME_VALUE_KEY, ACTION_NAME);
194
// response.addHeader(REQUIRED_METHOD_VALUE_KEY, "post");
195
// response.addHeader(REQUIRED_ACTION_VALUE_KEY, encodedURL);
196

197 // elFormTag.setActionExpr(ACTION_NAME);
198

199 // int startTagReturn = elFormTag.doStartTag();
200
// int endTagReturn = elFormTag.doEndTag();
201
// }
202

203 // public void endPlain(com.meterware.httpunit.WebResponse testResponse) {
204
// try {
205
// TestHelper.printResponse(testResponse);
206

207 // Element docElement = testResponse.getDOM().getDocumentElement();
208
// DOMHelper.printNode(docElement);
209

210 // HashMap attrMap = new HashMap();
211

212 // DOMHelper.recordFoundAttributes(testResponse.getDOM(),
213
// "/html/body/form", attrMap);
214
// DOMHelper.verifyAttributesPresent(attrMap,
215
// new String[] { "name", "method",
216
// "action" },
217
// false);
218
// checkAttrValue(attrMap, testResponse, REQUIRED_NAME_VALUE_KEY,
219
// "form", "name");
220
// checkAttrValue(attrMap, testResponse, REQUIRED_METHOD_VALUE_KEY,
221
// "form", "method");
222
// checkAttrValue(attrMap, testResponse, REQUIRED_ACTION_VALUE_KEY,
223
// "form", "action");
224
// } catch (Exception ex) {
225
// ex.printStackTrace();
226
// fail();
227
// }
228
// }
229

230 // public void testMethod()
231
// throws ServletException, JspException
232
// {
233
// ActionServlet actionServlet = new ActionServlet();
234
// actionServlet.init(pageContext.getServletConfig());
235
// actionServlet.init();
236

237 // ApplicationConfig appConfig = new ApplicationConfig("");
238

239 // pageContext.setAttribute(Action.APPLICATION_KEY, appConfig,
240
// PageContext.APPLICATION_SCOPE);
241

242 // ActionMapping mapping = new ActionMapping();
243
// mapping.setName(ACTION_NAME);
244
// mapping.setPath(convertActionNameToPath(mapping.getName()));
245

246 // ActionFormBean formBean =
247
// new ActionFormBean(mapping.getName(), FORM_BEAN_CLASS);
248

249 // appConfig.addActionConfig(mapping);
250
// appConfig.addFormBeanConfig(formBean);
251

252 // HttpServletResponse response =
253
// (HttpServletResponse)pageContext.getResponse();
254

255 // String encodedURL =
256
// response.encodeURL(RequestUtils.
257
// getActionMappingURL(mapping.getName(),
258
// pageContext));
259

260 // response.addHeader(REQUIRED_NAME_VALUE_KEY, ACTION_NAME);
261
// response.addHeader(REQUIRED_METHOD_VALUE_KEY, "GET");
262
// response.addHeader(REQUIRED_ACTION_VALUE_KEY, encodedURL);
263

264 // elFormTag.setActionExpr(ACTION_NAME);
265
// elFormTag.setMethodExpr("GET");
266

267 // int startTagReturn = elFormTag.doStartTag();
268
// int endTagReturn = elFormTag.doEndTag();
269
// }
270

271 // public void endMethod(com.meterware.httpunit.WebResponse testResponse) {
272
// try {
273
// TestHelper.printResponse(testResponse);
274

275 // Element docElement = testResponse.getDOM().getDocumentElement();
276
// DOMHelper.printNode(docElement);
277

278 // HashMap attrMap = new HashMap();
279

280 // DOMHelper.recordFoundAttributes(testResponse.getDOM(),
281
// "/html/body/form", attrMap);
282
// DOMHelper.verifyAttributesPresent(attrMap,
283
// new String[] { "name", "method",
284
// "action" },
285
// false);
286
// checkAttrValue(attrMap, testResponse, REQUIRED_NAME_VALUE_KEY,
287
// "form", "name");
288
// checkAttrValue(attrMap, testResponse, REQUIRED_METHOD_VALUE_KEY,
289
// "form", "method");
290
// checkAttrValue(attrMap, testResponse, REQUIRED_ACTION_VALUE_KEY,
291
// "form", "action");
292
// } catch (Exception ex) {
293
// ex.printStackTrace();
294
// fail();
295
// }
296
// }
297
}
298
Popular Tags