View Javadoc

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