1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18 package org.apache.struts2.views.jsp.ui;
19
20 import java.util.ArrayList;
21 import java.util.Collection;
22 import java.util.List;
23
24 import org.apache.struts2.TestAction;
25 import org.apache.struts2.views.jsp.AbstractUITagTest;
26
27 /***
28 * Test case for DoubleSelectTag.
29 *
30 */
31 public class DoubleSelectTest extends AbstractUITagTest {
32
33 public void testDouble() throws Exception {
34 TestAction testAction = (TestAction) action;
35
36 Region antwerp = new Region("Antwerp", "AN");
37 Region gent = new Region("Gent", "GN");
38 Region brugge = new Region("Brugge", "BRG");
39 ArrayList belgiumRegions = new ArrayList();
40 belgiumRegions.add(antwerp);
41 belgiumRegions.add(gent);
42 belgiumRegions.add(brugge);
43 Country belgium = new Country("Belgium", "BE", belgiumRegions);
44
45 Region paris = new Region("Paris", "PA");
46 Region bordeaux = new Region("Bordeaux", "BOR");
47 ArrayList franceRegions = new ArrayList();
48 franceRegions.add(paris);
49 franceRegions.add(bordeaux);
50 Country france = new Country("France", "FR", franceRegions);
51
52 Collection collection = new ArrayList(2);
53 collection.add("AN");
54 testAction.setCollection(collection);
55
56 List countries = new ArrayList();
57 countries.add(belgium);
58 countries.add(france);
59
60 testAction.setList2(countries);
61
62 DoubleSelectTag tag = new DoubleSelectTag();
63 tag.setPageContext(pageContext);
64 tag.setLabel("mylabel");
65 tag.setName("foo");
66 tag.setDoubleName("region");
67
68 tag.setList("list2");
69 tag.setDoubleList("regions");
70
71 tag.setListKey("iso");
72 tag.setDoubleListKey("key");
73 tag.setListValue("name");
74 tag.setDoubleListValue("name");
75
76 tag.setFormName("inputForm");
77
78 tag.setOnmousedown("window.status='onmousedown';");
79 tag.setOnmousemove("window.status='onmousemove';");
80 tag.setOnmouseout("window.status='onmouseout';");
81 tag.setOnmouseover("window.status='onmouseover';");
82 tag.setOnmouseup("window.status='onmouseup';");
83
84 tag.doStartTag();
85 tag.doEndTag();
86
87 verify(SelectTag.class.getResource("DoubleSelect-1.txt"));
88 }
89
90
91 public void testDoubleWithDefaultSelectedValues() throws Exception {
92
93 TestAction testAction = (TestAction) action;
94
95 Region antwerp = new Region("Antwerp", "AN");
96 Region gent = new Region("Gent", "GN");
97 Region brugge = new Region("Brugge", "BRG");
98 ArrayList belgiumRegions = new ArrayList();
99 belgiumRegions.add(antwerp);
100 belgiumRegions.add(gent);
101 belgiumRegions.add(brugge);
102 Country belgium = new Country("Belgium", "BE", belgiumRegions);
103
104 Region paris = new Region("Paris", "PA");
105 Region bordeaux = new Region("Bordeaux", "BOR");
106 ArrayList franceRegions = new ArrayList();
107 franceRegions.add(paris);
108 franceRegions.add(bordeaux);
109 Country france = new Country("France", "FR", franceRegions);
110
111 Collection collection = new ArrayList(2);
112 collection.add("AN");
113 testAction.setCollection(collection);
114
115 List countries = new ArrayList();
116 countries.add(belgium);
117 countries.add(france);
118
119 testAction.setList2(countries);
120
121 DoubleSelectTag tag = new DoubleSelectTag();
122 tag.setPageContext(pageContext);
123 tag.setLabel("mylabel");
124 tag.setName("foo");
125 tag.setDoubleName("region");
126
127 tag.setValue("'FR'");
128 tag.setDoubleValue("'BOR'");
129
130 tag.setList("list2");
131 tag.setDoubleList("regions");
132
133 tag.setListKey("iso");
134 tag.setDoubleListKey("key");
135 tag.setListValue("name");
136 tag.setDoubleListValue("name");
137
138 tag.setFormName("inputForm");
139
140 tag.setOnmousedown("window.status='onmousedown';");
141 tag.setOnmousemove("window.status='onmousemove';");
142 tag.setOnmouseout("window.status='onmouseout';");
143 tag.setOnmouseover("window.status='onmouseover';");
144 tag.setOnmouseup("window.status='onmouseup';");
145
146 tag.doStartTag();
147 tag.doEndTag();
148
149 verify(SelectTag.class.getResource("DoubleSelect-2.txt"));
150
151
152 }
153
154
155 public void testGenericSimple() throws Exception {
156 DoubleSelectTag tag = new DoubleSelectTag();
157 prepareTagGeneric(tag);
158 verifyGenericProperties(tag, "simple", new String[]{"value"});
159 }
160
161 public void testGenericXhtml() throws Exception {
162 DoubleSelectTag tag = new DoubleSelectTag();
163 prepareTagGeneric(tag);
164 verifyGenericProperties(tag, "xhtml", new String[]{"value"});
165 }
166
167 public void testGenericAjax() throws Exception {
168 DoubleSelectTag tag = new DoubleSelectTag();
169 prepareTagGeneric(tag);
170 verifyGenericProperties(tag, "ajax", new String[]{"value"});
171 }
172
173 private void prepareTagGeneric(DoubleSelectTag tag) {
174 TestAction testAction = (TestAction) action;
175 Region antwerp = new Region("Antwerp", "AN");
176 Region gent = new Region("Gent", "GN");
177 Region brugge = new Region("Brugge", "BRG");
178 ArrayList belgiumRegions = new ArrayList();
179 belgiumRegions.add(antwerp);
180 belgiumRegions.add(gent);
181 belgiumRegions.add(brugge);
182 Country belgium = new Country("Belgium", "BE", belgiumRegions);
183
184 Region paris = new Region("Paris", "PA");
185 Region bordeaux = new Region("Bordeaux", "BOR");
186 ArrayList franceRegions = new ArrayList();
187 franceRegions.add(paris);
188 franceRegions.add(bordeaux);
189 Country france = new Country("France", "FR", franceRegions);
190
191 Collection collection = new ArrayList(2);
192 collection.add("AN");
193 testAction.setCollection(collection);
194
195 tag.setList("collection");
196
197 List countries = new ArrayList();
198 countries.add(belgium);
199 countries.add(france);
200
201 testAction.setList2(countries);
202
203 tag.setValue("'FR'");
204 tag.setDoubleValue("'BOR'");
205
206 tag.setList("list2");
207 tag.setDoubleList("regions");
208 tag.setDoubleName("region");
209
210 tag.setListKey("iso");
211 tag.setDoubleListKey("key");
212 tag.setListValue("name");
213 tag.setDoubleListValue("name");
214
215 tag.setFormName("inputForm");
216 }
217
218 public class Country {
219 String name;
220 String iso;
221 Collection regions;
222
223 public Country(String name, String iso, Collection regions) {
224 this.name = name;
225 this.iso = iso;
226 this.regions = regions;
227 }
228
229 public String getName() {
230 return name;
231 }
232
233 public String getIso() {
234 return iso;
235 }
236
237 public Collection getRegions() {
238 return regions;
239 }
240 }
241
242 public class Region {
243 String name;
244 String key;
245
246 public Region(String name, String key) {
247 this.name = name;
248 this.key = key;
249 }
250
251 public String getName() {
252 return name;
253 }
254
255 public String getKey() {
256 return key;
257 }
258 }
259 }