001: /*
002: * $Id: CheckboxTest.java 471756 2006-11-06 15:01:43Z husted $
003: *
004: * Licensed to the Apache Software Foundation (ASF) under one
005: * or more contributor license agreements. See the NOTICE file
006: * distributed with this work for additional information
007: * regarding copyright ownership. The ASF licenses this file
008: * to you under the Apache License, Version 2.0 (the
009: * "License"); you may not use this file except in compliance
010: * with the License. You may obtain a copy of the License at
011: *
012: * http://www.apache.org/licenses/LICENSE-2.0
013: *
014: * Unless required by applicable law or agreed to in writing,
015: * software distributed under the License is distributed on an
016: * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
017: * KIND, either express or implied. See the License for the
018: * specific language governing permissions and limitations
019: * under the License.
020: */
021: package org.apache.struts2.views.jsp.ui;
022:
023: import java.util.Map;
024:
025: import org.apache.struts2.TestAction;
026: import org.apache.struts2.views.jsp.AbstractUITagTest;
027:
028: /**
029: */
030: public class CheckboxTest extends AbstractUITagTest {
031:
032: public CheckboxTest() {
033: }
034:
035: /**
036: * Initialize a map of {@link org.apache.struts2.views.jsp.AbstractUITagTest.PropertyHolder} for generic tag
037: * property testing. Will be used when calling {@link #verifyGenericProperties(org.apache.struts2.views.jsp.ui.AbstractUITag,
038: * String, String[])} as properties to verify.<p/> This implementation extends testdata from AbstractUITag.
039: *
040: * @return A Map of PropertyHolders values bound to {@link org.apache.struts2.views.jsp.AbstractUITagTest.PropertyHolder#getName()}
041: * as key.
042: */
043: protected Map initializedGenericTagTestProperties() {
044: Map result = super .initializedGenericTagTestProperties();
045: new PropertyHolder("value", "true").addToMap(result);
046: return result;
047: }
048:
049: public void testGenericSimple() throws Exception {
050: CheckboxTag tag = new CheckboxTag();
051: verifyGenericProperties(tag, "simple", null);
052: }
053:
054: public void testGenericXhtml() throws Exception {
055: CheckboxTag tag = new CheckboxTag();
056: verifyGenericProperties(tag, "xhtml", null);
057: }
058:
059: public void testGenericAjax() throws Exception {
060: CheckboxTag tag = new CheckboxTag();
061: verifyGenericProperties(tag, "ajax", null);
062: }
063:
064: public void testChecked() throws Exception {
065: TestAction testAction = (TestAction) action;
066: testAction.setFoo("true");
067:
068: CheckboxTag tag = new CheckboxTag();
069: tag.setPageContext(pageContext);
070: tag.setId("someId");
071: tag.setLabel("mylabel");
072: tag.setName("foo");
073: tag.setFieldValue("baz");
074: tag.setOnfocus("test();");
075: tag.setTitle("mytitle");
076:
077: tag.doStartTag();
078: tag.doEndTag();
079:
080: verify(CheckboxTag.class.getResource("Checkbox-1.txt"));
081: }
082:
083: public void testCheckedWithTopLabelPosition() throws Exception {
084: TestAction testAction = (TestAction) action;
085: testAction.setFoo("true");
086:
087: CheckboxTag tag = new CheckboxTag();
088: tag.setPageContext(pageContext);
089: tag.setId("someId");
090: tag.setLabel("mylabel");
091: tag.setName("foo");
092: tag.setFieldValue("baz");
093: tag.setOnfocus("test();");
094: tag.setTitle("mytitle");
095: tag.setLabelposition("top");
096:
097: tag.doStartTag();
098: tag.doEndTag();
099:
100: verify(CheckboxTag.class.getResource("Checkbox-4.txt"));
101: }
102:
103: public void testCheckedWithLeftLabelPosition() throws Exception {
104: TestAction testAction = (TestAction) action;
105: testAction.setFoo("true");
106:
107: CheckboxTag tag = new CheckboxTag();
108: tag.setPageContext(pageContext);
109: tag.setId("someId");
110: tag.setLabel("mylabel");
111: tag.setName("foo");
112: tag.setFieldValue("baz");
113: tag.setOnfocus("test();");
114: tag.setTitle("mytitle");
115: tag.setLabelposition("left");
116:
117: tag.doStartTag();
118: tag.doEndTag();
119:
120: verify(CheckboxTag.class.getResource("Checkbox-5.txt"));
121: }
122:
123: public void testCheckedWithError() throws Exception {
124: TestAction testAction = (TestAction) action;
125: testAction.setFoo("true");
126: testAction.addFieldError("foo", "Some Foo Error");
127: testAction.addFieldError("foo", "Another Foo Error");
128:
129: CheckboxTag tag = new CheckboxTag();
130: tag.setPageContext(pageContext);
131: tag.setLabel("mylabel");
132: tag.setName("foo");
133: tag.setFieldValue("baz");
134: tag.setOndblclick("test();");
135: tag.setOnclick("test();");
136: tag.setTitle("mytitle");
137:
138: tag.doStartTag();
139: tag.doEndTag();
140:
141: verify(CheckboxTag.class.getResource("Checkbox-3.txt"));
142: }
143:
144: public void testUnchecked() throws Exception {
145: TestAction testAction = (TestAction) action;
146: testAction.setFoo("false");
147:
148: CheckboxTag tag = new CheckboxTag();
149: tag.setPageContext(pageContext);
150: tag.setLabel("mylabel");
151: tag.setName("foo");
152: tag.setFieldValue("baz");
153: tag.setTitle("mytitle");
154:
155: tag.doStartTag();
156: tag.doEndTag();
157:
158: verify(CheckboxTag.class.getResource("Checkbox-2.txt"));
159: }
160: }
|