View Javadoc

1   /*
2    * $Id: CheckboxTest.java 651946 2008-04-27 13:41:38Z apetrelli $
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  package org.apache.struts2.views.jsp.ui;
23  
24  import java.util.Map;
25  import java.util.HashMap;
26  import java.util.Collections;
27  
28  import org.apache.struts2.TestAction;
29  import org.apache.struts2.views.jsp.AbstractUITagTest;
30  
31  
32  /***
33   */
34  public class CheckboxTest extends AbstractUITagTest {
35  
36      public CheckboxTest() {
37      }
38  
39      /***
40       * Initialize a map of {@link org.apache.struts2.views.jsp.AbstractUITagTest.PropertyHolder} for generic tag
41       * property testing. Will be used when calling {@link #verifyGenericProperties(org.apache.struts2.views.jsp.ui.AbstractUITag,
42       * String, String[])} as properties to verify.<p/> This implementation extends testdata from AbstractUITag.
43       *
44       * @return A Map of PropertyHolders values bound to {@link org.apache.struts2.views.jsp.AbstractUITagTest.PropertyHolder#getName()}
45       *         as key.
46       */
47      protected Map initializedGenericTagTestProperties() {
48          Map result = super.initializedGenericTagTestProperties();
49          new PropertyHolder("value", "true").addToMap(result);
50          return result;
51      }
52  
53      public void testGenericSimple() throws Exception {
54          CheckboxTag tag = new CheckboxTag();
55          verifyGenericProperties(tag, "simple", null);
56      }
57  
58      public void testGenericXhtml() throws Exception {
59          CheckboxTag tag = new CheckboxTag();
60          verifyGenericProperties(tag, "xhtml", null);
61      }
62  
63      public void testChecked() throws Exception {
64          TestAction testAction = (TestAction) action;
65          testAction.setFoo("true");
66  
67          CheckboxTag tag = new CheckboxTag();
68          tag.setPageContext(pageContext);
69          tag.setId("someId");
70          tag.setLabel("mylabel");
71          tag.setName("foo");
72          tag.setFieldValue("baz");
73          tag.setOnfocus("test();");
74          tag.setTitle("mytitle");
75  
76          tag.doStartTag();
77          tag.doEndTag();
78  
79          verify(CheckboxTag.class.getResource("Checkbox-1.txt"));
80      }
81  
82      public void testCheckedWithTopLabelPosition() throws Exception {
83          TestAction testAction = (TestAction) action;
84          testAction.setFoo("true");
85  
86          CheckboxTag tag = new CheckboxTag();
87          tag.setPageContext(pageContext);
88          tag.setId("someId");
89          tag.setLabel("mylabel");
90          tag.setName("foo");
91          tag.setFieldValue("baz");
92          tag.setOnfocus("test();");
93          tag.setTitle("mytitle");
94          tag.setLabelposition("top");
95  
96          tag.doStartTag();
97          tag.doEndTag();
98  
99          verify(CheckboxTag.class.getResource("Checkbox-4.txt"));
100     }
101 
102     public void testCheckedWithLeftLabelPosition() throws Exception {
103         TestAction testAction = (TestAction) action;
104         testAction.setFoo("true");
105 
106         CheckboxTag tag = new CheckboxTag();
107         tag.setPageContext(pageContext);
108         tag.setId("someId");
109         tag.setLabel("mylabel");
110         tag.setName("foo");
111         tag.setFieldValue("baz");
112         tag.setOnfocus("test();");
113         tag.setTitle("mytitle");
114         tag.setLabelposition("left");
115 
116         tag.doStartTag();
117         tag.doEndTag();
118 
119         verify(CheckboxTag.class.getResource("Checkbox-5.txt"));
120     }
121 
122     public void testCheckedWithError() throws Exception {
123         TestAction testAction = (TestAction) action;
124         testAction.setFoo("true");
125         testAction.addFieldError("foo", "Some Foo Error");
126         testAction.addFieldError("foo", "Another Foo Error");
127 
128         CheckboxTag tag = new CheckboxTag();
129         tag.setPageContext(pageContext);
130         tag.setLabel("mylabel");
131         tag.setName("foo");
132         tag.setFieldValue("baz");
133         tag.setOndblclick("test();");
134         tag.setOnclick("test();");
135         tag.setTitle("mytitle");
136         tag.setCssErrorClass("myErrorClass");
137 
138         tag.doStartTag();
139         tag.doEndTag();
140 
141         verify(CheckboxTag.class.getResource("Checkbox-3.txt"));
142     }
143 
144     public void testCheckedWithErrorStyle() throws Exception {
145         TestAction testAction = (TestAction) action;
146         testAction.setFoo("true");
147         testAction.addFieldError("foo", "Some Foo Error");
148         testAction.addFieldError("foo", "Another Foo Error");
149 
150         CheckboxTag tag = new CheckboxTag();
151         tag.setPageContext(pageContext);
152         tag.setLabel("mylabel");
153         tag.setName("foo");
154         tag.setFieldValue("baz");
155         tag.setOndblclick("test();");
156         tag.setOnclick("test();");
157         tag.setTitle("mytitle");
158         tag.setCssErrorStyle("color:red");
159 
160         tag.doStartTag();
161         tag.doEndTag();
162 
163         verify(CheckboxTag.class.getResource("Checkbox-33.txt"));
164     }
165 
166     public void testUnchecked() throws Exception {
167         TestAction testAction = (TestAction) action;
168         testAction.setFoo("false");
169 
170         CheckboxTag tag = new CheckboxTag();
171         tag.setPageContext(pageContext);
172         tag.setLabel("mylabel");
173         tag.setName("foo");
174         tag.setFieldValue("baz");
175         tag.setTitle("mytitle");
176 
177         tag.doStartTag();
178         tag.doEndTag();
179 
180         verify(CheckboxTag.class.getResource("Checkbox-2.txt"));
181     }
182     
183     public void testDisabled() throws Exception {
184         TestAction testAction = (TestAction) action;
185         testAction.setFoo("true");
186 
187         CheckboxTag tag = new CheckboxTag();
188         tag.setPageContext(pageContext);
189         tag.setLabel("mylabel");
190         tag.setName("foo");
191         tag.setFieldValue("baz");
192         tag.setTitle("mytitle");
193         tag.setDisabled("true");
194 
195         tag.doStartTag();
196         tag.doEndTag();
197 
198         verify(CheckboxTag.class.getResource("Checkbox-6.txt"));
199     }
200 }