001: /*
002: * Copyright (c) 2002-2006 by OpenSymphony
003: * All rights reserved.
004: */
005: package com.opensymphony.webwork.views.jsp.ui;
006:
007: import com.opensymphony.webwork.TestAction;
008: import com.opensymphony.webwork.views.jsp.AbstractUITagTest;
009:
010: import java.util.Map;
011: import java.util.HashMap;
012:
013: /**
014: * Unit test for {@link SubmitTag}.
015: *
016: * @author plightbo
017: */
018: public class SubmitTest extends AbstractUITagTest {
019:
020: public void testDefaultValues() throws Exception {
021: TestAction testAction = (TestAction) action;
022: testAction.setFoo("bar");
023:
024: SubmitTag tag = new SubmitTag();
025: tag.setPageContext(pageContext);
026: tag.setLabel("mylabel");
027: tag.setName("myname");
028: tag.setTitle("mytitle");
029:
030: tag.doStartTag();
031: tag.doEndTag();
032:
033: verify(TextFieldTag.class.getResource("Submit-2.txt"));
034: }
035:
036: public void testSimple() throws Exception {
037: TestAction testAction = (TestAction) action;
038: testAction.setFoo("bar");
039:
040: SubmitTag tag = new SubmitTag();
041: tag.setPageContext(pageContext);
042: tag.setLabel("mylabel");
043: tag.setAlign("left");
044: tag.setName("myname");
045: tag.setValue("%{foo}");
046:
047: tag.doStartTag();
048: tag.doEndTag();
049:
050: verify(TextFieldTag.class.getResource("Submit-1.txt"));
051: }
052:
053: public void testButtonSimple() throws Exception {
054: TestAction testAction = (TestAction) action;
055: testAction.setFoo("bar");
056:
057: SubmitTag tag = new SubmitTag();
058: tag.setPageContext(pageContext);
059: tag.setType("button");
060: tag.setName("myname");
061: tag.setValue("%{foo}");
062:
063: tag.doStartTag();
064: tag.doEndTag();
065:
066: verify(TextFieldTag.class.getResource("Submit-3.txt"));
067: }
068:
069: public void testButtonWithLabel() throws Exception {
070: TestAction testAction = (TestAction) action;
071: testAction.setFoo("bar");
072:
073: SubmitTag tag = new SubmitTag();
074: tag.setPageContext(pageContext);
075: tag.setLabel("mylabel");
076: tag.setType("button");
077: tag.setAlign("left");
078: tag.setName("myname");
079: tag.setValue("%{foo}");
080:
081: tag.doStartTag();
082: tag.doEndTag();
083:
084: verify(TextFieldTag.class.getResource("Submit-4.txt"));
085: }
086:
087: public void testImageSimple() throws Exception {
088: TestAction testAction = (TestAction) action;
089: testAction.setFoo("bar");
090:
091: SubmitTag tag = new SubmitTag();
092: tag.setPageContext(pageContext);
093: tag.setType("image");
094: tag.setName("myname");
095: tag.setValue("%{foo}");
096:
097: tag.doStartTag();
098: tag.doEndTag();
099:
100: verify(TextFieldTag.class.getResource("Submit-5.txt"));
101: }
102:
103: public void testImageWithSrc() throws Exception {
104: TestAction testAction = (TestAction) action;
105: testAction.setFoo("bar");
106:
107: SubmitTag tag = new SubmitTag();
108: tag.setPageContext(pageContext);
109: tag.setType("image");
110: tag.setName("myname");
111: tag.setLabel("mylabel");
112: tag.setValue("%{foo}");
113: tag.setSrc("some.gif");
114:
115: tag.doStartTag();
116: tag.doEndTag();
117:
118: verify(TextFieldTag.class.getResource("Submit-6.txt"));
119: }
120:
121: public void testSimpleThemeImageUsingActionAndMethod()
122: throws Exception {
123: TestAction testAction = (TestAction) action;
124: testAction.setFoo("bar");
125:
126: SubmitTag tag = new SubmitTag();
127: tag.setPageContext(pageContext);
128: tag.setTheme("simple");
129: tag.setType("button");
130: tag.setName("myname");
131: tag.setLabel("mylabel");
132: tag.setAction("manager");
133: tag.setMethod("update");
134: tag.setAlign("left");
135:
136: tag.doStartTag();
137: tag.doEndTag();
138:
139: assertEquals(
140: "<button type=\"submit\" id=\"myname\" name=\"action:manager!update\" value=\"Submit\">mylabel</button>",
141: writer.toString().trim());
142: }
143:
144: public void testSimpleThemeImageUsingActionOnly() throws Exception {
145: TestAction testAction = (TestAction) action;
146: testAction.setFoo("bar");
147:
148: SubmitTag tag = new SubmitTag();
149: tag.setPageContext(pageContext);
150: tag.setTheme("simple");
151: tag.setType("button");
152: tag.setName("myname");
153: tag.setLabel("mylabel");
154: tag.setAction("manager");
155: tag.setMethod(null); // no method
156: tag.setAlign("left");
157:
158: tag.doStartTag();
159: tag.doEndTag();
160:
161: assertEquals(
162: "<button type=\"submit\" id=\"myname\" name=\"action:manager\" value=\"Submit\">mylabel</button>",
163: writer.toString().trim());
164: }
165:
166: public void testSimpleThemeImageUsingMethodOnly() throws Exception {
167: TestAction testAction = (TestAction) action;
168: testAction.setFoo("bar");
169:
170: SubmitTag tag = new SubmitTag();
171: tag.setPageContext(pageContext);
172: tag.setTheme("simple");
173: tag.setType("button");
174: tag.setName("myname");
175: tag.setLabel("mylabel");
176: tag.setAction(null); // no action
177: tag.setMethod("update");
178: tag.setAlign("left");
179:
180: tag.doStartTag();
181: tag.doEndTag();
182:
183: assertEquals(
184: "<button type=\"submit\" id=\"myname\" name=\"method:update\" value=\"Submit\">mylabel</button>",
185: writer.toString().trim());
186: }
187:
188: public void testSimpleThemeInput() throws Exception {
189: TestAction testAction = (TestAction) action;
190: testAction.setFoo("bar");
191:
192: SubmitTag tag = new SubmitTag();
193: tag.setPageContext(pageContext);
194: tag.setTheme("simple");
195: tag.setType("input");
196: tag.setName("myname");
197: tag.setLabel("mylabel");
198: tag.setAction(null);
199: tag.setMethod(null);
200:
201: tag.doStartTag();
202: tag.doEndTag();
203:
204: assertEquals(
205: "<input type=\"submit\" id=\"myname\" name=\"myname\" value=\"Submit\"/>",
206: writer.toString().trim());
207: }
208:
209: /**
210: * Initialize a map of {@link com.opensymphony.webwork.views.jsp.AbstractUITagTest.PropertyHolder} for generic tag
211: * property testing. Will be used when calling {@link #verifyGenericProperties(com.opensymphony.webwork.views.jsp.ui.AbstractUITag,
212: * String, String[])} as properties to verify.<p/> This implementation extends testdata from AbstractUITag.
213: *
214: * @return A Map of PropertyHolders values bound to {@link com.opensymphony.webwork.views.jsp.AbstractUITagTest.PropertyHolder#getName()}
215: * as key.
216: */
217: protected Map initializedGenericTagTestProperties() {
218: Map result = new HashMap();
219: new PropertyHolder("title", "someTitle").addToMap(result);
220: new PropertyHolder("cssClass", "cssClass1",
221: "class=\"cssClass1\"").addToMap(result);
222: new PropertyHolder("cssStyle", "cssStyle1",
223: "style=\"cssStyle1\"").addToMap(result);
224: new PropertyHolder("name", "someName").addToMap(result);
225: new PropertyHolder("value", "someValue").addToMap(result);
226: return result;
227: }
228:
229: public void testGenericSimple() throws Exception {
230: SubmitTag tag = new SubmitTag();
231: verifyGenericProperties(tag, "simple", null);
232: }
233:
234: public void testGenericXhtml() throws Exception {
235: SubmitTag tag = new SubmitTag();
236: verifyGenericProperties(tag, "xhtml", null);
237: }
238:
239: public void testGenericAjax() throws Exception {
240: SubmitTag tag = new SubmitTag();
241: verifyGenericProperties(tag, "ajax", null);
242: }
243:
244: }
|