1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21 package org.apache.struts2.views.jsp.ui;
22
23 import org.apache.struts2.TestAction;
24 import org.apache.struts2.views.jsp.AbstractUITagTest;
25
26 import java.util.HashMap;
27 import java.util.Map;
28
29
30 /***
31 * Unit test for {@link SubmitTag}.
32 *
33 */
34 public class SubmitTest extends AbstractUITagTest {
35
36 public void testDefaultValues() throws Exception {
37 TestAction testAction = (TestAction) action;
38 testAction.setFoo("bar");
39
40 SubmitTag tag = new SubmitTag();
41 tag.setPageContext(pageContext);
42 tag.setLabel("mylabel");
43 tag.setName("myname");
44 tag.setTitle("mytitle");
45
46 tag.doStartTag();
47 tag.doEndTag();
48
49 verify(TextFieldTag.class.getResource("Submit-2.txt"));
50 }
51
52 public void testSimple() throws Exception {
53 TestAction testAction = (TestAction) action;
54 testAction.setFoo("bar");
55
56 SubmitTag tag = new SubmitTag();
57 tag.setPageContext(pageContext);
58 tag.setLabel("mylabel");
59 tag.setAlign("left");
60 tag.setName("myname");
61 tag.setValue("%{foo}");
62 tag.setDisabled("true");
63 tag.setTabindex("1");
64
65 tag.doStartTag();
66 tag.doEndTag();
67
68 verify(TextFieldTag.class.getResource("Submit-1.txt"));
69 }
70
71 public void testButtonSimple() throws Exception {
72 TestAction testAction = (TestAction) action;
73 testAction.setFoo("bar");
74
75 SubmitTag tag = new SubmitTag();
76 tag.setPageContext(pageContext);
77 tag.setType("button");
78 tag.setName("myname");
79 tag.setValue("%{foo}");
80 tag.setDisabled("true");
81 tag.setTabindex("1");
82
83 tag.doStartTag();
84 tag.doEndTag();
85
86 verify(TextFieldTag.class.getResource("Submit-3.txt"));
87 }
88
89 public void testButtonSimpleWithBody() throws Exception {
90 TestAction testAction = (TestAction) action;
91 testAction.setFoo("bar");
92
93 SubmitTag tag = new SubmitTag();
94 tag.setPageContext(pageContext);
95 tag.setType("button");
96 tag.setName("myname");
97 tag.setValue("%{foo}");
98
99 tag.doStartTag();
100 StrutsBodyContent body = new StrutsBodyContent(null);
101 body.append("foo");
102 tag.setBodyContent(body);
103 tag.doEndTag();
104
105 verify(TextFieldTag.class.getResource("Submit-7.txt"));
106 }
107
108 public void testButtonWithLabel() throws Exception {
109 TestAction testAction = (TestAction) action;
110 testAction.setFoo("bar");
111
112 SubmitTag tag = new SubmitTag();
113 tag.setPageContext(pageContext);
114 tag.setLabel("mylabel");
115 tag.setType("button");
116 tag.setAlign("left");
117 tag.setName("myname");
118 tag.setValue("%{foo}");
119
120 tag.doStartTag();
121 tag.doEndTag();
122
123 verify(TextFieldTag.class.getResource("Submit-4.txt"));
124 }
125
126 public void testImageSimple() throws Exception {
127 TestAction testAction = (TestAction) action;
128 testAction.setFoo("bar");
129
130 SubmitTag tag = new SubmitTag();
131 tag.setPageContext(pageContext);
132 tag.setType("image");
133 tag.setName("myname");
134 tag.setValue("%{foo}");
135 tag.setDisabled("true");
136
137 tag.doStartTag();
138 tag.doEndTag();
139
140 verify(TextFieldTag.class.getResource("Submit-5.txt"));
141 }
142
143 public void testImageWithSrc() throws Exception {
144 TestAction testAction = (TestAction) action;
145 testAction.setFoo("bar");
146
147 SubmitTag tag = new SubmitTag();
148 tag.setPageContext(pageContext);
149 tag.setType("image");
150 tag.setName("myname");
151 tag.setLabel("mylabel");
152 tag.setValue("%{foo}");
153 tag.setSrc("some.gif");
154
155 tag.doStartTag();
156 tag.doEndTag();
157
158 verify(TextFieldTag.class.getResource("Submit-6.txt"));
159 }
160
161 public void testSimpleThemeImageUsingActionAndMethod() 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("<button type=\"submit\" id=\"myname\" name=\"action:manager!update\" value=\"Submit\">mylabel</button>", writer.toString().trim());
179 }
180
181 public void testSimpleThemeImageUsingActionOnly() throws Exception {
182 TestAction testAction = (TestAction) action;
183 testAction.setFoo("bar");
184
185 SubmitTag tag = new SubmitTag();
186 tag.setPageContext(pageContext);
187 tag.setTheme("simple");
188 tag.setType("button");
189 tag.setName("myname");
190 tag.setLabel("mylabel");
191 tag.setAction("manager");
192 tag.setMethod(null);
193 tag.setAlign("left");
194
195 tag.doStartTag();
196 tag.doEndTag();
197
198 assertEquals("<button type=\"submit\" id=\"myname\" name=\"action:manager\" value=\"Submit\">mylabel</button>", writer.toString().trim());
199 }
200
201 public void testSimpleThemeImageUsingMethodOnly() throws Exception {
202 TestAction testAction = (TestAction) action;
203 testAction.setFoo("bar");
204
205 SubmitTag tag = new SubmitTag();
206 tag.setPageContext(pageContext);
207 tag.setTheme("simple");
208 tag.setType("button");
209 tag.setName("myname");
210 tag.setLabel("mylabel");
211 tag.setAction(null);
212 tag.setMethod("update");
213 tag.setAlign("left");
214
215 tag.doStartTag();
216 tag.doEndTag();
217
218 assertEquals("<button type=\"submit\" id=\"myname\" name=\"method:update\" value=\"Submit\">mylabel</button>", writer.toString().trim());
219 }
220
221 public void testSimpleThemeInput() throws Exception {
222 TestAction testAction = (TestAction) action;
223 testAction.setFoo("bar");
224
225 SubmitTag tag = new SubmitTag();
226 tag.setPageContext(pageContext);
227 tag.setTheme("simple");
228 tag.setType("input");
229 tag.setName("myname");
230 tag.setLabel("mylabel");
231 tag.setAction(null);
232 tag.setMethod(null);
233
234 tag.doStartTag();
235 tag.doEndTag();
236
237 assertEquals("<input type=\"submit\" id=\"myname\" name=\"myname\" value=\"Submit\"/>", writer.toString().trim());
238 }
239
240 /***
241 * Initialize a map of {@link org.apache.struts2.views.jsp.AbstractUITagTest.PropertyHolder} for generic tag
242 * property testing. Will be used when calling {@link #verifyGenericProperties(org.apache.struts2.views.jsp.ui.AbstractUITag,
243 * String, String[])} as properties to verify.<p/> This implementation extends testdata from AbstractUITag.
244 *
245 * @return A Map of PropertyHolders values bound to {@link org.apache.struts2.views.jsp.AbstractUITagTest.PropertyHolder#getName()}
246 * as key.
247 */
248 protected Map initializedGenericTagTestProperties() {
249 Map result = new HashMap();
250 new PropertyHolder("title", "someTitle").addToMap(result);
251 new PropertyHolder("cssClass", "cssClass1", "class=\"cssClass1\"").addToMap(result);
252 new PropertyHolder("cssStyle", "cssStyle1", "style=\"cssStyle1\"").addToMap(result);
253 new PropertyHolder("name", "someName").addToMap(result);
254 new PropertyHolder("value", "someValue").addToMap(result);
255 return result;
256 }
257
258 public void testGenericSimple() throws Exception {
259 SubmitTag tag = new SubmitTag();
260 verifyGenericProperties(tag, "simple", null);
261 }
262
263 public void testGenericXhtml() throws Exception {
264 SubmitTag tag = new SubmitTag();
265 verifyGenericProperties(tag, "xhtml", null);
266 }
267
268 public void testGenericAjax() throws Exception {
269 SubmitTag tag = new SubmitTag();
270 verifyGenericProperties(tag, "ajax", null);
271 }
272
273 }