001: /*
002: * Copyright (c) 2002-2003 by OpenSymphony
003: * All rights reserved.
004: */
005: package com.opensymphony.webwork.views.jsp.ui;
006:
007: import com.opensymphony.webwork.TestAction;
008: import com.opensymphony.webwork.views.jsp.AbstractUITagTest;
009:
010: import java.util.Map;
011:
012: /**
013: * @author Matt Ho <a href="mailto:matt@enginegreen.com"><matt@enginegreen.com></a>
014: * @version $Id: CheckboxTest.java 2322 2006-03-05 21:02:57Z plightbo $
015: */
016: public class CheckboxTest extends AbstractUITagTest {
017:
018: public CheckboxTest() {
019: }
020:
021: /**
022: * Initialize a map of {@link com.opensymphony.webwork.views.jsp.AbstractUITagTest.PropertyHolder} for generic tag
023: * property testing. Will be used when calling {@link #verifyGenericProperties(com.opensymphony.webwork.views.jsp.ui.AbstractUITag,
024: * String, String[])} as properties to verify.<p/> This implementation extends testdata from AbstractUITag.
025: *
026: * @return A Map of PropertyHolders values bound to {@link com.opensymphony.webwork.views.jsp.AbstractUITagTest.PropertyHolder#getName()}
027: * as key.
028: */
029: protected Map initializedGenericTagTestProperties() {
030: Map result = super .initializedGenericTagTestProperties();
031: new PropertyHolder("value", "true").addToMap(result);
032: return result;
033: }
034:
035: public void testGenericSimple() throws Exception {
036: CheckboxTag tag = new CheckboxTag();
037: verifyGenericProperties(tag, "simple", null);
038: }
039:
040: public void testGenericXhtml() throws Exception {
041: CheckboxTag tag = new CheckboxTag();
042: verifyGenericProperties(tag, "xhtml", null);
043: }
044:
045: public void testGenericAjax() throws Exception {
046: CheckboxTag tag = new CheckboxTag();
047: verifyGenericProperties(tag, "ajax", null);
048: }
049:
050: public void testChecked() throws Exception {
051: TestAction testAction = (TestAction) action;
052: testAction.setFoo("true");
053:
054: CheckboxTag tag = new CheckboxTag();
055: tag.setPageContext(pageContext);
056: tag.setId("someId");
057: tag.setLabel("mylabel");
058: tag.setName("foo");
059: tag.setFieldValue("baz");
060: tag.setOnfocus("test();");
061: tag.setTitle("mytitle");
062:
063: tag.doStartTag();
064: tag.doEndTag();
065:
066: verify(CheckboxTag.class.getResource("Checkbox-1.txt"));
067: }
068:
069: public void testCheckedWithTopLabelPosition() throws Exception {
070: TestAction testAction = (TestAction) action;
071: testAction.setFoo("true");
072:
073: CheckboxTag tag = new CheckboxTag();
074: tag.setPageContext(pageContext);
075: tag.setId("someId");
076: tag.setLabel("mylabel");
077: tag.setName("foo");
078: tag.setFieldValue("baz");
079: tag.setOnfocus("test();");
080: tag.setTitle("mytitle");
081: tag.setLabelPosition("top");
082:
083: tag.doStartTag();
084: tag.doEndTag();
085:
086: verify(CheckboxTag.class.getResource("Checkbox-4.txt"));
087: }
088:
089: public void testCheckedWithLeftLabelPosition() throws Exception {
090: TestAction testAction = (TestAction) action;
091: testAction.setFoo("true");
092:
093: CheckboxTag tag = new CheckboxTag();
094: tag.setPageContext(pageContext);
095: tag.setId("someId");
096: tag.setLabel("mylabel");
097: tag.setName("foo");
098: tag.setFieldValue("baz");
099: tag.setOnfocus("test();");
100: tag.setTitle("mytitle");
101: tag.setLabelPosition("left");
102:
103: tag.doStartTag();
104: tag.doEndTag();
105:
106: verify(CheckboxTag.class.getResource("Checkbox-5.txt"));
107: }
108:
109: public void testCheckedWithError() throws Exception {
110: TestAction testAction = (TestAction) action;
111: testAction.setFoo("true");
112: testAction.addFieldError("foo", "Some Foo Error");
113: testAction.addFieldError("foo", "Another Foo Error");
114:
115: CheckboxTag tag = new CheckboxTag();
116: tag.setPageContext(pageContext);
117: tag.setLabel("mylabel");
118: tag.setName("foo");
119: tag.setFieldValue("baz");
120: tag.setOndblclick("test();");
121: tag.setOnclick("test();");
122: tag.setTitle("mytitle");
123:
124: tag.doStartTag();
125: tag.doEndTag();
126:
127: verify(CheckboxTag.class.getResource("Checkbox-3.txt"));
128: }
129:
130: public void testUnchecked() throws Exception {
131: TestAction testAction = (TestAction) action;
132: testAction.setFoo("false");
133:
134: CheckboxTag tag = new CheckboxTag();
135: tag.setPageContext(pageContext);
136: tag.setLabel("mylabel");
137: tag.setName("foo");
138: tag.setFieldValue("baz");
139: tag.setTitle("mytitle");
140:
141: tag.doStartTag();
142: tag.doEndTag();
143:
144: verify(CheckboxTag.class.getResource("Checkbox-2.txt"));
145: }
146: }
|