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.freemarker.tags.TextFieldModel;
009: import com.opensymphony.webwork.views.jsp.AbstractUITagTest;
010: import freemarker.template.TransformControl;
011:
012: import java.util.HashMap;
013: import java.util.Map;
014:
015: /**
016: * @author Matt Ho <a href="mailto:matt@enginegreen.com"><matt@enginegreen.com></a>
017: * @version $Id: TextfieldTest.java 2088 2006-02-03 11:03:56Z rgielen $
018: */
019: public class TextfieldTest extends AbstractUITagTest {
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("maxlength", "10").addToMap(result);
032: new PropertyHolder("readonly", "true", "readonly=\"readonly\"")
033: .addToMap(result);
034: new PropertyHolder("size", "12").addToMap(result);
035: return result;
036: }
037:
038: public void testGenericSimple() throws Exception {
039: TextFieldTag tag = new TextFieldTag();
040: verifyGenericProperties(tag, "simple", null);
041: }
042:
043: public void testGenericXhtml() throws Exception {
044: TextFieldTag tag = new TextFieldTag();
045: verifyGenericProperties(tag, "xhtml", null);
046: }
047:
048: public void testGenericAjax() throws Exception {
049: TextFieldTag tag = new TextFieldTag();
050: verifyGenericProperties(tag, "ajax", null);
051: }
052:
053: public void testErrors() throws Exception {
054: TestAction testAction = (TestAction) action;
055: testAction.setFoo("bar");
056:
057: TextFieldTag tag = new TextFieldTag();
058: tag.setPageContext(pageContext);
059: tag.setId("myId");
060: tag.setLabel("mylabel");
061: tag.setName("foo");
062: tag.setValue("bar");
063: tag.setTitle("mytitle");
064:
065: testAction.addFieldError("foo", "bar error message");
066: tag.doStartTag();
067: tag.doEndTag();
068:
069: verify(TextFieldTag.class.getResource("Textfield-2.txt"));
070: }
071:
072: public void testNoLabelJsp() throws Exception {
073: TestAction testAction = (TestAction) action;
074: testAction.setFoo("bar");
075:
076: TextFieldTag tag = new TextFieldTag();
077: tag.setPageContext(pageContext);
078: tag.setName("myname");
079: tag.setValue("%{foo}");
080: tag.setSize("10");
081: tag.setOnblur("blahescape('somevalue');");
082:
083: tag.doStartTag();
084: tag.doEndTag();
085:
086: verify(TextFieldTag.class.getResource("Textfield-3.txt"));
087: }
088:
089: public void testNoLabelFtl() throws Exception {
090: TestAction testAction = (TestAction) action;
091: testAction.setFoo("bar");
092:
093: TextFieldModel model = new TextFieldModel(stack, request,
094: response);
095: HashMap params = new HashMap();
096: params.put("name", "myname");
097: params.put("value", "%{foo}");
098: params.put("size", "10");
099: params.put("onblur", "blahescape('somevalue');");
100: TransformControl control = (TransformControl) model.getWriter(
101: writer, params);
102: control.onStart();
103: control.afterBody();
104:
105: verify(TextFieldTag.class.getResource("Textfield-3.txt"));
106: }
107:
108: public void testSimple() throws Exception {
109: TestAction testAction = (TestAction) action;
110: testAction.setFoo("bar");
111:
112: TextFieldTag tag = new TextFieldTag();
113: tag.setPageContext(pageContext);
114: tag.setLabel("mylabel");
115: tag.setName("myname");
116: tag.setValue("%{foo}");
117: tag.setSize("10");
118:
119: tag.doStartTag();
120: tag.doEndTag();
121:
122: verify(TextFieldTag.class.getResource("Textfield-1.txt"));
123: }
124: }
|