001: /*
002: * Copyright (c) 2002-2003 by OpenSymphony
003: * All rights reserved.
004: */
005: package com.opensymphony.webwork.views.jsp.ui;
006:
007: import com.opensymphony.webwork.TestAction;
008: import com.opensymphony.webwork.views.jsp.AbstractUITagTest;
009:
010: import java.util.ArrayList;
011: import java.util.Collection;
012: import java.util.Map;
013:
014: /**
015: * Test case for CheckboxList.
016: *
017: * @author $author$
018: * @version $Date: 2006-02-03 13:59:14 +0100 (Fri, 03 Feb 2006) $ $Id: CheckboxListTest.java 2097 2006-02-03 12:59:14Z rgielen $
019: */
020: public class CheckboxListTest extends AbstractUITagTest {
021:
022: /**
023: * Initialize a map of {@link com.opensymphony.webwork.views.jsp.AbstractUITagTest.PropertyHolder} for generic tag
024: * property testing. Will be used when calling {@link #verifyGenericProperties(com.opensymphony.webwork.views.jsp.ui.AbstractUITag,
025: * String, String[])} as properties to verify.<p/> This implementation extends testdata from AbstractUITag.
026: *
027: * @return A Map of PropertyHolders values bound to {@link com.opensymphony.webwork.views.jsp.AbstractUITagTest.PropertyHolder#getName()}
028: * as key.
029: */
030: protected Map initializedGenericTagTestProperties() {
031: Map result = super .initializedGenericTagTestProperties();
032: new PropertyHolder("value", "hello").addToMap(result);
033: return result;
034: }
035:
036: public void testGenericSimple() throws Exception {
037: CheckboxListTag tag = new CheckboxListTag();
038: prepareTagGeneric(tag);
039: verifyGenericProperties(tag, "simple", new String[] {
040: "tabindex", "cssClass", "cssStyle", "id" });
041: }
042:
043: public void testGenericXhtml() throws Exception {
044: CheckboxListTag tag = new CheckboxListTag();
045: prepareTagGeneric(tag);
046: verifyGenericProperties(tag, "xhtml", new String[] {
047: "tabindex", "cssClass", "cssStyle", "id" });
048: }
049:
050: public void testGenericAjax() throws Exception {
051: CheckboxListTag tag = new CheckboxListTag();
052: prepareTagGeneric(tag);
053: verifyGenericProperties(tag, "ajax", new String[] { "tabindex",
054: "cssClass", "cssStyle", "id" });
055: }
056:
057: private void prepareTagGeneric(CheckboxListTag tag) {
058: TestAction testAction = (TestAction) action;
059: Collection collection = new ArrayList(2);
060: collection.add("hello");
061: collection.add("foo");
062: testAction.setCollection(collection);
063: testAction.setList(new String[][] { { "hello", "world" },
064: { "foo", "bar" }, });
065: tag.setName("collection");
066: tag.setList("list");
067: tag.setListKey("top[0]");
068: tag.setListValue("top[1]");
069: }
070:
071: public void testMultiple() throws Exception {
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" }, { "cat", "dog" } });
079:
080: CheckboxListTag tag = new CheckboxListTag();
081: tag.setPageContext(pageContext);
082: tag.setLabel("mylabel");
083: tag.setName("collection");
084: tag.setList("list");
085: tag.setListKey("top[0]");
086: tag.setListValue("top[1]");
087:
088: tag.doStartTag();
089: tag.doEndTag();
090:
091: verify(CheckboxListTag.class.getResource("CheckboxList-2.txt"));
092: }
093:
094: public void testMultipleWithDisabledOn() throws Exception {
095: TestAction testAction = (TestAction) action;
096: Collection collection = new ArrayList(2);
097: collection.add("hello");
098: collection.add("foo");
099: testAction.setCollection(collection);
100: testAction.setList(new String[][] { { "hello", "world" },
101: { "foo", "bar" }, { "cat", "dog" } });
102:
103: CheckboxListTag tag = new CheckboxListTag();
104: tag.setPageContext(pageContext);
105: tag.setLabel("mylabel");
106: tag.setName("collection");
107: tag.setList("list");
108: tag.setListKey("top[0]");
109: tag.setListValue("top[1]");
110: tag.setDisabled("true");
111:
112: tag.doStartTag();
113: tag.doEndTag();
114:
115: verify(CheckboxListTag.class.getResource("CheckboxList-3.txt"));
116: }
117:
118: public void testSimple() throws Exception {
119: TestAction testAction = (TestAction) action;
120: testAction.setFoo("hello");
121: testAction.setList(new String[][] { { "hello", "world" },
122: { "foo", "bar" } });
123:
124: CheckboxListTag tag = new CheckboxListTag();
125: tag.setPageContext(pageContext);
126: tag.setLabel("mylabel");
127: tag.setName("foo");
128: tag.setList("list");
129: tag.setListKey("top[0]");
130: tag.setListValue("top[1]");
131: tag.setOnchange("alert('foo');");
132: tag.setTitle("mytitle");
133:
134: tag.doStartTag();
135: tag.doEndTag();
136:
137: verify(CheckboxListTag.class.getResource("CheckboxList-1.txt"));
138: }
139:
140: public void testSimpleWithDisableOn() throws Exception {
141: TestAction testAction = (TestAction) action;
142: testAction.setFoo("hello");
143: testAction.setList(new String[][] { { "hello", "world" },
144: { "foo", "bar" } });
145:
146: CheckboxListTag tag = new CheckboxListTag();
147: tag.setPageContext(pageContext);
148: tag.setLabel("mylabel");
149: tag.setName("foo");
150: tag.setList("list");
151: tag.setListKey("top[0]");
152: tag.setListValue("top[1]");
153: tag.setOnchange("alert('foo');");
154: tag.setDisabled("true");
155:
156: tag.doStartTag();
157: tag.doEndTag();
158:
159: verify(CheckboxListTag.class.getResource("CheckboxList-4.txt"));
160: }
161: }
|