001: /*
002: * $Id: DoubleSelectTest.java 539100 2007-05-17 20:19:02Z musachy $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021: package org.apache.struts2.views.jsp.ui;
022:
023: import java.util.ArrayList;
024: import java.util.Collection;
025: import java.util.List;
026:
027: import org.apache.struts2.TestAction;
028: import org.apache.struts2.views.jsp.AbstractUITagTest;
029:
030: /**
031: * Test case for DoubleSelectTag.
032: *
033: */
034: public class DoubleSelectTest extends AbstractUITagTest {
035:
036: public void testDouble() throws Exception {
037: TestAction testAction = (TestAction) action;
038:
039: Region antwerp = new Region("Antwerp", "AN");
040: Region gent = new Region("Gent", "GN");
041: Region brugge = new Region("Brugge", "BRG");
042: ArrayList belgiumRegions = new ArrayList();
043: belgiumRegions.add(antwerp);
044: belgiumRegions.add(gent);
045: belgiumRegions.add(brugge);
046: Country belgium = new Country("Belgium", "BE", belgiumRegions);
047:
048: Region paris = new Region("Paris", "PA");
049: Region bordeaux = new Region("Bordeaux", "BOR");
050: ArrayList franceRegions = new ArrayList();
051: franceRegions.add(paris);
052: franceRegions.add(bordeaux);
053: Country france = new Country("France", "FR", franceRegions);
054:
055: Collection collection = new ArrayList(2);
056: collection.add("AN");
057: testAction.setCollection(collection);
058:
059: List countries = new ArrayList();
060: countries.add(belgium);
061: countries.add(france);
062:
063: testAction.setList2(countries);
064:
065: DoubleSelectTag tag = new DoubleSelectTag();
066: tag.setPageContext(pageContext);
067: tag.setLabel("mylabel");
068: tag.setName("foo");
069: tag.setDoubleName("region");
070:
071: tag.setList("list2");
072: tag.setDoubleList("regions");
073:
074: tag.setListKey("iso");
075: tag.setDoubleListKey("key");
076: tag.setListValue("name");
077: tag.setDoubleListValue("name");
078:
079: tag.setFormName("inputForm");
080:
081: tag.setOnmousedown("window.status='onmousedown';");
082: tag.setOnmousemove("window.status='onmousemove';");
083: tag.setOnmouseout("window.status='onmouseout';");
084: tag.setOnmouseover("window.status='onmouseover';");
085: tag.setOnmouseup("window.status='onmouseup';");
086:
087: //css style and class
088: tag.setCssClass("c1");
089: tag.setCssStyle("s1");
090: tag.setDoubleCssClass("c2");
091: tag.setDoubleCssStyle("s2");
092:
093: tag.doStartTag();
094: tag.doEndTag();
095:
096: verify(SelectTag.class.getResource("DoubleSelect-1.txt"));
097: }
098:
099: public void testDoubleWithDefaultSelectedValues() throws Exception {
100:
101: TestAction testAction = (TestAction) action;
102:
103: Region antwerp = new Region("Antwerp", "AN");
104: Region gent = new Region("Gent", "GN");
105: Region brugge = new Region("Brugge", "BRG");
106: ArrayList belgiumRegions = new ArrayList();
107: belgiumRegions.add(antwerp);
108: belgiumRegions.add(gent);
109: belgiumRegions.add(brugge);
110: Country belgium = new Country("Belgium", "BE", belgiumRegions);
111:
112: Region paris = new Region("Paris", "PA");
113: Region bordeaux = new Region("Bordeaux", "BOR");
114: ArrayList franceRegions = new ArrayList();
115: franceRegions.add(paris);
116: franceRegions.add(bordeaux);
117: Country france = new Country("France", "FR", franceRegions);
118:
119: Collection collection = new ArrayList(2);
120: collection.add("AN");
121: testAction.setCollection(collection);
122:
123: List countries = new ArrayList();
124: countries.add(belgium);
125: countries.add(france);
126:
127: testAction.setList2(countries);
128:
129: DoubleSelectTag tag = new DoubleSelectTag();
130: tag.setPageContext(pageContext);
131: tag.setLabel("mylabel");
132: tag.setName("foo");
133: tag.setDoubleName("region");
134:
135: tag.setValue("'FR'");
136: tag.setDoubleValue("'BOR'");
137:
138: tag.setList("list2");
139: tag.setDoubleList("regions");
140:
141: tag.setListKey("iso");
142: tag.setDoubleListKey("key");
143: tag.setListValue("name");
144: tag.setDoubleListValue("name");
145:
146: tag.setFormName("inputForm");
147:
148: tag.setOnmousedown("window.status='onmousedown';");
149: tag.setOnmousemove("window.status='onmousemove';");
150: tag.setOnmouseout("window.status='onmouseout';");
151: tag.setOnmouseover("window.status='onmouseover';");
152: tag.setOnmouseup("window.status='onmouseup';");
153:
154: tag.doStartTag();
155: tag.doEndTag();
156:
157: verify(SelectTag.class.getResource("DoubleSelect-2.txt"));
158:
159: }
160:
161: public void testDoubleWithDotName() throws Exception {
162: TestAction testAction = (TestAction) action;
163:
164: Region antwerp = new Region("Antwerp", "AN");
165: Region gent = new Region("Gent", "GN");
166: Region brugge = new Region("Brugge", "BRG");
167: ArrayList belgiumRegions = new ArrayList();
168: belgiumRegions.add(antwerp);
169: belgiumRegions.add(gent);
170: belgiumRegions.add(brugge);
171: Country belgium = new Country("Belgium", "BE", belgiumRegions);
172:
173: Region paris = new Region("Paris", "PA");
174: Region bordeaux = new Region("Bordeaux", "BOR");
175: ArrayList franceRegions = new ArrayList();
176: franceRegions.add(paris);
177: franceRegions.add(bordeaux);
178: Country france = new Country("France", "FR", franceRegions);
179:
180: Collection collection = new ArrayList(2);
181: collection.add("AN");
182: testAction.setCollection(collection);
183:
184: List countries = new ArrayList();
185: countries.add(belgium);
186: countries.add(france);
187:
188: testAction.setList2(countries);
189:
190: DoubleSelectTag tag = new DoubleSelectTag();
191: tag.setPageContext(pageContext);
192: tag.setLabel("mylabel");
193: tag.setName("foo.bar");
194: tag.setDoubleName("region");
195:
196: tag.setList("list2");
197: tag.setDoubleList("regions");
198:
199: tag.setListKey("iso");
200: tag.setDoubleListKey("key");
201: tag.setListValue("name");
202: tag.setDoubleListValue("name");
203:
204: tag.setFormName("inputForm");
205:
206: tag.setOnmousedown("window.status='onmousedown';");
207: tag.setOnmousemove("window.status='onmousemove';");
208: tag.setOnmouseout("window.status='onmouseout';");
209: tag.setOnmouseover("window.status='onmouseover';");
210: tag.setOnmouseup("window.status='onmouseup';");
211:
212: tag.doStartTag();
213: tag.doEndTag();
214:
215: verify(SelectTag.class.getResource("DoubleSelect-3.txt"));
216: }
217:
218: public void testGenericSimple() throws Exception {
219: DoubleSelectTag tag = new DoubleSelectTag();
220: prepareTagGeneric(tag);
221: verifyGenericProperties(tag, "simple", new String[] { "value" });
222: }
223:
224: public void testGenericXhtml() throws Exception {
225: DoubleSelectTag tag = new DoubleSelectTag();
226: prepareTagGeneric(tag);
227: verifyGenericProperties(tag, "xhtml", new String[] { "value" });
228: }
229:
230: public void testGenericAjax() throws Exception {
231: DoubleSelectTag tag = new DoubleSelectTag();
232: prepareTagGeneric(tag);
233: verifyGenericProperties(tag, "ajax", new String[] { "value" });
234: }
235:
236: private void prepareTagGeneric(DoubleSelectTag tag) {
237: TestAction testAction = (TestAction) action;
238: Region antwerp = new Region("Antwerp", "AN");
239: Region gent = new Region("Gent", "GN");
240: Region brugge = new Region("Brugge", "BRG");
241: ArrayList belgiumRegions = new ArrayList();
242: belgiumRegions.add(antwerp);
243: belgiumRegions.add(gent);
244: belgiumRegions.add(brugge);
245: Country belgium = new Country("Belgium", "BE", belgiumRegions);
246:
247: Region paris = new Region("Paris", "PA");
248: Region bordeaux = new Region("Bordeaux", "BOR");
249: ArrayList franceRegions = new ArrayList();
250: franceRegions.add(paris);
251: franceRegions.add(bordeaux);
252: Country france = new Country("France", "FR", franceRegions);
253:
254: Collection collection = new ArrayList(2);
255: collection.add("AN");
256: testAction.setCollection(collection);
257:
258: tag.setList("collection");
259:
260: List countries = new ArrayList();
261: countries.add(belgium);
262: countries.add(france);
263:
264: testAction.setList2(countries);
265:
266: tag.setValue("'FR'");
267: tag.setDoubleValue("'BOR'");
268:
269: tag.setList("list2");
270: tag.setDoubleList("regions");
271: tag.setDoubleName("region");
272:
273: tag.setListKey("iso");
274: tag.setDoubleListKey("key");
275: tag.setListValue("name");
276: tag.setDoubleListValue("name");
277:
278: tag.setFormName("inputForm");
279: }
280:
281: public class Country {
282: String name;
283: String iso;
284: Collection regions;
285:
286: public Country(String name, String iso, Collection regions) {
287: this .name = name;
288: this .iso = iso;
289: this .regions = regions;
290: }
291:
292: public String getName() {
293: return name;
294: }
295:
296: public String getIso() {
297: return iso;
298: }
299:
300: public Collection getRegions() {
301: return regions;
302: }
303: }
304:
305: public class Region {
306: String name;
307: String key;
308:
309: public Region(String name, String key) {
310: this .name = name;
311: this .key = key;
312: }
313:
314: public String getName() {
315: return name;
316: }
317:
318: public String getKey() {
319: return key;
320: }
321: }
322: }
|