001: /*
002: * $Id: SubmitTest.java 537478 2007-05-12 16:25:59Z musachy $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021: package org.apache.struts2.views.jsp.ui;
022:
023: import org.apache.struts2.TestAction;
024: import org.apache.struts2.views.jsp.AbstractUITagTest;
025:
026: import java.util.HashMap;
027: import java.util.Map;
028:
029: /**
030: * Unit test for {@link SubmitTag}.
031: *
032: */
033: public class SubmitTest extends AbstractUITagTest {
034:
035: public void testDefaultValues() throws Exception {
036: TestAction testAction = (TestAction) action;
037: testAction.setFoo("bar");
038:
039: SubmitTag tag = new SubmitTag();
040: tag.setPageContext(pageContext);
041: tag.setLabel("mylabel");
042: tag.setName("myname");
043: tag.setTitle("mytitle");
044:
045: tag.doStartTag();
046: tag.doEndTag();
047:
048: verify(TextFieldTag.class.getResource("Submit-2.txt"));
049: }
050:
051: public void testSimple() throws Exception {
052: TestAction testAction = (TestAction) action;
053: testAction.setFoo("bar");
054:
055: SubmitTag tag = new SubmitTag();
056: tag.setPageContext(pageContext);
057: tag.setLabel("mylabel");
058: tag.setAlign("left");
059: tag.setName("myname");
060: tag.setValue("%{foo}");
061: tag.setDisabled("true");
062: tag.setTabindex("1");
063:
064: tag.doStartTag();
065: tag.doEndTag();
066:
067: verify(TextFieldTag.class.getResource("Submit-1.txt"));
068: }
069:
070: public void testButtonSimple() throws Exception {
071: TestAction testAction = (TestAction) action;
072: testAction.setFoo("bar");
073:
074: SubmitTag tag = new SubmitTag();
075: tag.setPageContext(pageContext);
076: tag.setType("button");
077: tag.setName("myname");
078: tag.setValue("%{foo}");
079: tag.setDisabled("true");
080: tag.setTabindex("1");
081:
082: tag.doStartTag();
083: tag.doEndTag();
084:
085: verify(TextFieldTag.class.getResource("Submit-3.txt"));
086: }
087:
088: public void testButtonSimpleWithBody() throws Exception {
089: TestAction testAction = (TestAction) action;
090: testAction.setFoo("bar");
091:
092: SubmitTag tag = new SubmitTag();
093: tag.setPageContext(pageContext);
094: tag.setType("button");
095: tag.setName("myname");
096: tag.setValue("%{foo}");
097:
098: tag.doStartTag();
099: StrutsBodyContent body = new StrutsBodyContent(null);
100: body.append("foo");
101: tag.setBodyContent(body);
102: tag.doEndTag();
103:
104: verify(TextFieldTag.class.getResource("Submit-7.txt"));
105: }
106:
107: public void testButtonWithLabel() throws Exception {
108: TestAction testAction = (TestAction) action;
109: testAction.setFoo("bar");
110:
111: SubmitTag tag = new SubmitTag();
112: tag.setPageContext(pageContext);
113: tag.setLabel("mylabel");
114: tag.setType("button");
115: tag.setAlign("left");
116: tag.setName("myname");
117: tag.setValue("%{foo}");
118:
119: tag.doStartTag();
120: tag.doEndTag();
121:
122: verify(TextFieldTag.class.getResource("Submit-4.txt"));
123: }
124:
125: public void testImageSimple() throws Exception {
126: TestAction testAction = (TestAction) action;
127: testAction.setFoo("bar");
128:
129: SubmitTag tag = new SubmitTag();
130: tag.setPageContext(pageContext);
131: tag.setType("image");
132: tag.setName("myname");
133: tag.setValue("%{foo}");
134: tag.setDisabled("true");
135:
136: tag.doStartTag();
137: tag.doEndTag();
138:
139: verify(TextFieldTag.class.getResource("Submit-5.txt"));
140: }
141:
142: public void testImageWithSrc() throws Exception {
143: TestAction testAction = (TestAction) action;
144: testAction.setFoo("bar");
145:
146: SubmitTag tag = new SubmitTag();
147: tag.setPageContext(pageContext);
148: tag.setType("image");
149: tag.setName("myname");
150: tag.setLabel("mylabel");
151: tag.setValue("%{foo}");
152: tag.setSrc("some.gif");
153:
154: tag.doStartTag();
155: tag.doEndTag();
156:
157: verify(TextFieldTag.class.getResource("Submit-6.txt"));
158: }
159:
160: public void testSimpleThemeImageUsingActionAndMethod()
161: throws Exception {
162: TestAction testAction = (TestAction) action;
163: testAction.setFoo("bar");
164:
165: SubmitTag tag = new SubmitTag();
166: tag.setPageContext(pageContext);
167: tag.setTheme("simple");
168: tag.setType("button");
169: tag.setName("myname");
170: tag.setLabel("mylabel");
171: tag.setAction("manager");
172: tag.setMethod("update");
173: tag.setAlign("left");
174:
175: tag.doStartTag();
176: tag.doEndTag();
177:
178: assertEquals(
179: "<button type=\"submit\" id=\"myname\" name=\"action:manager!update\" value=\"Submit\">mylabel</button>",
180: writer.toString().trim());
181: }
182:
183: public void testSimpleThemeImageUsingActionOnly() throws Exception {
184: TestAction testAction = (TestAction) action;
185: testAction.setFoo("bar");
186:
187: SubmitTag tag = new SubmitTag();
188: tag.setPageContext(pageContext);
189: tag.setTheme("simple");
190: tag.setType("button");
191: tag.setName("myname");
192: tag.setLabel("mylabel");
193: tag.setAction("manager");
194: tag.setMethod(null); // no method
195: tag.setAlign("left");
196:
197: tag.doStartTag();
198: tag.doEndTag();
199:
200: assertEquals(
201: "<button type=\"submit\" id=\"myname\" name=\"action:manager\" value=\"Submit\">mylabel</button>",
202: writer.toString().trim());
203: }
204:
205: public void testSimpleThemeImageUsingMethodOnly() throws Exception {
206: TestAction testAction = (TestAction) action;
207: testAction.setFoo("bar");
208:
209: SubmitTag tag = new SubmitTag();
210: tag.setPageContext(pageContext);
211: tag.setTheme("simple");
212: tag.setType("button");
213: tag.setName("myname");
214: tag.setLabel("mylabel");
215: tag.setAction(null); // no action
216: tag.setMethod("update");
217: tag.setAlign("left");
218:
219: tag.doStartTag();
220: tag.doEndTag();
221:
222: assertEquals(
223: "<button type=\"submit\" id=\"myname\" name=\"method:update\" value=\"Submit\">mylabel</button>",
224: writer.toString().trim());
225: }
226:
227: public void testSimpleThemeInput() throws Exception {
228: TestAction testAction = (TestAction) action;
229: testAction.setFoo("bar");
230:
231: SubmitTag tag = new SubmitTag();
232: tag.setPageContext(pageContext);
233: tag.setTheme("simple");
234: tag.setType("input");
235: tag.setName("myname");
236: tag.setLabel("mylabel");
237: tag.setAction(null);
238: tag.setMethod(null);
239:
240: tag.doStartTag();
241: tag.doEndTag();
242:
243: assertEquals(
244: "<input type=\"submit\" id=\"myname\" name=\"myname\" value=\"Submit\"/>",
245: writer.toString().trim());
246: }
247:
248: /**
249: * Initialize a map of {@link org.apache.struts2.views.jsp.AbstractUITagTest.PropertyHolder} for generic tag
250: * property testing. Will be used when calling {@link #verifyGenericProperties(org.apache.struts2.views.jsp.ui.AbstractUITag,
251: * String, String[])} as properties to verify.<p/> This implementation extends testdata from AbstractUITag.
252: *
253: * @return A Map of PropertyHolders values bound to {@link org.apache.struts2.views.jsp.AbstractUITagTest.PropertyHolder#getName()}
254: * as key.
255: */
256: protected Map initializedGenericTagTestProperties() {
257: Map result = new HashMap();
258: new PropertyHolder("title", "someTitle").addToMap(result);
259: new PropertyHolder("cssClass", "cssClass1",
260: "class=\"cssClass1\"").addToMap(result);
261: new PropertyHolder("cssStyle", "cssStyle1",
262: "style=\"cssStyle1\"").addToMap(result);
263: new PropertyHolder("name", "someName").addToMap(result);
264: new PropertyHolder("value", "someValue").addToMap(result);
265: return result;
266: }
267:
268: public void testGenericSimple() throws Exception {
269: SubmitTag tag = new SubmitTag();
270: verifyGenericProperties(tag, "simple", null);
271: }
272:
273: public void testGenericXhtml() throws Exception {
274: SubmitTag tag = new SubmitTag();
275: verifyGenericProperties(tag, "xhtml", null);
276: }
277:
278: public void testGenericAjax() throws Exception {
279: SubmitTag tag = new SubmitTag();
280: verifyGenericProperties(tag, "ajax", null);
281: }
282:
283: }
|