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.LinkedHashMap;
26 import java.util.List;
27 import java.util.Map;
28
29 import org.apache.struts2.TestAction;
30 import org.apache.struts2.views.jsp.AbstractUITagTest;
31
32
33 /***
34 * Test case for ComboBox component.
35 */
36 public class ComboBoxTest extends AbstractUITagTest {
37
38 public void testGenericSimple() throws Exception {
39 ComboBoxTag tag = new ComboBoxTag();
40 prepareTagGeneric(tag);
41 verifyGenericProperties(tag, "simple", null);
42 }
43
44 public void testGenericXhtml() throws Exception {
45 ComboBoxTag tag = new ComboBoxTag();
46 prepareTagGeneric(tag);
47 verifyGenericProperties(tag, "xhtml", null);
48 }
49
50 private void prepareTagGeneric(ComboBoxTag tag) {
51 TestAction testAction = (TestAction) action;
52 ArrayList collection = new ArrayList();
53 collection.add("foo");
54 collection.add("bar");
55 collection.add("baz");
56
57 testAction.setCollection(collection);
58
59 tag.setList("collection");
60 }
61
62 public void testSimple() throws Exception {
63 TestAction testAction = (TestAction) action;
64 testAction.setFoo("hello");
65
66 ArrayList collection = new ArrayList();
67 collection.add("foo");
68 collection.add("bar");
69 collection.add("baz");
70 testAction.setCollection(collection);
71
72 ComboBoxTag tag = new ComboBoxTag();
73 tag.setPageContext(pageContext);
74 tag.setLabel("mylabel");
75 tag.setName("foo");
76 tag.setId("cb");
77 tag.setList("collection");
78
79 tag.doStartTag();
80 tag.doEndTag();
81
82 verify(ComboBoxTag.class.getResource("ComboBox-1.txt"));
83 }
84
85 public void testWithEmptyOptionAndHeader() throws Exception {
86 TestAction testAction = (TestAction) action;
87 testAction.setFoo("banana");
88
89 List l = new ArrayList();
90 l.add("apple");
91 l.add("banana");
92 l.add("pineaple");
93 l.add("grapes");
94 testAction.setCollection(l);
95
96 ComboBoxTag tag = new ComboBoxTag();
97 tag.setPageContext(pageContext);
98 tag.setLabel("My Favourite Fruit");
99 tag.setName("myFavouriteFruit");
100 tag.setEmptyOption("true");
101 tag.setHeaderKey("-1");
102 tag.setHeaderValue("--- Please Select ---");
103 tag.setList("collection");
104 tag.setValue("%{foo}");
105
106 tag.doStartTag();
107 tag.doEndTag();
108
109 verify(ComboBoxTag.class.getResource("ComboBox-2.txt"));
110 }
111
112 public void testWithMap() throws Exception {
113 TestAction testAction = (TestAction) action;
114 testAction.setFoo("banana");
115
116 Map m = new LinkedHashMap();
117 m.put("apple", "apple");
118 m.put("banana", "banana");
119 m.put("pineaple", "pineaple");
120 m.put("grapes", "grapes");
121 testAction.setMap(m);
122
123 ComboBoxTag tag = new ComboBoxTag();
124 tag.setPageContext(pageContext);
125 tag.setLabel("My Favourite Fruit");
126 tag.setName("myFavouriteFruit");
127 tag.setHeaderKey("-1");
128 tag.setHeaderValue("--- Please Select ---");
129 tag.setEmptyOption("true");
130 tag.setList("map");
131 tag.setValue("%{foo}");
132
133 tag.doStartTag();
134 tag.doEndTag();
135
136 verify(ComboBoxTag.class.getResource("ComboBox-3.txt"));
137 }
138
139 public void testJsCallNamingUsesEscapedId() throws Exception {
140 TestAction testAction = (TestAction) action;
141 testAction.setFoo("hello");
142
143 ArrayList collection = new ArrayList();
144 collection.add("foo");
145 testAction.setCollection(collection);
146
147 ComboBoxTag tag = new ComboBoxTag();
148 tag.setPageContext(pageContext);
149 tag.setLabel("mylabel");
150 tag.setName("foo");
151 tag.setId("cb.bc");
152 tag.setList("collection");
153
154 tag.doStartTag();
155 tag.doEndTag();
156
157 verify(ComboBoxTag.class.getResource("ComboBox-4.txt"));
158 }
159
160 }