001: /*
002: * $Id: UpDownSelectTagTest.java 471756 2006-11-06 15:01:43Z husted $
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.LinkedHashMap;
025: import java.util.List;
026: import java.util.Map;
027:
028: import org.apache.struts2.views.jsp.AbstractUITagTest;
029:
030: import com.opensymphony.xwork2.Action;
031: import com.opensymphony.xwork2.ActionSupport;
032:
033: /**
034: * Test case for UpDownSelectTag
035: *
036: */
037: public class UpDownSelectTagTest extends AbstractUITagTest {
038:
039: public void testWithAllSelected() throws Exception {
040:
041: UpDownSelectTag tag = new UpDownSelectTag();
042: tag.setPageContext(pageContext);
043: tag.setId("myId");
044: tag.setName("myName");
045: tag.setList("myMap");
046: tag.setValue("myAllSelectedMapIds");
047: tag.setEmptyOption("true");
048:
049: tag.doStartTag();
050: tag.doEndTag();
051:
052: verify(UpDownSelectTagTest.class
053: .getResource("updownselecttag-1.txt"));
054: }
055:
056: public void testWithPartialSelected() throws Exception {
057:
058: UpDownSelectTag tag = new UpDownSelectTag();
059: tag.setPageContext(pageContext);
060: tag.setId("myId");
061: tag.setName("myName");
062: tag.setList("myMap");
063: tag.setValue("mySelectedMapIds");
064: tag.setEmptyOption("false");
065:
066: tag.doStartTag();
067: tag.doEndTag();
068:
069: verify(UpDownSelectTagTest.class
070: .getResource("updownselecttag-2.txt"));
071: }
072:
073: public void testWithHeaderAndEmptyOption() throws Exception {
074:
075: UpDownSelectTag tag = new UpDownSelectTag();
076: tag.setPageContext(pageContext);
077: tag.setId("myId");
078: tag.setName("myName");
079: tag.setList("myMap");
080: tag.setValue("mySelectedMapIds");
081: tag.setEmptyOption("true");
082: tag.setHeaderKey("-1");
083: tag.setHeaderValue("--- Please Order ---");
084:
085: tag.doStartTag();
086: tag.doEndTag();
087:
088: verify(UpDownSelectTagTest.class
089: .getResource("updownselecttag-3.txt"));
090: }
091:
092: public void testWithHeaderOnly() throws Exception {
093:
094: UpDownSelectTag tag = new UpDownSelectTag();
095: tag.setPageContext(pageContext);
096: tag.setId("myId");
097: tag.setName("myName");
098: tag.setList("myMap");
099: tag.setValue("mySelectedMapIds");
100: tag.setEmptyOption("false");
101: tag.setHeaderKey("-1");
102: tag.setHeaderValue("--- Please Order ---");
103:
104: tag.doStartTag();
105: tag.doEndTag();
106:
107: verify(UpDownSelectTagTest.class
108: .getResource("updownselecttag-4.txt"));
109: }
110:
111: public void testWithEmptyOptionOnly() throws Exception {
112:
113: UpDownSelectTag tag = new UpDownSelectTag();
114: tag.setPageContext(pageContext);
115: tag.setId("myId");
116: tag.setName("myName");
117: tag.setList("myMap");
118: tag.setValue("mySelectedMapIds");
119: tag.setEmptyOption("true");
120:
121: tag.doStartTag();
122: tag.doEndTag();
123:
124: verify(UpDownSelectTagTest.class
125: .getResource("updownselecttag-5.txt"));
126: }
127:
128: public void testDisableSomeSelectAllButton() throws Exception {
129:
130: UpDownSelectTag tag = new UpDownSelectTag();
131: tag.setPageContext(pageContext);
132: tag.setId("myId");
133: tag.setName("myName");
134: tag.setList("myMap");
135: tag.setValue("mySelectedMapIds");
136: tag.setEmptyOption("true");
137: tag.setAllowSelectAll("false");
138:
139: tag.doStartTag();
140: tag.doEndTag();
141:
142: verify(UpDownSelectTagTest.class
143: .getResource("updownselecttag-6.txt"));
144: }
145:
146: public void testDisableMoveUpButton() throws Exception {
147: UpDownSelectTag tag = new UpDownSelectTag();
148: tag.setPageContext(pageContext);
149: tag.setId("myId");
150: tag.setName("myName");
151: tag.setList("myMap");
152: tag.setValue("mySelectedMapIds");
153: tag.setEmptyOption("true");
154: tag.setAllowMoveUp("false");
155:
156: tag.doStartTag();
157: tag.doEndTag();
158:
159: verify(UpDownSelectTagTest.class
160: .getResource("updownselecttag-7.txt"));
161: }
162:
163: public void testDisableMoveDownButton() throws Exception {
164: UpDownSelectTag tag = new UpDownSelectTag();
165: tag.setPageContext(pageContext);
166: tag.setId("myId");
167: tag.setName("myName");
168: tag.setList("myMap");
169: tag.setValue("mySelectedMapIds");
170: tag.setEmptyOption("true");
171: tag.setAllowMoveDown("false");
172:
173: tag.doStartTag();
174: tag.doEndTag();
175:
176: verify(UpDownSelectTagTest.class
177: .getResource("updownselecttag-8.txt"));
178: }
179:
180: public void testChangeSelectAllButtonText() throws Exception {
181: UpDownSelectTag tag = new UpDownSelectTag();
182: tag.setPageContext(pageContext);
183: tag.setId("myId");
184: tag.setName("myName");
185: tag.setList("myMap");
186: tag.setValue("mySelectedMapIds");
187: tag.setEmptyOption("true");
188: tag.setSelectAllLabel("Select All");
189:
190: tag.doStartTag();
191: tag.doEndTag();
192:
193: verify(UpDownSelectTagTest.class
194: .getResource("updownselecttag-9.txt"));
195: }
196:
197: public void testChangeMoveUpButtonText() throws Exception {
198: UpDownSelectTag tag = new UpDownSelectTag();
199: tag.setPageContext(pageContext);
200: tag.setId("myId");
201: tag.setName("myName");
202: tag.setList("myMap");
203: tag.setValue("mySelectedMapIds");
204: tag.setEmptyOption("true");
205: tag.setMoveUpLabel("Move Up");
206:
207: tag.doStartTag();
208: tag.doEndTag();
209:
210: verify(UpDownSelectTagTest.class
211: .getResource("updownselecttag-10.txt"));
212: }
213:
214: public void testChangeMoveDownButtonText() throws Exception {
215: UpDownSelectTag tag = new UpDownSelectTag();
216: tag.setPageContext(pageContext);
217: tag.setId("myId");
218: tag.setName("myName");
219: tag.setList("myMap");
220: tag.setValue("mySelectedMapIds");
221: tag.setEmptyOption("true");
222: tag.setMoveDownLabel("Move Down");
223:
224: tag.doStartTag();
225: tag.doEndTag();
226:
227: verify(UpDownSelectTagTest.class
228: .getResource("updownselecttag-11.txt"));
229: }
230:
231: public void testGenericSimple() throws Exception {
232: UpDownSelectTag tag = new UpDownSelectTag();
233: prepareTagGeneric(tag);
234: verifyGenericProperties(tag, "simple", new String[] { "value" });
235: }
236:
237: public void testGenericXhtml() throws Exception {
238: UpDownSelectTag tag = new UpDownSelectTag();
239: prepareTagGeneric(tag);
240: verifyGenericProperties(tag, "xhtml", new String[] { "value" });
241: }
242:
243: public void testGenericAjax() throws Exception {
244: UpDownSelectTag tag = new UpDownSelectTag();
245: prepareTagGeneric(tag);
246: verifyGenericProperties(tag, "ajax", new String[] { "value" });
247: }
248:
249: private void prepareTagGeneric(UpDownSelectTag tag) {
250: tag.setList("myMap");
251: }
252:
253: // ===============================
254: public Action getAction() {
255: return new ActionSupport() {
256:
257: public Map getMyMap() {
258: Map _myMap = new LinkedHashMap();
259: _myMap.put("england", "England");
260: _myMap.put("america", "America");
261: _myMap.put("australia", "Australia");
262: _myMap.put("germany", "Germany");
263: return _myMap;
264: }
265:
266: public List getMySelectedMapIds() {
267: List _mySelectedMapIds = new ArrayList();
268: _mySelectedMapIds.add("america");
269: _mySelectedMapIds.add("germany");
270: return _mySelectedMapIds;
271: }
272:
273: public List getMyAllSelectedMapIds() {
274: List _mySelectedMapIds = new ArrayList();
275: _mySelectedMapIds.add("england");
276: _mySelectedMapIds.add("america");
277: _mySelectedMapIds.add("australia");
278: _mySelectedMapIds.add("germany");
279: return _mySelectedMapIds;
280: }
281: };
282: }
283: }
|