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 java.util.ArrayList;
25 import java.util.LinkedHashMap;
26 import java.util.List;
27 import java.util.Map;
28
29 import org.apache.struts2.views.jsp.AbstractUITagTest;
30
31 import com.opensymphony.xwork2.Action;
32 import com.opensymphony.xwork2.ActionSupport;
33
34 /***
35 * Test case for UpDownSelectTag
36 *
37 */
38 public class UpDownSelectTagTest extends AbstractUITagTest {
39
40 public void testWithAllSelected() throws Exception {
41
42 UpDownSelectTag tag = new UpDownSelectTag();
43 tag.setPageContext(pageContext);
44 tag.setId("myId");
45 tag.setName("myName");
46 tag.setList("myMap");
47 tag.setValue("myAllSelectedMapIds");
48 tag.setEmptyOption("true");
49
50 tag.doStartTag();
51 tag.doEndTag();
52
53 verify(UpDownSelectTagTest.class.getResource("updownselecttag-1.txt"));
54 }
55
56 public void testWithPartialSelected() throws Exception {
57
58 UpDownSelectTag tag = new UpDownSelectTag();
59 tag.setPageContext(pageContext);
60 tag.setId("myId");
61 tag.setName("myName");
62 tag.setList("myMap");
63 tag.setValue("mySelectedMapIds");
64 tag.setEmptyOption("false");
65
66 tag.doStartTag();
67 tag.doEndTag();
68
69 verify(UpDownSelectTagTest.class.getResource("updownselecttag-2.txt"));
70 }
71
72 public void testWithHeaderAndEmptyOption() throws Exception {
73
74 UpDownSelectTag tag = new UpDownSelectTag();
75 tag.setPageContext(pageContext);
76 tag.setId("myId");
77 tag.setName("myName");
78 tag.setList("myMap");
79 tag.setValue("mySelectedMapIds");
80 tag.setEmptyOption("true");
81 tag.setHeaderKey("-1");
82 tag.setHeaderValue("--- Please Order ---");
83
84 tag.doStartTag();
85 tag.doEndTag();
86
87 verify(UpDownSelectTagTest.class.getResource("updownselecttag-3.txt"));
88 }
89
90 public void testWithHeaderOnly() throws Exception {
91
92 UpDownSelectTag tag = new UpDownSelectTag();
93 tag.setPageContext(pageContext);
94 tag.setId("myId");
95 tag.setName("myName");
96 tag.setList("myMap");
97 tag.setValue("mySelectedMapIds");
98 tag.setEmptyOption("false");
99 tag.setHeaderKey("-1");
100 tag.setHeaderValue("--- Please Order ---");
101
102 tag.doStartTag();
103 tag.doEndTag();
104
105 verify(UpDownSelectTagTest.class.getResource("updownselecttag-4.txt"));
106 }
107
108 public void testWithEmptyOptionOnly() throws Exception {
109
110 UpDownSelectTag tag = new UpDownSelectTag();
111 tag.setPageContext(pageContext);
112 tag.setId("myId");
113 tag.setName("myName");
114 tag.setList("myMap");
115 tag.setValue("mySelectedMapIds");
116 tag.setEmptyOption("true");
117
118 tag.doStartTag();
119 tag.doEndTag();
120
121 verify(UpDownSelectTagTest.class.getResource("updownselecttag-5.txt"));
122 }
123
124
125 public void testDisableSomeSelectAllButton() throws Exception {
126
127 UpDownSelectTag tag = new UpDownSelectTag();
128 tag.setPageContext(pageContext);
129 tag.setId("myId");
130 tag.setName("myName");
131 tag.setList("myMap");
132 tag.setValue("mySelectedMapIds");
133 tag.setEmptyOption("true");
134 tag.setAllowSelectAll("false");
135
136 tag.doStartTag();
137 tag.doEndTag();
138
139 verify(UpDownSelectTagTest.class.getResource("updownselecttag-6.txt"));
140 }
141
142 public void testDisableMoveUpButton() throws Exception {
143 UpDownSelectTag tag = new UpDownSelectTag();
144 tag.setPageContext(pageContext);
145 tag.setId("myId");
146 tag.setName("myName");
147 tag.setList("myMap");
148 tag.setValue("mySelectedMapIds");
149 tag.setEmptyOption("true");
150 tag.setAllowMoveUp("false");
151
152 tag.doStartTag();
153 tag.doEndTag();
154
155 verify(UpDownSelectTagTest.class.getResource("updownselecttag-7.txt"));
156 }
157
158 public void testDisableMoveDownButton() throws Exception {
159 UpDownSelectTag tag = new UpDownSelectTag();
160 tag.setPageContext(pageContext);
161 tag.setId("myId");
162 tag.setName("myName");
163 tag.setList("myMap");
164 tag.setValue("mySelectedMapIds");
165 tag.setEmptyOption("true");
166 tag.setAllowMoveDown("false");
167
168 tag.doStartTag();
169 tag.doEndTag();
170
171 verify(UpDownSelectTagTest.class.getResource("updownselecttag-8.txt"));
172 }
173
174 public void testChangeSelectAllButtonText() throws Exception {
175 UpDownSelectTag tag = new UpDownSelectTag();
176 tag.setPageContext(pageContext);
177 tag.setId("myId");
178 tag.setName("myName");
179 tag.setList("myMap");
180 tag.setValue("mySelectedMapIds");
181 tag.setEmptyOption("true");
182 tag.setSelectAllLabel("Select All");
183
184 tag.doStartTag();
185 tag.doEndTag();
186
187 verify(UpDownSelectTagTest.class.getResource("updownselecttag-9.txt"));
188 }
189
190 public void testChangeMoveUpButtonText() throws Exception {
191 UpDownSelectTag tag = new UpDownSelectTag();
192 tag.setPageContext(pageContext);
193 tag.setId("myId");
194 tag.setName("myName");
195 tag.setList("myMap");
196 tag.setValue("mySelectedMapIds");
197 tag.setEmptyOption("true");
198 tag.setMoveUpLabel("Move Up");
199
200 tag.doStartTag();
201 tag.doEndTag();
202
203 verify(UpDownSelectTagTest.class.getResource("updownselecttag-10.txt"));
204 }
205
206 public void testChangeMoveDownButtonText() throws Exception {
207 UpDownSelectTag tag = new UpDownSelectTag();
208 tag.setPageContext(pageContext);
209 tag.setId("myId");
210 tag.setName("myName");
211 tag.setList("myMap");
212 tag.setValue("mySelectedMapIds");
213 tag.setEmptyOption("true");
214 tag.setMoveDownLabel("Move Down");
215
216 tag.doStartTag();
217 tag.doEndTag();
218
219 verify(UpDownSelectTagTest.class.getResource("updownselecttag-11.txt"));
220 }
221
222 public void testGenericSimple() throws Exception {
223 UpDownSelectTag tag = new UpDownSelectTag();
224 prepareTagGeneric(tag);
225 verifyGenericProperties(tag, "simple", new String[]{"value"});
226 }
227
228 public void testGenericXhtml() throws Exception {
229 UpDownSelectTag tag = new UpDownSelectTag();
230 prepareTagGeneric(tag);
231 verifyGenericProperties(tag, "xhtml", new String[]{"value"});
232 }
233
234 private void prepareTagGeneric(UpDownSelectTag tag) {
235 tag.setList("myMap");
236 }
237
238
239
240
241 public Action getAction() {
242 return new ActionSupport() {
243
244 public Map getMyMap() {
245 Map _myMap = new LinkedHashMap();
246 _myMap.put("england", "England");
247 _myMap.put("america", "America");
248 _myMap.put("australia", "Australia");
249 _myMap.put("germany", "Germany");
250 return _myMap;
251 }
252
253 public List getMySelectedMapIds() {
254 List _mySelectedMapIds = new ArrayList();
255 _mySelectedMapIds.add("america");
256 _mySelectedMapIds.add("germany");
257 return _mySelectedMapIds;
258 }
259
260 public List getMyAllSelectedMapIds() {
261 List _mySelectedMapIds = new ArrayList();
262 _mySelectedMapIds.add("england");
263 _mySelectedMapIds.add("america");
264 _mySelectedMapIds.add("australia");
265 _mySelectedMapIds.add("germany");
266 return _mySelectedMapIds;
267 }
268 };
269 }
270 }