View Javadoc

1   /*
2    * $Id: UpDownSelectTagTest.java 439747 2006-09-03 09:22:46Z mrdon $
3    *
4    * Copyright 2006 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.struts2.views.jsp.ui;
19  
20  import java.util.ArrayList;
21  import java.util.LinkedHashMap;
22  import java.util.List;
23  import java.util.Map;
24  
25  import org.apache.struts2.views.jsp.AbstractUITagTest;
26  
27  import com.opensymphony.xwork2.Action;
28  import com.opensymphony.xwork2.ActionSupport;
29  
30  /***
31   * Test case for UpDownSelectTag 
32   * 
33   */
34  public class UpDownSelectTagTest extends AbstractUITagTest {
35  
36  	public void testWithAllSelected() throws Exception {
37  		
38  		UpDownSelectTag tag = new UpDownSelectTag();
39  		tag.setPageContext(pageContext);
40  		tag.setId("myId");
41  		tag.setName("myName");
42  		tag.setList("myMap");
43  		tag.setValue("myAllSelectedMapIds");
44  		tag.setEmptyOption("true");
45  		
46  		tag.doStartTag();
47  		tag.doEndTag();
48  		
49  		verify(UpDownSelectTagTest.class.getResource("updownselecttag-1.txt"));
50  	}
51  	
52  	public void testWithPartialSelected() throws Exception {
53  		
54  		UpDownSelectTag tag = new UpDownSelectTag();
55  		tag.setPageContext(pageContext);
56  		tag.setId("myId");
57  		tag.setName("myName");
58  		tag.setList("myMap");
59  		tag.setValue("mySelectedMapIds");
60  		tag.setEmptyOption("false");
61  		
62  		tag.doStartTag();
63  		tag.doEndTag();
64  		
65  		verify(UpDownSelectTagTest.class.getResource("updownselecttag-2.txt"));
66  	}
67  	
68  	public void testWithHeaderAndEmptyOption() throws Exception {
69  		
70  		UpDownSelectTag tag = new UpDownSelectTag();
71  		tag.setPageContext(pageContext);
72  		tag.setId("myId");
73  		tag.setName("myName");
74  		tag.setList("myMap");
75  		tag.setValue("mySelectedMapIds");
76  		tag.setEmptyOption("true");
77  		tag.setHeaderKey("-1");
78  		tag.setHeaderValue("--- Please Order ---");
79  		
80  		tag.doStartTag();
81  		tag.doEndTag();
82  		
83  		verify(UpDownSelectTagTest.class.getResource("updownselecttag-3.txt"));
84  	}
85  	
86  	public void testWithHeaderOnly() throws Exception {
87  		
88  		UpDownSelectTag tag = new UpDownSelectTag();
89  		tag.setPageContext(pageContext);
90  		tag.setId("myId");
91  		tag.setName("myName");
92  		tag.setList("myMap");
93  		tag.setValue("mySelectedMapIds");
94  		tag.setEmptyOption("false");
95  		tag.setHeaderKey("-1");
96  		tag.setHeaderValue("--- Please Order ---");
97  		
98  		tag.doStartTag();
99  		tag.doEndTag();
100 		
101 		verify(UpDownSelectTagTest.class.getResource("updownselecttag-4.txt"));
102 	}
103 	
104 	public void testWithEmptyOptionOnly() throws Exception {
105 		
106 		UpDownSelectTag tag = new UpDownSelectTag();
107 		tag.setPageContext(pageContext);
108 		tag.setId("myId");
109 		tag.setName("myName");
110 		tag.setList("myMap");
111 		tag.setValue("mySelectedMapIds");
112 		tag.setEmptyOption("true");
113 		
114 		tag.doStartTag();
115 		tag.doEndTag();
116 		
117 		verify(UpDownSelectTagTest.class.getResource("updownselecttag-5.txt"));
118 	}
119 	
120 	
121 	public void testDisableSomeSelectAllButton() throws Exception {
122 		
123 		UpDownSelectTag tag = new UpDownSelectTag();
124 		tag.setPageContext(pageContext);
125 		tag.setId("myId");
126 		tag.setName("myName");
127 		tag.setList("myMap");
128 		tag.setValue("mySelectedMapIds");
129 		tag.setEmptyOption("true");
130 		tag.setAllowSelectAll("false");
131 		
132 		tag.doStartTag();
133 		tag.doEndTag();
134 		
135 		verify(UpDownSelectTagTest.class.getResource("updownselecttag-6.txt"));
136 	}
137 	
138 	public void testDisableMoveUpButton() throws Exception {
139 		UpDownSelectTag tag = new UpDownSelectTag();
140 		tag.setPageContext(pageContext);
141 		tag.setId("myId");
142 		tag.setName("myName");
143 		tag.setList("myMap");
144 		tag.setValue("mySelectedMapIds");
145 		tag.setEmptyOption("true");
146 		tag.setAllowMoveUp("false");
147 		
148 		tag.doStartTag();
149 		tag.doEndTag();
150 		
151 		verify(UpDownSelectTagTest.class.getResource("updownselecttag-7.txt"));
152 	}
153 	
154 	public void testDisableMoveDownButton() throws Exception {
155 		UpDownSelectTag tag = new UpDownSelectTag();
156 		tag.setPageContext(pageContext);
157 		tag.setId("myId");
158 		tag.setName("myName");
159 		tag.setList("myMap");
160 		tag.setValue("mySelectedMapIds");
161 		tag.setEmptyOption("true");
162 		tag.setAllowMoveDown("false");
163 		
164 		tag.doStartTag();
165 		tag.doEndTag();
166 		
167 		verify(UpDownSelectTagTest.class.getResource("updownselecttag-8.txt"));
168 	}
169 	
170 	public void testChangeSelectAllButtonText() throws Exception {
171 		UpDownSelectTag tag = new UpDownSelectTag();
172 		tag.setPageContext(pageContext);
173 		tag.setId("myId");
174 		tag.setName("myName");
175 		tag.setList("myMap");
176 		tag.setValue("mySelectedMapIds");
177 		tag.setEmptyOption("true");
178 		tag.setSelectAllLabel("Select All");
179 		
180 		tag.doStartTag();
181 		tag.doEndTag();
182 		
183 		verify(UpDownSelectTagTest.class.getResource("updownselecttag-9.txt"));
184 	}
185 	
186 	public void testChangeMoveUpButtonText() throws Exception {
187 		UpDownSelectTag tag = new UpDownSelectTag();
188 		tag.setPageContext(pageContext);
189 		tag.setId("myId");
190 		tag.setName("myName");
191 		tag.setList("myMap");
192 		tag.setValue("mySelectedMapIds");
193 		tag.setEmptyOption("true");
194 		tag.setMoveUpLabel("Move Up");
195 		
196 		tag.doStartTag();
197 		tag.doEndTag();
198 		
199 		verify(UpDownSelectTagTest.class.getResource("updownselecttag-10.txt"));
200 	}
201 	
202 	public void testChangeMoveDownButtonText() throws Exception {
203 		UpDownSelectTag tag = new UpDownSelectTag();
204 		tag.setPageContext(pageContext);
205 		tag.setId("myId");
206 		tag.setName("myName");
207 		tag.setList("myMap");
208 		tag.setValue("mySelectedMapIds");
209 		tag.setEmptyOption("true");
210 		tag.setMoveDownLabel("Move Down");
211 		
212 		tag.doStartTag();
213 		tag.doEndTag();
214 		
215 		verify(UpDownSelectTagTest.class.getResource("updownselecttag-11.txt"));
216 	}
217 	
218     public void testGenericSimple() throws Exception {
219         UpDownSelectTag tag = new UpDownSelectTag();
220         prepareTagGeneric(tag);
221         verifyGenericProperties(tag, "simple", new String[]{"value"});
222     }
223 
224     public void testGenericXhtml() throws Exception {
225         UpDownSelectTag tag = new UpDownSelectTag();
226         prepareTagGeneric(tag);
227         verifyGenericProperties(tag, "xhtml", new String[]{"value"});
228     }
229 
230     public void testGenericAjax() throws Exception {
231         UpDownSelectTag tag = new UpDownSelectTag();
232         prepareTagGeneric(tag);
233         verifyGenericProperties(tag, "ajax", new String[]{"value"});
234     }
235 
236     private void prepareTagGeneric(UpDownSelectTag tag) {
237         tag.setList("myMap");
238     }
239 
240 
241 	
242 	// ===============================
243 	public Action getAction() {
244 		return new ActionSupport() {
245 			
246 			public Map getMyMap() {
247 				Map _myMap = new LinkedHashMap();
248 				_myMap.put("england", "England");
249 				_myMap.put("america", "America");
250 				_myMap.put("australia", "Australia");
251 				_myMap.put("germany", "Germany");
252 				return _myMap;
253 			}
254 			
255 			public List getMySelectedMapIds() {
256 				List _mySelectedMapIds = new ArrayList();
257 				_mySelectedMapIds.add("america");
258 				_mySelectedMapIds.add("germany");
259 				return _mySelectedMapIds;
260 			}
261 			
262 			public List getMyAllSelectedMapIds() {
263 				List _mySelectedMapIds = new ArrayList();
264 				_mySelectedMapIds.add("england");
265 				_mySelectedMapIds.add("america");
266 				_mySelectedMapIds.add("australia");
267 				_mySelectedMapIds.add("germany");
268 				return _mySelectedMapIds;
269 			}
270 		};
271 	}
272 }