View Javadoc

1   /*
2    * $Id: DoubleSelectTest.java 539100 2007-05-17 20:19:02Z 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  package org.apache.struts2.views.jsp.ui;
22  
23  import java.util.ArrayList;
24  import java.util.Collection;
25  import java.util.List;
26  
27  import org.apache.struts2.TestAction;
28  import org.apache.struts2.views.jsp.AbstractUITagTest;
29  
30  /***
31   * Test case for DoubleSelectTag.
32   *
33   */
34  public class DoubleSelectTest extends AbstractUITagTest {
35  
36      public void testDouble() throws Exception {
37          TestAction testAction = (TestAction) action;
38  
39          Region antwerp = new Region("Antwerp", "AN");
40          Region gent = new Region("Gent", "GN");
41          Region brugge = new Region("Brugge", "BRG");
42          ArrayList belgiumRegions = new ArrayList();
43          belgiumRegions.add(antwerp);
44          belgiumRegions.add(gent);
45          belgiumRegions.add(brugge);
46          Country belgium = new Country("Belgium", "BE", belgiumRegions);
47  
48          Region paris = new Region("Paris", "PA");
49          Region bordeaux = new Region("Bordeaux", "BOR");
50          ArrayList franceRegions = new ArrayList();
51          franceRegions.add(paris);
52          franceRegions.add(bordeaux);
53          Country france = new Country("France", "FR", franceRegions);
54  
55          Collection collection = new ArrayList(2);
56          collection.add("AN");
57          testAction.setCollection(collection);
58  
59          List countries = new ArrayList();
60          countries.add(belgium);
61          countries.add(france);
62  
63          testAction.setList2(countries);
64  
65          DoubleSelectTag tag = new DoubleSelectTag();
66          tag.setPageContext(pageContext);
67          tag.setLabel("mylabel");
68          tag.setName("foo");
69          tag.setDoubleName("region");
70  
71          tag.setList("list2");
72          tag.setDoubleList("regions");
73  
74          tag.setListKey("iso");
75          tag.setDoubleListKey("key");
76          tag.setListValue("name");
77          tag.setDoubleListValue("name");
78  
79          tag.setFormName("inputForm");
80  
81          tag.setOnmousedown("window.status='onmousedown';");
82          tag.setOnmousemove("window.status='onmousemove';");
83          tag.setOnmouseout("window.status='onmouseout';");
84          tag.setOnmouseover("window.status='onmouseover';");
85          tag.setOnmouseup("window.status='onmouseup';");
86  
87          //css style and class
88          tag.setCssClass("c1");
89          tag.setCssStyle("s1");
90          tag.setDoubleCssClass("c2");
91          tag.setDoubleCssStyle("s2");
92          
93          tag.doStartTag();
94          tag.doEndTag();
95  
96          verify(SelectTag.class.getResource("DoubleSelect-1.txt"));
97      }
98  
99  
100     public void testDoubleWithDefaultSelectedValues() throws Exception {
101 
102         TestAction testAction = (TestAction) action;
103 
104         Region antwerp = new Region("Antwerp", "AN");
105         Region gent = new Region("Gent", "GN");
106         Region brugge = new Region("Brugge", "BRG");
107         ArrayList belgiumRegions = new ArrayList();
108         belgiumRegions.add(antwerp);
109         belgiumRegions.add(gent);
110         belgiumRegions.add(brugge);
111         Country belgium = new Country("Belgium", "BE", belgiumRegions);
112 
113         Region paris = new Region("Paris", "PA");
114         Region bordeaux = new Region("Bordeaux", "BOR");
115         ArrayList franceRegions = new ArrayList();
116         franceRegions.add(paris);
117         franceRegions.add(bordeaux);
118         Country france = new Country("France", "FR", franceRegions);
119 
120         Collection collection = new ArrayList(2);
121         collection.add("AN");
122         testAction.setCollection(collection);
123 
124         List countries = new ArrayList();
125         countries.add(belgium);
126         countries.add(france);
127 
128         testAction.setList2(countries);
129 
130         DoubleSelectTag tag = new DoubleSelectTag();
131         tag.setPageContext(pageContext);
132         tag.setLabel("mylabel");
133         tag.setName("foo");
134         tag.setDoubleName("region");
135 
136         tag.setValue("'FR'");
137         tag.setDoubleValue("'BOR'");
138 
139         tag.setList("list2");
140         tag.setDoubleList("regions");
141 
142         tag.setListKey("iso");
143         tag.setDoubleListKey("key");
144         tag.setListValue("name");
145         tag.setDoubleListValue("name");
146 
147         tag.setFormName("inputForm");
148 
149         tag.setOnmousedown("window.status='onmousedown';");
150         tag.setOnmousemove("window.status='onmousemove';");
151         tag.setOnmouseout("window.status='onmouseout';");
152         tag.setOnmouseover("window.status='onmouseover';");
153         tag.setOnmouseup("window.status='onmouseup';");
154 
155         tag.doStartTag();
156         tag.doEndTag();
157 
158         verify(SelectTag.class.getResource("DoubleSelect-2.txt"));
159 
160 
161     }
162     
163     public void testDoubleWithDotName() throws Exception {
164         TestAction testAction = (TestAction) action;
165 
166         Region antwerp = new Region("Antwerp", "AN");
167         Region gent = new Region("Gent", "GN");
168         Region brugge = new Region("Brugge", "BRG");
169         ArrayList belgiumRegions = new ArrayList();
170         belgiumRegions.add(antwerp);
171         belgiumRegions.add(gent);
172         belgiumRegions.add(brugge);
173         Country belgium = new Country("Belgium", "BE", belgiumRegions);
174 
175         Region paris = new Region("Paris", "PA");
176         Region bordeaux = new Region("Bordeaux", "BOR");
177         ArrayList franceRegions = new ArrayList();
178         franceRegions.add(paris);
179         franceRegions.add(bordeaux);
180         Country france = new Country("France", "FR", franceRegions);
181 
182         Collection collection = new ArrayList(2);
183         collection.add("AN");
184         testAction.setCollection(collection);
185 
186         List countries = new ArrayList();
187         countries.add(belgium);
188         countries.add(france);
189 
190         testAction.setList2(countries);
191 
192         DoubleSelectTag tag = new DoubleSelectTag();
193         tag.setPageContext(pageContext);
194         tag.setLabel("mylabel");
195         tag.setName("foo.bar");
196         tag.setDoubleName("region");
197 
198         tag.setList("list2");
199         tag.setDoubleList("regions");
200 
201         tag.setListKey("iso");
202         tag.setDoubleListKey("key");
203         tag.setListValue("name");
204         tag.setDoubleListValue("name");
205 
206         tag.setFormName("inputForm");
207 
208         tag.setOnmousedown("window.status='onmousedown';");
209         tag.setOnmousemove("window.status='onmousemove';");
210         tag.setOnmouseout("window.status='onmouseout';");
211         tag.setOnmouseover("window.status='onmouseover';");
212         tag.setOnmouseup("window.status='onmouseup';");
213 
214         tag.doStartTag();
215         tag.doEndTag();
216 
217         verify(SelectTag.class.getResource("DoubleSelect-3.txt"));
218     }
219 
220     public void testGenericSimple() throws Exception {
221         DoubleSelectTag tag = new DoubleSelectTag();
222         prepareTagGeneric(tag);
223         verifyGenericProperties(tag, "simple", new String[]{"value"});
224     }
225 
226     public void testGenericXhtml() throws Exception {
227         DoubleSelectTag tag = new DoubleSelectTag();
228         prepareTagGeneric(tag);
229         verifyGenericProperties(tag, "xhtml", new String[]{"value"});
230     }
231 
232     public void testGenericAjax() throws Exception {
233         DoubleSelectTag tag = new DoubleSelectTag();
234         prepareTagGeneric(tag);
235         verifyGenericProperties(tag, "ajax", new String[]{"value"});
236     }
237 
238     private void prepareTagGeneric(DoubleSelectTag tag) {
239         TestAction testAction = (TestAction) action;
240         Region antwerp = new Region("Antwerp", "AN");
241         Region gent = new Region("Gent", "GN");
242         Region brugge = new Region("Brugge", "BRG");
243         ArrayList belgiumRegions = new ArrayList();
244         belgiumRegions.add(antwerp);
245         belgiumRegions.add(gent);
246         belgiumRegions.add(brugge);
247         Country belgium = new Country("Belgium", "BE", belgiumRegions);
248 
249         Region paris = new Region("Paris", "PA");
250         Region bordeaux = new Region("Bordeaux", "BOR");
251         ArrayList franceRegions = new ArrayList();
252         franceRegions.add(paris);
253         franceRegions.add(bordeaux);
254         Country france = new Country("France", "FR", franceRegions);
255 
256         Collection collection = new ArrayList(2);
257         collection.add("AN");
258         testAction.setCollection(collection);
259 
260         tag.setList("collection");
261 
262         List countries = new ArrayList();
263         countries.add(belgium);
264         countries.add(france);
265 
266         testAction.setList2(countries);
267 
268         tag.setValue("'FR'");
269         tag.setDoubleValue("'BOR'");
270 
271         tag.setList("list2");
272         tag.setDoubleList("regions");
273         tag.setDoubleName("region");
274 
275         tag.setListKey("iso");
276         tag.setDoubleListKey("key");
277         tag.setListValue("name");
278         tag.setDoubleListValue("name");
279 
280         tag.setFormName("inputForm");
281     }
282 
283     public class Country {
284         String name;
285         String iso;
286         Collection regions;
287 
288         public Country(String name, String iso, Collection regions) {
289             this.name = name;
290             this.iso = iso;
291             this.regions = regions;
292         }
293 
294         public String getName() {
295             return name;
296         }
297 
298         public String getIso() {
299             return iso;
300         }
301 
302         public Collection getRegions() {
303             return regions;
304         }
305     }
306 
307     public class Region {
308         String name;
309         String key;
310 
311         public Region(String name, String key) {
312             this.name = name;
313             this.key = key;
314         }
315 
316         public String getName() {
317             return name;
318         }
319 
320         public String getKey() {
321             return key;
322         }
323     }
324 }