View Javadoc

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