001: /*
002: * $Id: LabelTest.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.jsp.AbstractUITagTest;
028:
029: /**
030: */
031: public class LabelTest extends AbstractUITagTest {
032:
033: public void testSimple() throws Exception {
034: TestAction testAction = (TestAction) action;
035: testAction.setFoo("bar");
036:
037: LabelTag tag = new LabelTag();
038: tag.setPageContext(pageContext);
039: tag.setLabel("mylabel");
040: tag.setName("myname");
041: tag.setTitle("mytitle");
042: tag.setValue("%{foo}");
043:
044: tag.doStartTag();
045: tag.doEndTag();
046:
047: verify(LabelTest.class.getResource("Label-1.txt"));
048: }
049:
050: public void testSimpleWithLabelposition() throws Exception {
051: TestAction testAction = (TestAction) action;
052: testAction.setFoo("bar");
053:
054: LabelTag tag = new LabelTag();
055: tag.setPageContext(pageContext);
056: tag.setLabel("mylabel");
057: tag.setName("myname");
058: tag.setValue("%{foo}");
059: tag.setLabelposition("top");
060:
061: tag.doStartTag();
062: tag.doEndTag();
063:
064: verify(LabelTest.class.getResource("Label-3.txt"));
065: }
066:
067: /**
068: * Initialize a map of {@link org.apache.struts2.views.jsp.AbstractUITagTest.PropertyHolder} for generic tag
069: * property testing. Will be used when calling {@link #verifyGenericProperties(org.apache.struts2.views.jsp.ui.AbstractUITag,
070: * String, String[])} as properties to verify.<p/> This implementation extends testdata from AbstractUITag.
071: *
072: * @return A Map of PropertyHolders values bound to {@link org.apache.struts2.views.jsp.AbstractUITagTest.PropertyHolder#getName()}
073: * as key.
074: */
075: protected Map initializedGenericTagTestProperties() {
076: Map result = new HashMap();
077: new PropertyHolder("title", "someTitle").addToMap(result);
078: new PropertyHolder("cssClass", "cssClass1",
079: "class=\"cssClass1\"").addToMap(result);
080: new PropertyHolder("cssStyle", "cssStyle1",
081: "style=\"cssStyle1\"").addToMap(result);
082: new PropertyHolder("id", "someId").addToMap(result);
083: new PropertyHolder("for", "someFor").addToMap(result);
084: return result;
085: }
086:
087: public void testWithNoValue() throws Exception {
088: TestAction testAction = (TestAction) action;
089: testAction.setFoo("baz");
090:
091: LabelTag tag = new LabelTag();
092: tag.setPageContext(pageContext);
093: tag.setLabel("mylabel");
094: tag.setName("foo");
095: tag.setFor("for");
096:
097: tag.doStartTag();
098: tag.doEndTag();
099:
100: verify(LabelTest.class.getResource("Label-2.txt"));
101: }
102:
103: public void testGenericSimple() throws Exception {
104: LabelTag tag = new LabelTag();
105: verifyGenericProperties(tag, "simple", null);
106: }
107:
108: public void testGenericXhtml() throws Exception {
109: LabelTag tag = new LabelTag();
110: verifyGenericProperties(tag, "xhtml", null);
111: }
112:
113: public void testGenericAjax() throws Exception {
114: LabelTag tag = new LabelTag();
115: verifyGenericProperties(tag, "ajax", null);
116: }
117:
118: }
|