View Javadoc

1   /*
2    * $Id: OptionTransferSelectTagTest.java 651946 2008-04-27 13:41:38Z apetrelli $
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 java.util.ArrayList;
25  import java.util.List;
26  
27  import org.apache.struts2.TestAction;
28  import org.apache.struts2.views.jsp.AbstractUITagTest;
29  
30  /***
31   *
32   */
33  public class OptionTransferSelectTagTest extends AbstractUITagTest {
34  
35      public void testWithAllSelected() throws Exception {
36          List left = new ArrayList();
37          left.add("Left1");
38          left.add("Left2");
39  
40          List right = new ArrayList();
41          right.add("Right1");
42          right.add("Right2");
43  
44          TestAction testaction = (TestAction) action;
45          testaction.setCollection(left);
46          testaction.setList2(right);
47  
48          OptionTransferSelectTag tag = new OptionTransferSelectTag();
49          tag.setPageContext(pageContext);
50  
51          tag.setName("collection");
52          tag.setId("id");
53          tag.setList("collection");
54          tag.setSize("20");
55          tag.setMultiple("true");
56          tag.setEmptyOption("true");
57  
58          tag.setDoubleName("list2");
59          tag.setDoubleList("list2");
60          tag.setDoubleId("doubleId");
61          tag.setDoubleSize("20");
62          tag.setMultiple("true");
63          tag.setDoubleEmptyOption("true");
64          tag.setDoubleCssClass("c2");
65          tag.setDoubleCssStyle("s2");
66  
67          tag.setAllowAddAllToLeft("true");
68          tag.setAllowAddAllToRight("true");
69          tag.setAllowAddToLeft("true");
70          tag.setAllowAddToRight("true");
71          tag.setAllowSelectAll("true");
72  
73          tag.setAddAllToLeftLabel("All Left");
74          tag.setAddAllToRightLabel("All Right");
75          tag.setAddToLeftLabel("Left");
76          tag.setAddToRightLabel("Right");
77          tag.setSelectAllLabel("Select All");
78  
79          tag.setLeftTitle("Title Left");
80          tag.setRightTitle("Title Right");
81  
82          tag.setButtonCssClass("buttonCssClass");
83          tag.setButtonCssStyle("buttonCssStyle");
84  
85          tag.setHeaderKey("Header Key");
86          tag.setHeaderValue("Header Value");
87  
88          tag.setDoubleHeaderKey("Double Header Key");
89          tag.setDoubleHeaderValue("Double Header Value");
90  
91          tag.doStartTag();
92          tag.doEndTag();
93  
94          //System.out.println(writer.toString());
95          verify(OptionTransferSelectTagTest.class.getResource("optiontransferselect-1.txt"));
96      }
97  
98      public void testWithPartialSelectedOnBothSides() throws Exception {
99          List left = new ArrayList();
100         left.add("Left2");
101 
102         List right = new ArrayList();
103         right.add("Right2");
104 
105         List leftVal = new ArrayList();
106         leftVal.add("Left1");
107         leftVal.add("Left2");
108         leftVal.add("Left3");
109 
110         List rightVal = new ArrayList();
111         rightVal.add("Right1");
112         rightVal.add("Right2");
113         rightVal.add("Right3");
114 
115 
116         TestAction testaction = (TestAction) action;
117         testaction.setCollection(left);
118         testaction.setList2(right);
119         testaction.setCollection2(leftVal);
120         testaction.setList3(rightVal);
121 
122 
123         OptionTransferSelectTag tag = new OptionTransferSelectTag();
124         tag.setPageContext(pageContext);
125 
126         tag.setName("collection");
127         tag.setId("id");
128         tag.setList("collection2");
129         tag.setSize("20");
130         tag.setMultiple("true");
131         tag.setEmptyOption("true");
132 
133         tag.setDoubleName("list2");
134         tag.setDoubleList("list3");
135         tag.setDoubleId("doubleId");
136         tag.setDoubleSize("20");
137         tag.setMultiple("true");
138         tag.setDoubleEmptyOption("true");
139 
140         tag.setAllowAddAllToLeft("true");
141         tag.setAllowAddAllToRight("true");
142         tag.setAllowAddToLeft("true");
143         tag.setAllowAddToRight("true");
144         tag.setAllowSelectAll("true");
145 
146         tag.setAddAllToLeftLabel("All Left");
147         tag.setAddAllToRightLabel("All Right");
148         tag.setAddToLeftLabel("Left");
149         tag.setAddToRightLabel("Right");
150         tag.setSelectAllLabel("Select All");
151 
152         tag.setLeftTitle("Title Left");
153         tag.setRightTitle("Title Right");
154 
155         tag.setButtonCssClass("buttonCssClass");
156         tag.setButtonCssStyle("buttonCssStyle");
157 
158         tag.setHeaderKey("Header Key");
159         tag.setHeaderValue("Header Value");
160 
161         tag.setDoubleHeaderKey("Double Header Key");
162         tag.setDoubleHeaderValue("Double Header Value");
163 
164         tag.doStartTag();
165         tag.doEndTag();
166 
167         //System.out.println(writer.toString());
168         verify(OptionTransferSelectTagTest.class.getResource("optiontransferselect-2.txt"));
169     }
170 
171     public void testWithoutHeaderOnBothSides() throws Exception {
172         List left = new ArrayList();
173         left.add("Left2");
174 
175         List right = new ArrayList();
176         right.add("Right2");
177 
178         List leftVal = new ArrayList();
179         leftVal.add("Left1");
180         leftVal.add("Left2");
181         leftVal.add("Left3");
182 
183         List rightVal = new ArrayList();
184         rightVal.add("Right1");
185         rightVal.add("Right2");
186         rightVal.add("Right3");
187 
188 
189         TestAction testaction = (TestAction) action;
190         testaction.setCollection(left);
191         testaction.setList2(right);
192         testaction.setCollection2(leftVal);
193         testaction.setList3(rightVal);
194 
195 
196         OptionTransferSelectTag tag = new OptionTransferSelectTag();
197         tag.setPageContext(pageContext);
198 
199         tag.setName("collection");
200         tag.setId("id");
201         tag.setList("collection2");
202         tag.setSize("20");
203         tag.setMultiple("true");
204         tag.setEmptyOption("true");
205 
206         tag.setDoubleName("list2");
207         tag.setDoubleList("list3");
208         tag.setDoubleId("doubleId");
209         tag.setDoubleSize("20");
210         tag.setMultiple("true");
211         tag.setDoubleEmptyOption("true");
212 
213         tag.setAllowAddAllToLeft("true");
214         tag.setAllowAddAllToRight("true");
215         tag.setAllowAddToLeft("true");
216         tag.setAllowAddToRight("true");
217         tag.setAllowSelectAll("true");
218 
219         tag.setAddAllToLeftLabel("All Left");
220         tag.setAddAllToRightLabel("All Right");
221         tag.setAddToLeftLabel("Left");
222         tag.setAddToRightLabel("Right");
223         tag.setSelectAllLabel("Select All");
224 
225         tag.setLeftTitle("Title Left");
226         tag.setRightTitle("Title Right");
227 
228         tag.setButtonCssClass("buttonCssClass");
229         tag.setButtonCssStyle("buttonCssStyle");
230 
231         tag.doStartTag();
232         tag.doEndTag();
233 
234         //System.out.println(writer.toString());
235         verify(OptionTransferSelectTagTest.class.getResource("optiontransferselect-3.txt"));
236     }
237 
238     public void testWithoutHeaderOnOneSide() throws Exception {
239         List left = new ArrayList();
240         left.add("Left2");
241 
242         List right = new ArrayList();
243         right.add("Right2");
244 
245         List leftVal = new ArrayList();
246         leftVal.add("Left1");
247         leftVal.add("Left2");
248         leftVal.add("Left3");
249 
250         List rightVal = new ArrayList();
251         rightVal.add("Right1");
252         rightVal.add("Right2");
253         rightVal.add("Right3");
254 
255 
256         TestAction testaction = (TestAction) action;
257         testaction.setCollection(left);
258         testaction.setList2(right);
259         testaction.setCollection2(leftVal);
260         testaction.setList3(rightVal);
261 
262 
263         OptionTransferSelectTag tag = new OptionTransferSelectTag();
264         tag.setPageContext(pageContext);
265 
266         tag.setName("collection");
267         tag.setId("id");
268         tag.setList("collection2");
269         tag.setSize("20");
270         tag.setMultiple("true");
271         tag.setEmptyOption("true");
272 
273         tag.setDoubleName("list2");
274         tag.setDoubleList("list3");
275         tag.setDoubleId("doubleId");
276         tag.setDoubleSize("20");
277         tag.setMultiple("true");
278         tag.setDoubleEmptyOption("true");
279 
280         tag.setAllowAddAllToLeft("true");
281         tag.setAllowAddAllToRight("true");
282         tag.setAllowAddToLeft("true");
283         tag.setAllowAddToRight("true");
284         tag.setAllowSelectAll("true");
285 
286         tag.setAddAllToLeftLabel("All Left");
287         tag.setAddAllToRightLabel("All Right");
288         tag.setAddToLeftLabel("Left");
289         tag.setAddToRightLabel("Right");
290         tag.setSelectAllLabel("Select All");
291 
292         tag.setLeftTitle("Title Left");
293         tag.setRightTitle("Title Right");
294 
295         tag.setButtonCssClass("buttonCssClass");
296         tag.setButtonCssStyle("buttonCssStyle");
297 
298         tag.setHeaderKey("Header Key");
299         tag.setHeaderValue("Header Value");
300 
301         tag.doStartTag();
302         tag.doEndTag();
303 
304         //System.out.println(writer.toString());
305         verify(OptionTransferSelectTagTest.class.getResource("optiontransferselect-4.txt"));
306     }
307 
308     public void testWithoutEmptyOptionOnBothSides() throws Exception {
309         List left = new ArrayList();
310         left.add("Left2");
311 
312         List right = new ArrayList();
313         right.add("Right2");
314 
315         List leftVal = new ArrayList();
316         leftVal.add("Left1");
317         leftVal.add("Left2");
318         leftVal.add("Left3");
319 
320         List rightVal = new ArrayList();
321         rightVal.add("Right1");
322         rightVal.add("Right2");
323         rightVal.add("Right3");
324 
325 
326         TestAction testaction = (TestAction) action;
327         testaction.setCollection(left);
328         testaction.setList2(right);
329         testaction.setCollection2(leftVal);
330         testaction.setList3(rightVal);
331 
332 
333         OptionTransferSelectTag tag = new OptionTransferSelectTag();
334         tag.setPageContext(pageContext);
335 
336         tag.setName("collection");
337         tag.setId("id");
338         tag.setList("collection2");
339         tag.setSize("20");
340         tag.setMultiple("true");
341         tag.setEmptyOption("false");
342 
343         tag.setDoubleName("list2");
344         tag.setDoubleList("list3");
345         tag.setDoubleId("doubleId");
346         tag.setDoubleSize("20");
347         tag.setMultiple("true");
348         tag.setDoubleEmptyOption("false");
349 
350         tag.setAllowAddAllToLeft("true");
351         tag.setAllowAddAllToRight("true");
352         tag.setAllowAddToLeft("true");
353         tag.setAllowAddToRight("true");
354         tag.setAllowSelectAll("true");
355 
356         tag.setAddAllToLeftLabel("All Left");
357         tag.setAddAllToRightLabel("All Right");
358         tag.setAddToLeftLabel("Left");
359         tag.setAddToRightLabel("Right");
360         tag.setSelectAllLabel("Select All");
361 
362         tag.setLeftTitle("Title Left");
363         tag.setRightTitle("Title Right");
364 
365         tag.setButtonCssClass("buttonCssClass");
366         tag.setButtonCssStyle("buttonCssStyle");
367 
368         tag.setHeaderKey("Header Key");
369         tag.setHeaderValue("Header Value");
370 
371         tag.setDoubleHeaderKey("Double Header Key");
372         tag.setDoubleHeaderValue("Double Header Value");
373 
374         tag.doStartTag();
375         tag.doEndTag();
376 
377         //System.out.println(writer.toString());
378         verify(OptionTransferSelectTagTest.class.getResource("optiontransferselect-5.txt"));
379     }
380 
381     public void testWithoutEmptyOptionOnOneSide() throws Exception {
382         List left = new ArrayList();
383         left.add("Left2");
384 
385         List right = new ArrayList();
386         right.add("Right2");
387 
388         List leftVal = new ArrayList();
389         leftVal.add("Left1");
390         leftVal.add("Left2");
391         leftVal.add("Left3");
392 
393         List rightVal = new ArrayList();
394         rightVal.add("Right1");
395         rightVal.add("Right2");
396         rightVal.add("Right3");
397 
398 
399         TestAction testaction = (TestAction) action;
400         testaction.setCollection(left);
401         testaction.setList2(right);
402         testaction.setCollection2(leftVal);
403         testaction.setList3(rightVal);
404 
405 
406         OptionTransferSelectTag tag = new OptionTransferSelectTag();
407         tag.setPageContext(pageContext);
408 
409         tag.setName("collection");
410         tag.setId("id");
411         tag.setList("collection2");
412         tag.setSize("20");
413         tag.setMultiple("true");
414         tag.setEmptyOption("true");
415 
416         tag.setDoubleName("list2");
417         tag.setDoubleList("list3");
418         tag.setDoubleId("doubleId");
419         tag.setDoubleSize("20");
420         tag.setMultiple("true");
421         tag.setDoubleEmptyOption("false");
422 
423         tag.setAllowAddAllToLeft("true");
424         tag.setAllowAddAllToRight("true");
425         tag.setAllowAddToLeft("true");
426         tag.setAllowAddToRight("true");
427         tag.setAllowSelectAll("true");
428 
429         tag.setAddAllToLeftLabel("All Left");
430         tag.setAddAllToRightLabel("All Right");
431         tag.setAddToLeftLabel("Left");
432         tag.setAddToRightLabel("Right");
433         tag.setSelectAllLabel("Select All");
434 
435         tag.setLeftTitle("Title Left");
436         tag.setRightTitle("Title Right");
437 
438         tag.setButtonCssClass("buttonCssClass");
439         tag.setButtonCssStyle("buttonCssStyle");
440 
441         tag.setHeaderKey("Header Key");
442         tag.setHeaderValue("Header Value");
443 
444         tag.setDoubleHeaderKey("Double Header Key");
445         tag.setDoubleHeaderValue("Double Header Value");
446 
447         tag.doStartTag();
448         tag.doEndTag();
449 
450         //System.out.println(writer.toString());
451         verify(OptionTransferSelectTagTest.class.getResource("optiontransferselect-6.txt"));
452     }
453 
454     public void testDisableSomeButtons() throws Exception {
455         List left = new ArrayList();
456         left.add("Left2");
457 
458         List right = new ArrayList();
459         right.add("Right2");
460 
461         List leftVal = new ArrayList();
462         leftVal.add("Left1");
463         leftVal.add("Left2");
464         leftVal.add("Left3");
465 
466         List rightVal = new ArrayList();
467         rightVal.add("Right1");
468         rightVal.add("Right2");
469         rightVal.add("Right3");
470 
471 
472         TestAction testaction = (TestAction) action;
473         testaction.setCollection(left);
474         testaction.setList2(right);
475         testaction.setCollection2(leftVal);
476         testaction.setList3(rightVal);
477 
478 
479         OptionTransferSelectTag tag = new OptionTransferSelectTag();
480         tag.setPageContext(pageContext);
481 
482         tag.setName("collection");
483         tag.setId("id");
484         tag.setList("collection2");
485         tag.setSize("20");
486         tag.setMultiple("true");
487         tag.setEmptyOption("true");
488 
489         tag.setDoubleName("list2");
490         tag.setDoubleList("list3");
491         tag.setDoubleId("doubleId");
492         tag.setDoubleSize("20");
493         tag.setMultiple("true");
494         tag.setDoubleEmptyOption("true");
495 
496         tag.setAllowAddAllToLeft("false");
497         tag.setAllowAddAllToRight("false");
498         tag.setAllowAddToLeft("true");
499         tag.setAllowAddToRight("true");
500         tag.setAllowSelectAll("false");
501 
502         tag.setAddAllToLeftLabel("All Left");
503         tag.setAddAllToRightLabel("All Right");
504         tag.setAddToLeftLabel("Left");
505         tag.setAddToRightLabel("Right");
506         tag.setSelectAllLabel("Select All");
507 
508         tag.setLeftTitle("Title Left");
509         tag.setRightTitle("Title Right");
510 
511         tag.setButtonCssClass("buttonCssClass");
512         tag.setButtonCssStyle("buttonCssStyle");
513 
514         tag.setHeaderKey("Header Key");
515         tag.setHeaderValue("Header Value");
516 
517         tag.setDoubleHeaderKey("Double Header Key");
518         tag.setDoubleHeaderValue("Double Header Value");
519 
520         tag.setAddToLeftOnclick("alert('Moving Left')");
521         tag.setAddToRightOnclick("alert('Moving Right')");
522 
523         tag.doStartTag();
524         tag.doEndTag();
525 
526         //System.out.println(writer.toString());
527         verify(OptionTransferSelectTagTest.class.getResource("optiontransferselect-7.txt"));
528     }
529 }