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