1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 package org.apache.struts2.views.jsp.ui;
23
24 import java.util.ArrayList;
25 import java.util.Collection;
26 import java.util.Map;
27
28 import org.apache.struts2.TestAction;
29 import org.apache.struts2.views.jsp.AbstractUITagTest;
30
31
32 /***
33 * Test case for CheckboxList.
34 *
35 */
36 public class CheckboxListTest extends AbstractUITagTest {
37
38 /***
39 * Initialize a map of {@link org.apache.struts2.views.jsp.AbstractUITagTest.PropertyHolder} for generic tag
40 * property testing. Will be used when calling {@link #verifyGenericProperties(org.apache.struts2.views.jsp.ui.AbstractUITag,
41 * String, String[])} as properties to verify.<p/> This implementation extends testdata from AbstractUITag.
42 *
43 * @return A Map of PropertyHolders values bound to {@link org.apache.struts2.views.jsp.AbstractUITagTest.PropertyHolder#getName()}
44 * as key.
45 */
46 protected Map initializedGenericTagTestProperties() {
47 Map result = super.initializedGenericTagTestProperties();
48 new PropertyHolder("value", "hello").addToMap(result);
49 return result;
50 }
51
52 public void testGenericSimple() throws Exception {
53 CheckboxListTag tag = new CheckboxListTag();
54 prepareTagGeneric(tag);
55 verifyGenericProperties(tag, "simple", new String[]{"tabindex","cssClass","cssStyle","id"});
56 }
57
58 public void testGenericXhtml() throws Exception {
59 CheckboxListTag tag = new CheckboxListTag();
60 prepareTagGeneric(tag);
61 verifyGenericProperties(tag, "xhtml", new String[]{"tabindex","cssClass","cssStyle","id"});
62 }
63
64 private void prepareTagGeneric(CheckboxListTag tag) {
65 TestAction testAction = (TestAction) action;
66 Collection collection = new ArrayList(2);
67 collection.add("hello");
68 collection.add("foo");
69 testAction.setCollection(collection);
70 testAction.setList(new String[][]{
71 {"hello", "world"},
72 {"foo", "bar"},
73 });
74 tag.setName("collection");
75 tag.setList("list");
76 tag.setListKey("top[0]");
77 tag.setListValue("top[1]");
78 }
79
80 public void testMultiple() throws Exception {
81 TestAction testAction = (TestAction) action;
82 Collection collection = new ArrayList(2);
83 collection.add("hello");
84 collection.add("foo");
85 testAction.setCollection(collection);
86 testAction.setList(new String[][]{
87 {"hello", "world"},
88 {"foo", "bar"},
89 {"cat", "dog"}
90 });
91
92 CheckboxListTag tag = new CheckboxListTag();
93 tag.setPageContext(pageContext);
94 tag.setLabel("mylabel");
95 tag.setName("collection");
96 tag.setList("list");
97 tag.setListKey("top[0]");
98 tag.setListValue("top[1]");
99
100 tag.doStartTag();
101 tag.doEndTag();
102
103 verify(CheckboxListTag.class.getResource("CheckboxList-2.txt"));
104 }
105
106 public void testMultipleWithDisabledOn() throws Exception {
107 TestAction testAction = (TestAction) action;
108 Collection collection = new ArrayList(2);
109 collection.add("hello");
110 collection.add("foo");
111 testAction.setCollection(collection);
112 testAction.setList(new String[][]{
113 {"hello", "world"},
114 {"foo", "bar"},
115 {"cat", "dog"}
116 });
117
118 CheckboxListTag tag = new CheckboxListTag();
119 tag.setPageContext(pageContext);
120 tag.setLabel("mylabel");
121 tag.setName("collection");
122 tag.setList("list");
123 tag.setListKey("top[0]");
124 tag.setListValue("top[1]");
125 tag.setDisabled("true");
126
127 tag.doStartTag();
128 tag.doEndTag();
129
130 verify(CheckboxListTag.class.getResource("CheckboxList-3.txt"));
131 }
132
133 public void testSimple() throws Exception {
134 TestAction testAction = (TestAction) action;
135 testAction.setFoo("hello");
136 testAction.setList(new String[][]{
137 {"hello", "world"},
138 {"foo", "bar"},
139 {"baz", null}
140 });
141
142 CheckboxListTag tag = new CheckboxListTag();
143 tag.setPageContext(pageContext);
144 tag.setLabel("mylabel");
145 tag.setName("foo");
146 tag.setList("list");
147 tag.setListKey("top[0]");
148 tag.setListValue("top[1]");
149 tag.setOnchange("alert('foo');");
150 tag.setTitle("mytitle");
151
152 tag.doStartTag();
153 tag.doEndTag();
154
155 verify(CheckboxListTag.class.getResource("CheckboxList-1.txt"));
156 }
157
158 public void testSimpleWithDisableOn() throws Exception {
159 TestAction testAction = (TestAction) action;
160 testAction.setFoo("hello");
161 testAction.setList(new String[][]{
162 {"hello", "world"},
163 {"foo", "bar"}
164 });
165
166 CheckboxListTag tag = new CheckboxListTag();
167 tag.setPageContext(pageContext);
168 tag.setLabel("mylabel");
169 tag.setName("foo");
170 tag.setList("list");
171 tag.setListKey("top[0]");
172 tag.setListValue("top[1]");
173 tag.setOnchange("alert('foo');");
174 tag.setDisabled("true");
175
176 tag.doStartTag();
177 tag.doEndTag();
178
179 verify(CheckboxListTag.class.getResource("CheckboxList-4.txt"));
180 }
181 }