View Javadoc

1   /*
2    * $Id: SubmitTest.java 678079 2008-07-19 00:08:47Z musachy $
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
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 testButtonSimpleWithBody() throws Exception {
38          TestAction testAction = (TestAction) action;
39          testAction.setFoo("bar");
40  
41          SubmitTag tag = new SubmitTag();
42          tag.setTheme("simple");
43          tag.setPageContext(pageContext);
44          tag.setType("button");
45          tag.setName("myname");
46          tag.setLabel("yoyoyoyoy");
47          tag.setValue("%{foo}");
48  
49          StrutsBodyContent body = new StrutsBodyContent(null);
50          body.print("foo");
51          tag.setBodyContent(body);
52          tag.doStartTag();
53          tag.doEndTag();
54  
55          verify(TextFieldTag.class.getResource("Submit-10.txt"));
56      }
57  
58      public void testDefaultValues() throws Exception {
59          TestAction testAction = (TestAction) action;
60          testAction.setFoo("bar");
61  
62          SubmitTag tag = new SubmitTag();
63          tag.setPageContext(pageContext);
64          tag.setLabel("mylabel");
65          tag.setName("myname");
66          tag.setTitle("mytitle");
67  
68          tag.doStartTag();
69          tag.doEndTag();
70  
71          verify(TextFieldTag.class.getResource("Submit-2.txt"));
72      }
73  
74      public void testSimple() throws Exception {
75          TestAction testAction = (TestAction) action;
76          testAction.setFoo("bar");
77  
78          SubmitTag tag = new SubmitTag();
79          tag.setPageContext(pageContext);
80          tag.setLabel("mylabel");
81          tag.setAlign("left");
82          tag.setName("myname");
83          tag.setValue("%{foo}");
84          tag.setDisabled("true");
85          tag.setTabindex("1");
86  
87          tag.doStartTag();
88          tag.doEndTag();
89  
90          verify(TextFieldTag.class.getResource("Submit-1.txt"));
91      }
92  
93      public void testButtonSimple() throws Exception {
94          TestAction testAction = (TestAction) action;
95          testAction.setFoo("bar");
96  
97          SubmitTag tag = new SubmitTag();
98          tag.setPageContext(pageContext);
99          tag.setType("button");
100         tag.setName("myname");
101         tag.setValue("%{foo}");
102         tag.setDisabled("true");
103         tag.setTabindex("1");
104 
105         tag.doStartTag();
106         tag.doEndTag();
107 
108         verify(TextFieldTag.class.getResource("Submit-3.txt"));
109     }
110 
111     public void testButtonWithLabel() throws Exception {
112         TestAction testAction = (TestAction) action;
113         testAction.setFoo("bar");
114 
115         SubmitTag tag = new SubmitTag();
116         tag.setPageContext(pageContext);
117         tag.setLabel("mylabel");
118         tag.setType("button");
119         tag.setAlign("left");
120         tag.setName("myname");
121         tag.setValue("%{foo}");
122 
123         tag.doStartTag();
124         tag.doEndTag();
125 
126         verify(TextFieldTag.class.getResource("Submit-4.txt"));
127     }
128 
129     public void testImageSimple() throws Exception {
130         TestAction testAction = (TestAction) action;
131         testAction.setFoo("bar");
132 
133         SubmitTag tag = new SubmitTag();
134         tag.setPageContext(pageContext);
135         tag.setType("image");
136         tag.setName("myname");
137         tag.setValue("%{foo}");
138         tag.setDisabled("true");
139 
140         tag.doStartTag();
141         tag.doEndTag();
142 
143         verify(TextFieldTag.class.getResource("Submit-5.txt"));
144     }
145 
146     public void testImageWithSrc() throws Exception {
147         TestAction testAction = (TestAction) action;
148         testAction.setFoo("bar");
149 
150         SubmitTag tag = new SubmitTag();
151         tag.setPageContext(pageContext);
152         tag.setType("image");
153         tag.setName("myname");
154         tag.setLabel("mylabel");
155         tag.setValue("%{foo}");
156         tag.setSrc("some.gif");
157 
158         tag.doStartTag();
159         tag.doEndTag();
160 
161         verify(TextFieldTag.class.getResource("Submit-6.txt"));
162     }
163 
164     public void testSimpleThemeImageUsingActionAndMethod() throws Exception {
165         TestAction testAction = (TestAction) action;
166         testAction.setFoo("bar");
167 
168         SubmitTag tag = new SubmitTag();
169         tag.setPageContext(pageContext);
170         tag.setTheme("simple");
171         tag.setType("button");
172         tag.setName("myname");
173         tag.setLabel("mylabel");
174         tag.setAction("manager");
175         tag.setMethod("update");
176         tag.setAlign("left");
177 
178         tag.doStartTag();
179         tag.doEndTag();
180 
181         verify(TextFieldTag.class.getResource("Submit-7.txt"));
182     }
183 
184     public void testSimpleThemeImageUsingActionOnly() throws Exception {
185         TestAction testAction = (TestAction) action;
186         testAction.setFoo("bar");
187 
188         SubmitTag tag = new SubmitTag();
189         tag.setPageContext(pageContext);
190         tag.setTheme("simple");
191         tag.setType("button");
192         tag.setName("myname");
193         tag.setLabel("mylabel");
194         tag.setAction("manager");
195         tag.setMethod(null); // no method
196         tag.setAlign("left");
197 
198         tag.doStartTag();
199         tag.doEndTag();
200 
201         verify(TextFieldTag.class.getResource("Submit-8.txt"));
202     }
203 
204     public void testSimpleThemeImageUsingMethodOnly() throws Exception {
205         TestAction testAction = (TestAction) action;
206         testAction.setFoo("bar");
207 
208         SubmitTag tag = new SubmitTag();
209         tag.setPageContext(pageContext);
210         tag.setTheme("simple");
211         tag.setType("button");
212         tag.setName("myname");
213         tag.setLabel("mylabel");
214         tag.setAction(null); // no action
215         tag.setMethod("update");
216         tag.setAlign("left");
217 
218         tag.doStartTag();
219         tag.doEndTag();
220 
221         verify(TextFieldTag.class.getResource("Submit-9.txt"));
222     }
223 
224     public void testSimpleThemeInput() throws Exception {
225         TestAction testAction = (TestAction) action;
226         testAction.setFoo("bar");
227 
228         SubmitTag tag = new SubmitTag();
229         tag.setPageContext(pageContext);
230         tag.setTheme("simple");
231         tag.setType("input");
232         tag.setName("myname");
233         tag.setLabel("mylabel");
234         tag.setAction(null);
235         tag.setMethod(null);
236 
237         tag.doStartTag();
238         tag.doEndTag();
239 
240         assertEquals("<input type=\"submit\" id=\"myname\" name=\"myname\" value=\"Submit\"/>", writer.toString().trim());
241     }
242 
243     /***
244      * Initialize a map of {@link org.apache.struts2.views.jsp.AbstractUITagTest.PropertyHolder} for generic tag
245      * property testing. Will be used when calling {@link #verifyGenericProperties(org.apache.struts2.views.jsp.ui.AbstractUITag,
246      * String, String[])} as properties to verify.<p/> This implementation extends testdata from AbstractUITag.
247      *
248      * @return A Map of PropertyHolders values bound to {@link org.apache.struts2.views.jsp.AbstractUITagTest.PropertyHolder#getName()}
249      *         as key.
250      */
251     protected Map initializedGenericTagTestProperties() {
252         Map result = new HashMap();
253         new PropertyHolder("title", "someTitle").addToMap(result);
254         new PropertyHolder("cssClass", "cssClass1", "class=\"cssClass1\"").addToMap(result);
255         new PropertyHolder("cssStyle", "cssStyle1", "style=\"cssStyle1\"").addToMap(result);
256         new PropertyHolder("name", "someName").addToMap(result);
257         new PropertyHolder("value", "someValue").addToMap(result);
258         return result;
259     }
260 
261     public void testGenericSimple() throws Exception {
262         SubmitTag tag = new SubmitTag();
263         verifyGenericProperties(tag, "simple", null);
264     }
265 
266     public void testGenericXhtml() throws Exception {
267         SubmitTag tag = new SubmitTag();
268         verifyGenericProperties(tag, "xhtml", null);
269     }
270 
271 }