001: /*
002: * $Id: CheckboxListTest.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.Collection;
025: import java.util.Map;
026:
027: import org.apache.struts2.TestAction;
028: import org.apache.struts2.views.jsp.AbstractUITagTest;
029:
030: /**
031: * Test case for CheckboxList.
032: *
033: */
034: public class CheckboxListTest extends AbstractUITagTest {
035:
036: /**
037: * Initialize a map of {@link org.apache.struts2.views.jsp.AbstractUITagTest.PropertyHolder} for generic tag
038: * property testing. Will be used when calling {@link #verifyGenericProperties(org.apache.struts2.views.jsp.ui.AbstractUITag,
039: * String, String[])} as properties to verify.<p/> This implementation extends testdata from AbstractUITag.
040: *
041: * @return A Map of PropertyHolders values bound to {@link org.apache.struts2.views.jsp.AbstractUITagTest.PropertyHolder#getName()}
042: * as key.
043: */
044: protected Map initializedGenericTagTestProperties() {
045: Map result = super .initializedGenericTagTestProperties();
046: new PropertyHolder("value", "hello").addToMap(result);
047: return result;
048: }
049:
050: public void testGenericSimple() throws Exception {
051: CheckboxListTag tag = new CheckboxListTag();
052: prepareTagGeneric(tag);
053: verifyGenericProperties(tag, "simple", new String[] {
054: "tabindex", "cssClass", "cssStyle", "id" });
055: }
056:
057: public void testGenericXhtml() throws Exception {
058: CheckboxListTag tag = new CheckboxListTag();
059: prepareTagGeneric(tag);
060: verifyGenericProperties(tag, "xhtml", new String[] {
061: "tabindex", "cssClass", "cssStyle", "id" });
062: }
063:
064: public void testGenericAjax() throws Exception {
065: CheckboxListTag tag = new CheckboxListTag();
066: prepareTagGeneric(tag);
067: verifyGenericProperties(tag, "ajax", new String[] { "tabindex",
068: "cssClass", "cssStyle", "id" });
069: }
070:
071: private void prepareTagGeneric(CheckboxListTag tag) {
072: TestAction testAction = (TestAction) action;
073: Collection collection = new ArrayList(2);
074: collection.add("hello");
075: collection.add("foo");
076: testAction.setCollection(collection);
077: testAction.setList(new String[][] { { "hello", "world" },
078: { "foo", "bar" }, });
079: tag.setName("collection");
080: tag.setList("list");
081: tag.setListKey("top[0]");
082: tag.setListValue("top[1]");
083: }
084:
085: public void testMultiple() throws Exception {
086: TestAction testAction = (TestAction) action;
087: Collection collection = new ArrayList(2);
088: collection.add("hello");
089: collection.add("foo");
090: testAction.setCollection(collection);
091: testAction.setList(new String[][] { { "hello", "world" },
092: { "foo", "bar" }, { "cat", "dog" } });
093:
094: CheckboxListTag tag = new CheckboxListTag();
095: tag.setPageContext(pageContext);
096: tag.setLabel("mylabel");
097: tag.setName("collection");
098: tag.setList("list");
099: tag.setListKey("top[0]");
100: tag.setListValue("top[1]");
101:
102: tag.doStartTag();
103: tag.doEndTag();
104:
105: verify(CheckboxListTag.class.getResource("CheckboxList-2.txt"));
106: }
107:
108: public void testMultipleWithDisabledOn() throws Exception {
109: TestAction testAction = (TestAction) action;
110: Collection collection = new ArrayList(2);
111: collection.add("hello");
112: collection.add("foo");
113: testAction.setCollection(collection);
114: testAction.setList(new String[][] { { "hello", "world" },
115: { "foo", "bar" }, { "cat", "dog" } });
116:
117: CheckboxListTag tag = new CheckboxListTag();
118: tag.setPageContext(pageContext);
119: tag.setLabel("mylabel");
120: tag.setName("collection");
121: tag.setList("list");
122: tag.setListKey("top[0]");
123: tag.setListValue("top[1]");
124: tag.setDisabled("true");
125:
126: tag.doStartTag();
127: tag.doEndTag();
128:
129: verify(CheckboxListTag.class.getResource("CheckboxList-3.txt"));
130: }
131:
132: public void testSimple() throws Exception {
133: TestAction testAction = (TestAction) action;
134: testAction.setFoo("hello");
135: testAction.setList(new String[][] { { "hello", "world" },
136: { "foo", "bar" } });
137:
138: CheckboxListTag tag = new CheckboxListTag();
139: tag.setPageContext(pageContext);
140: tag.setLabel("mylabel");
141: tag.setName("foo");
142: tag.setList("list");
143: tag.setListKey("top[0]");
144: tag.setListValue("top[1]");
145: tag.setOnchange("alert('foo');");
146: tag.setTitle("mytitle");
147:
148: tag.doStartTag();
149: tag.doEndTag();
150:
151: verify(CheckboxListTag.class.getResource("CheckboxList-1.txt"));
152: }
153:
154: public void testSimpleWithDisableOn() throws Exception {
155: TestAction testAction = (TestAction) action;
156: testAction.setFoo("hello");
157: testAction.setList(new String[][] { { "hello", "world" },
158: { "foo", "bar" } });
159:
160: CheckboxListTag tag = new CheckboxListTag();
161: tag.setPageContext(pageContext);
162: tag.setLabel("mylabel");
163: tag.setName("foo");
164: tag.setList("list");
165: tag.setListKey("top[0]");
166: tag.setListValue("top[1]");
167: tag.setOnchange("alert('foo');");
168: tag.setDisabled("true");
169:
170: tag.doStartTag();
171: tag.doEndTag();
172:
173: verify(CheckboxListTag.class.getResource("CheckboxList-4.txt"));
174: }
175: }
|