View Javadoc

1   /*
2    * $Id: CheckboxTest.java 446875 2006-09-16 13:49:55Z tmjee $
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.Map;
21  
22  import org.apache.struts2.TestAction;
23  import org.apache.struts2.views.jsp.AbstractUITagTest;
24  
25  
26  /***
27   */
28  public class CheckboxTest extends AbstractUITagTest {
29  
30      public CheckboxTest() {
31      }
32  
33      /***
34       * Initialize a map of {@link org.apache.struts2.views.jsp.AbstractUITagTest.PropertyHolder} for generic tag
35       * property testing. Will be used when calling {@link #verifyGenericProperties(org.apache.struts2.views.jsp.ui.AbstractUITag,
36       * String, String[])} as properties to verify.<p/> This implementation extends testdata from AbstractUITag.
37       *
38       * @return A Map of PropertyHolders values bound to {@link org.apache.struts2.views.jsp.AbstractUITagTest.PropertyHolder#getName()}
39       *         as key.
40       */
41      protected Map initializedGenericTagTestProperties() {
42          Map result = super.initializedGenericTagTestProperties();
43          new PropertyHolder("value", "true").addToMap(result);
44          return result;
45      }
46  
47      public void testGenericSimple() throws Exception {
48          CheckboxTag tag = new CheckboxTag();
49          verifyGenericProperties(tag, "simple", null);
50      }
51  
52      public void testGenericXhtml() throws Exception {
53          CheckboxTag tag = new CheckboxTag();
54          verifyGenericProperties(tag, "xhtml", null);
55      }
56  
57      public void testGenericAjax() throws Exception {
58          CheckboxTag tag = new CheckboxTag();
59          verifyGenericProperties(tag, "ajax", null);
60      }
61  
62      public void testChecked() throws Exception {
63          TestAction testAction = (TestAction) action;
64          testAction.setFoo("true");
65  
66          CheckboxTag tag = new CheckboxTag();
67          tag.setPageContext(pageContext);
68          tag.setId("someId");
69          tag.setLabel("mylabel");
70          tag.setName("foo");
71          tag.setFieldValue("baz");
72          tag.setOnfocus("test();");
73          tag.setTitle("mytitle");
74  
75          tag.doStartTag();
76          tag.doEndTag();
77  
78          verify(CheckboxTag.class.getResource("Checkbox-1.txt"));
79      }
80  
81      public void testCheckedWithTopLabelPosition() throws Exception {
82          TestAction testAction = (TestAction) action;
83          testAction.setFoo("true");
84  
85          CheckboxTag tag = new CheckboxTag();
86          tag.setPageContext(pageContext);
87          tag.setId("someId");
88          tag.setLabel("mylabel");
89          tag.setName("foo");
90          tag.setFieldValue("baz");
91          tag.setOnfocus("test();");
92          tag.setTitle("mytitle");
93          tag.setLabelposition("top");
94  
95          tag.doStartTag();
96          tag.doEndTag();
97  
98          verify(CheckboxTag.class.getResource("Checkbox-4.txt"));
99      }
100 
101     public void testCheckedWithLeftLabelPosition() throws Exception {
102         TestAction testAction = (TestAction) action;
103         testAction.setFoo("true");
104 
105         CheckboxTag tag = new CheckboxTag();
106         tag.setPageContext(pageContext);
107         tag.setId("someId");
108         tag.setLabel("mylabel");
109         tag.setName("foo");
110         tag.setFieldValue("baz");
111         tag.setOnfocus("test();");
112         tag.setTitle("mytitle");
113         tag.setLabelposition("left");
114 
115         tag.doStartTag();
116         tag.doEndTag();
117 
118         verify(CheckboxTag.class.getResource("Checkbox-5.txt"));
119     }
120 
121     public void testCheckedWithError() throws Exception {
122         TestAction testAction = (TestAction) action;
123         testAction.setFoo("true");
124         testAction.addFieldError("foo", "Some Foo Error");
125         testAction.addFieldError("foo", "Another Foo Error");
126 
127         CheckboxTag tag = new CheckboxTag();
128         tag.setPageContext(pageContext);
129         tag.setLabel("mylabel");
130         tag.setName("foo");
131         tag.setFieldValue("baz");
132         tag.setOndblclick("test();");
133         tag.setOnclick("test();");
134         tag.setTitle("mytitle");
135 
136         tag.doStartTag();
137         tag.doEndTag();
138 
139         verify(CheckboxTag.class.getResource("Checkbox-3.txt"));
140     }
141 
142     public void testUnchecked() throws Exception {
143         TestAction testAction = (TestAction) action;
144         testAction.setFoo("false");
145 
146         CheckboxTag tag = new CheckboxTag();
147         tag.setPageContext(pageContext);
148         tag.setLabel("mylabel");
149         tag.setName("foo");
150         tag.setFieldValue("baz");
151         tag.setTitle("mytitle");
152 
153         tag.doStartTag();
154         tag.doEndTag();
155 
156         verify(CheckboxTag.class.getResource("Checkbox-2.txt"));
157     }
158 }