001: /*
002: * $Id: TextfieldTest.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.HashMap;
024: import java.util.Map;
025:
026: import org.apache.struts2.TestAction;
027: import org.apache.struts2.views.freemarker.tags.TextFieldModel;
028: import org.apache.struts2.views.jsp.AbstractUITagTest;
029:
030: import freemarker.template.TransformControl;
031:
032: /**
033: */
034: public class TextfieldTest extends AbstractUITagTest {
035:
036: /**
037: * Initialize a map of {@link org.apache.struts2.views.jsp.AbstractUITagTest.PropertyHolder} for generic tag
038: * property testing. Will be used when calling {@link #verifyGenericProperties(org.apache.struts2.views.jsp.ui.AbstractUITag,
039: * String, String[])} as properties to verify.<p/> This implementation extends testdata from AbstractUITag.
040: *
041: * @return A Map of PropertyHolders values bound to {@link org.apache.struts2.views.jsp.AbstractUITagTest.PropertyHolder#getName()}
042: * as key.
043: */
044: protected Map initializedGenericTagTestProperties() {
045: Map result = super .initializedGenericTagTestProperties();
046: new PropertyHolder("maxlength", "10").addToMap(result);
047: new PropertyHolder("readonly", "true", "readonly=\"readonly\"")
048: .addToMap(result);
049: new PropertyHolder("size", "12").addToMap(result);
050: return result;
051: }
052:
053: public void testGenericSimple() throws Exception {
054: TextFieldTag tag = new TextFieldTag();
055: verifyGenericProperties(tag, "simple", null);
056: }
057:
058: public void testGenericXhtml() throws Exception {
059: TextFieldTag tag = new TextFieldTag();
060: verifyGenericProperties(tag, "xhtml", null);
061: }
062:
063: public void testGenericAjax() throws Exception {
064: TextFieldTag tag = new TextFieldTag();
065: verifyGenericProperties(tag, "ajax", null);
066: }
067:
068: public void testErrors() throws Exception {
069: TestAction testAction = (TestAction) action;
070: testAction.setFoo("bar");
071:
072: TextFieldTag tag = new TextFieldTag();
073: tag.setPageContext(pageContext);
074: tag.setId("myId");
075: tag.setLabel("mylabel");
076: tag.setName("foo");
077: tag.setValue("bar");
078: tag.setTitle("mytitle");
079:
080: testAction.addFieldError("foo", "bar error message");
081: tag.doStartTag();
082: tag.doEndTag();
083:
084: verify(TextFieldTag.class.getResource("Textfield-2.txt"));
085: }
086:
087: public void testNoLabelJsp() throws Exception {
088: TestAction testAction = (TestAction) action;
089: testAction.setFoo("bar");
090:
091: TextFieldTag tag = new TextFieldTag();
092: tag.setPageContext(pageContext);
093: tag.setName("myname");
094: tag.setValue("%{foo}");
095: tag.setSize("10");
096: tag.setOnblur("blahescape('somevalue');");
097:
098: tag.doStartTag();
099: tag.doEndTag();
100:
101: verify(TextFieldTag.class.getResource("Textfield-3.txt"));
102: }
103:
104: public void testNoLabelFtl() throws Exception {
105: TestAction testAction = (TestAction) action;
106: testAction.setFoo("bar");
107:
108: TextFieldModel model = new TextFieldModel(stack, request,
109: response);
110: HashMap params = new HashMap();
111: params.put("name", "myname");
112: params.put("value", "%{foo}");
113: params.put("size", "10");
114: params.put("onblur", "blahescape('somevalue');");
115: TransformControl control = (TransformControl) model.getWriter(
116: writer, params);
117: control.onStart();
118: control.afterBody();
119:
120: verify(TextFieldTag.class.getResource("Textfield-3.txt"));
121: }
122:
123: public void testSimple() throws Exception {
124: TestAction testAction = (TestAction) action;
125: testAction.setFoo("bar");
126:
127: TextFieldTag tag = new TextFieldTag();
128: tag.setPageContext(pageContext);
129: tag.setLabel("mylabel");
130: tag.setName("myname");
131: tag.setValue("%{foo}");
132: tag.setSize("10");
133:
134: tag.doStartTag();
135: tag.doEndTag();
136:
137: verify(TextFieldTag.class.getResource("Textfield-1.txt"));
138: }
139: }
|