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