View Javadoc

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