View Javadoc

1   /*
2    * $Id: RadioTest.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.HashMap;
21  import java.util.LinkedHashMap;
22  
23  import org.apache.struts2.TestAction;
24  import org.apache.struts2.views.jsp.AbstractUITagTest;
25  
26  
27  /***
28   */
29  public class RadioTest extends AbstractUITagTest {
30  	
31  	public void testMapWithBooleanAsKey() throws Exception {
32  		TestAction testAction = (TestAction) action;
33  		
34  		HashMap map = new LinkedHashMap();
35  		map.put(Boolean.TRUE, "male");
36  		map.put(Boolean.FALSE, "female");
37  		testAction.setMap(map);
38  		
39  		RadioTag tag = new RadioTag();
40  		tag.setPageContext(pageContext);
41  		tag.setLabel("mylabel");
42  		tag.setName("myname");
43  		tag.setValue("%{'true'}");
44  		tag.setList("map");
45  		
46  		tag.doStartTag();
47  		tag.doEndTag();
48  		
49  		verify(RadioTag.class.getResource("Radio-3.txt"));
50  	}
51  	
52  
53      public void testMapChecked() throws Exception {
54          TestAction testAction = (TestAction) action;
55          testAction.setFoo("bar");
56  
57          HashMap map = new HashMap();
58          map.put("1", "One");
59          map.put("2", "Two");
60          testAction.setMap(map);
61  
62          RadioTag tag = new RadioTag();
63          tag.setPageContext(pageContext);
64          tag.setLabel("mylabel");
65          tag.setName("myname");
66          tag.setValue("\"1\"");
67          tag.setList("map");
68          tag.setListKey("key");
69          tag.setListValue("value");
70  
71          tag.doStartTag();
72          tag.doEndTag();
73  
74          verify(RadioTag.class.getResource("Radio-2.txt"));
75      }
76  
77      public void testSimple() throws Exception {
78          TestAction testAction = (TestAction) action;
79          testAction.setFoo("bar");
80          testAction.setList(new String[][]{
81                  {"hello", "world"},
82                  {"foo", "bar"}
83          });
84  
85          RadioTag tag = new RadioTag();
86          tag.setPageContext(pageContext);
87          tag.setLabel("mylabel");
88          tag.setName("myname");
89          tag.setValue("");
90          tag.setList("list");
91          tag.setListKey("top[0]");
92          tag.setListValue("top[1]");
93  
94          tag.doStartTag();
95          tag.doEndTag();
96  
97          verify(RadioTag.class.getResource("Radio-1.txt"));
98      }
99  
100     public void testGenericSimple() throws Exception {
101         RadioTag tag = new RadioTag();
102         prepareTagGeneric(tag);
103         verifyGenericProperties(tag, "simple", new String[]{"id","value"});
104     }
105 
106     public void testGenericXhtml() throws Exception {
107         RadioTag tag = new RadioTag();
108         prepareTagGeneric(tag);
109         verifyGenericProperties(tag, "xhtml", new String[]{"id","value"});
110     }
111 
112     public void testGenericAjax() throws Exception {
113         RadioTag tag = new RadioTag();
114         prepareTagGeneric(tag);
115         verifyGenericProperties(tag, "ajax", new String[]{"id","value"});
116     }
117 
118     private void prepareTagGeneric(RadioTag tag) {
119         TestAction testAction = (TestAction) action;
120         testAction.setFoo("bar");
121         testAction.setList(new String[][]{
122                 {"hello", "world"},
123                 {"foo", "bar"}
124         });
125         tag.setList("list");
126         tag.setListKey("top[0]");
127         tag.setListValue("top[1]");
128     }
129 
130 }