View Javadoc

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