001: package com.opensymphony.webwork.views.jsp.ui;
002:
003: import com.opensymphony.webwork.TestAction;
004: import com.opensymphony.webwork.views.jsp.AbstractUITagTest;
005:
006: import java.util.ArrayList;
007: import java.util.Collection;
008: import java.util.List;
009:
010: /**
011: * Test case for DoubleSelectTag.
012: *
013: * @author <a href="mailto:m.bogaert@memenco.com">Mathias Bogaert</a>
014: * @author tm_jee
015: * @version $Date: 2006-02-03 13:45:25 +0100 (Fri, 03 Feb 2006) $ $Id: DoubleSelectTest.java 2094 2006-02-03 12:45:25Z rgielen $
016: */
017: public class DoubleSelectTest extends AbstractUITagTest {
018:
019: public void testDouble() throws Exception {
020: TestAction testAction = (TestAction) action;
021:
022: Region antwerp = new Region("Antwerp", "AN");
023: Region gent = new Region("Gent", "GN");
024: Region brugge = new Region("Brugge", "BRG");
025: ArrayList belgiumRegions = new ArrayList();
026: belgiumRegions.add(antwerp);
027: belgiumRegions.add(gent);
028: belgiumRegions.add(brugge);
029: Country belgium = new Country("Belgium", "BE", belgiumRegions);
030:
031: Region paris = new Region("Paris", "PA");
032: Region bordeaux = new Region("Bordeaux", "BOR");
033: ArrayList franceRegions = new ArrayList();
034: franceRegions.add(paris);
035: franceRegions.add(bordeaux);
036: Country france = new Country("France", "FR", franceRegions);
037:
038: Collection collection = new ArrayList(2);
039: collection.add("AN");
040: testAction.setCollection(collection);
041:
042: List countries = new ArrayList();
043: countries.add(belgium);
044: countries.add(france);
045:
046: testAction.setList2(countries);
047:
048: DoubleSelectTag tag = new DoubleSelectTag();
049: tag.setPageContext(pageContext);
050: tag.setLabel("mylabel");
051: tag.setName("foo");
052: tag.setDoubleName("region");
053:
054: tag.setList("list2");
055: tag.setDoubleList("regions");
056:
057: tag.setListKey("iso");
058: tag.setDoubleListKey("key");
059: tag.setListValue("name");
060: tag.setDoubleListValue("name");
061:
062: tag.setFormName("inputForm");
063:
064: tag.setOnmousedown("window.status='onmousedown';");
065: tag.setOnmousemove("window.status='onmousemove';");
066: tag.setOnmouseout("window.status='onmouseout';");
067: tag.setOnmouseover("window.status='onmouseover';");
068: tag.setOnmouseup("window.status='onmouseup';");
069:
070: tag.doStartTag();
071: tag.doEndTag();
072:
073: verify(SelectTag.class.getResource("DoubleSelect-1.txt"));
074: }
075:
076: public void testDoubleWithDefaultSelectedValues() throws Exception {
077:
078: TestAction testAction = (TestAction) action;
079:
080: Region antwerp = new Region("Antwerp", "AN");
081: Region gent = new Region("Gent", "GN");
082: Region brugge = new Region("Brugge", "BRG");
083: ArrayList belgiumRegions = new ArrayList();
084: belgiumRegions.add(antwerp);
085: belgiumRegions.add(gent);
086: belgiumRegions.add(brugge);
087: Country belgium = new Country("Belgium", "BE", belgiumRegions);
088:
089: Region paris = new Region("Paris", "PA");
090: Region bordeaux = new Region("Bordeaux", "BOR");
091: ArrayList franceRegions = new ArrayList();
092: franceRegions.add(paris);
093: franceRegions.add(bordeaux);
094: Country france = new Country("France", "FR", franceRegions);
095:
096: Collection collection = new ArrayList(2);
097: collection.add("AN");
098: testAction.setCollection(collection);
099:
100: List countries = new ArrayList();
101: countries.add(belgium);
102: countries.add(france);
103:
104: testAction.setList2(countries);
105:
106: DoubleSelectTag tag = new DoubleSelectTag();
107: tag.setPageContext(pageContext);
108: tag.setLabel("mylabel");
109: tag.setName("foo");
110: tag.setDoubleName("region");
111:
112: tag.setValue("'FR'");
113: tag.setDoubleValue("'BOR'");
114:
115: tag.setList("list2");
116: tag.setDoubleList("regions");
117:
118: tag.setListKey("iso");
119: tag.setDoubleListKey("key");
120: tag.setListValue("name");
121: tag.setDoubleListValue("name");
122:
123: tag.setFormName("inputForm");
124:
125: tag.setOnmousedown("window.status='onmousedown';");
126: tag.setOnmousemove("window.status='onmousemove';");
127: tag.setOnmouseout("window.status='onmouseout';");
128: tag.setOnmouseover("window.status='onmouseover';");
129: tag.setOnmouseup("window.status='onmouseup';");
130:
131: tag.doStartTag();
132: tag.doEndTag();
133:
134: verify(SelectTag.class.getResource("DoubleSelect-2.txt"));
135:
136: }
137:
138: public void testGenericSimple() throws Exception {
139: DoubleSelectTag tag = new DoubleSelectTag();
140: prepareTagGeneric(tag);
141: verifyGenericProperties(tag, "simple", new String[] { "value" });
142: }
143:
144: public void testGenericXhtml() throws Exception {
145: DoubleSelectTag tag = new DoubleSelectTag();
146: prepareTagGeneric(tag);
147: verifyGenericProperties(tag, "xhtml", new String[] { "value" });
148: }
149:
150: public void testGenericAjax() throws Exception {
151: DoubleSelectTag tag = new DoubleSelectTag();
152: prepareTagGeneric(tag);
153: verifyGenericProperties(tag, "ajax", new String[] { "value" });
154: }
155:
156: private void prepareTagGeneric(DoubleSelectTag tag) {
157: TestAction testAction = (TestAction) action;
158: Region antwerp = new Region("Antwerp", "AN");
159: Region gent = new Region("Gent", "GN");
160: Region brugge = new Region("Brugge", "BRG");
161: ArrayList belgiumRegions = new ArrayList();
162: belgiumRegions.add(antwerp);
163: belgiumRegions.add(gent);
164: belgiumRegions.add(brugge);
165: Country belgium = new Country("Belgium", "BE", belgiumRegions);
166:
167: Region paris = new Region("Paris", "PA");
168: Region bordeaux = new Region("Bordeaux", "BOR");
169: ArrayList franceRegions = new ArrayList();
170: franceRegions.add(paris);
171: franceRegions.add(bordeaux);
172: Country france = new Country("France", "FR", franceRegions);
173:
174: Collection collection = new ArrayList(2);
175: collection.add("AN");
176: testAction.setCollection(collection);
177:
178: tag.setList("collection");
179:
180: List countries = new ArrayList();
181: countries.add(belgium);
182: countries.add(france);
183:
184: testAction.setList2(countries);
185:
186: tag.setValue("'FR'");
187: tag.setDoubleValue("'BOR'");
188:
189: tag.setList("list2");
190: tag.setDoubleList("regions");
191: tag.setDoubleName("region");
192:
193: tag.setListKey("iso");
194: tag.setDoubleListKey("key");
195: tag.setListValue("name");
196: tag.setDoubleListValue("name");
197:
198: tag.setFormName("inputForm");
199: }
200:
201: public class Country {
202: String name;
203: String iso;
204: Collection regions;
205:
206: public Country(String name, String iso, Collection regions) {
207: this .name = name;
208: this .iso = iso;
209: this .regions = regions;
210: }
211:
212: public String getName() {
213: return name;
214: }
215:
216: public String getIso() {
217: return iso;
218: }
219:
220: public Collection getRegions() {
221: return regions;
222: }
223: }
224:
225: public class Region {
226: String name;
227: String key;
228:
229: public Region(String name, String key) {
230: this .name = name;
231: this .key = key;
232: }
233:
234: public String getName() {
235: return name;
236: }
237:
238: public String getKey() {
239: return key;
240: }
241: }
242: }
|