001: /*
002: * $Id: ComboBoxTest.java 560260 2007-07-27 14:57:26Z rgielen $
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.TestAction;
029: import org.apache.struts2.views.jsp.AbstractUITagTest;
030:
031: /**
032: * Test case for ComboBox component.
033: */
034: public class ComboBoxTest extends AbstractUITagTest {
035:
036: public void testGenericSimple() throws Exception {
037: ComboBoxTag tag = new ComboBoxTag();
038: prepareTagGeneric(tag);
039: verifyGenericProperties(tag, "simple", null);
040: }
041:
042: public void testGenericXhtml() throws Exception {
043: ComboBoxTag tag = new ComboBoxTag();
044: prepareTagGeneric(tag);
045: verifyGenericProperties(tag, "xhtml", null);
046: }
047:
048: public void testGenericAjax() throws Exception {
049: ComboBoxTag tag = new ComboBoxTag();
050: prepareTagGeneric(tag);
051: verifyGenericProperties(tag, "ajax", null);
052: }
053:
054: private void prepareTagGeneric(ComboBoxTag tag) {
055: TestAction testAction = (TestAction) action;
056: ArrayList collection = new ArrayList();
057: collection.add("foo");
058: collection.add("bar");
059: collection.add("baz");
060:
061: testAction.setCollection(collection);
062:
063: tag.setList("collection");
064: }
065:
066: public void testSimple() throws Exception {
067: TestAction testAction = (TestAction) action;
068: testAction.setFoo("hello");
069:
070: ArrayList collection = new ArrayList();
071: collection.add("foo");
072: collection.add("bar");
073: collection.add("baz");
074: testAction.setCollection(collection);
075:
076: ComboBoxTag tag = new ComboBoxTag();
077: tag.setPageContext(pageContext);
078: tag.setLabel("mylabel");
079: tag.setName("foo");
080: tag.setId("cb");
081: tag.setList("collection");
082:
083: tag.doStartTag();
084: tag.doEndTag();
085:
086: verify(ComboBoxTag.class.getResource("ComboBox-1.txt"));
087: }
088:
089: public void testWithEmptyOptionAndHeader() throws Exception {
090: TestAction testAction = (TestAction) action;
091: testAction.setFoo("banana");
092:
093: List l = new ArrayList();
094: l.add("apple");
095: l.add("banana");
096: l.add("pineaple");
097: l.add("grapes");
098: testAction.setCollection(l);
099:
100: ComboBoxTag tag = new ComboBoxTag();
101: tag.setPageContext(pageContext);
102: tag.setLabel("My Favourite Fruit");
103: tag.setName("myFavouriteFruit");
104: tag.setEmptyOption("true");
105: tag.setHeaderKey("-1");
106: tag.setHeaderValue("--- Please Select ---");
107: tag.setList("collection");
108: tag.setValue("%{foo}");
109:
110: tag.doStartTag();
111: tag.doEndTag();
112:
113: verify(ComboBoxTag.class.getResource("ComboBox-2.txt"));
114: }
115:
116: public void testWithMap() throws Exception {
117: TestAction testAction = (TestAction) action;
118: testAction.setFoo("banana");
119:
120: Map m = new LinkedHashMap();
121: m.put("apple", "apple");
122: m.put("banana", "banana");
123: m.put("pineaple", "pineaple");
124: m.put("grapes", "grapes");
125: testAction.setMap(m);
126:
127: ComboBoxTag tag = new ComboBoxTag();
128: tag.setPageContext(pageContext);
129: tag.setLabel("My Favourite Fruit");
130: tag.setName("myFavouriteFruit");
131: tag.setHeaderKey("-1");
132: tag.setHeaderValue("--- Please Select ---");
133: tag.setEmptyOption("true");
134: tag.setList("map");
135: tag.setValue("%{foo}");
136:
137: tag.doStartTag();
138: tag.doEndTag();
139:
140: verify(ComboBoxTag.class.getResource("ComboBox-3.txt"));
141: }
142:
143: public void testJsCallNamingUsesEscapedId() throws Exception {
144: TestAction testAction = (TestAction) action;
145: testAction.setFoo("hello");
146:
147: ArrayList collection = new ArrayList();
148: collection.add("foo");
149: testAction.setCollection(collection);
150:
151: ComboBoxTag tag = new ComboBoxTag();
152: tag.setPageContext(pageContext);
153: tag.setLabel("mylabel");
154: tag.setName("foo");
155: tag.setId("cb.bc");
156: tag.setList("collection");
157:
158: tag.doStartTag();
159: tag.doEndTag();
160:
161: verify(ComboBoxTag.class.getResource("ComboBox-4.txt"));
162: }
163:
164: }
|