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