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