View Javadoc

1   /*
2    * $Id: LabelTest.java 751799 2009-03-09 19:28:20Z musachy $
3    *
4    * Licensed to the Apache Software Foundation (ASF) under one
5    * or more contributor license agreements.  See the NOTICE file
6    * distributed with this work for additional information
7    * regarding copyright ownership.  The ASF licenses this file
8    * to you under the Apache License, Version 2.0 (the
9    * "License"); you may not use this file except in compliance
10   * with the License.  You may obtain a copy of the License at
11   *
12   *  http://www.apache.org/licenses/LICENSE-2.0
13   *
14   * Unless required by applicable law or agreed to in writing,
15   * software distributed under the License is distributed on an
16   * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
17   * KIND, either express or implied.  See the License for the
18   * specific language governing permissions and limitations
19   * under the License.
20   */
21  
22  package org.apache.struts2.views.jsp.ui;
23  
24  import java.util.HashMap;
25  import java.util.Map;
26  
27  import org.apache.struts2.TestAction;
28  import org.apache.struts2.views.jsp.AbstractUITagTest;
29  
30  
31  /***
32   */
33  public class LabelTest extends AbstractUITagTest {
34  
35      public void testSimple() throws Exception {
36          TestAction testAction = (TestAction) action;
37          testAction.setFoo("bar");
38  
39          LabelTag tag = new LabelTag();
40          tag.setPageContext(pageContext);
41          tag.setLabel("mylabel");
42          tag.setName("myname");
43          tag.setTitle("mytitle");
44          tag.setValue("%{foo}");
45  
46          tag.doStartTag();
47          tag.doEndTag();
48  
49          verify(LabelTest.class.getResource("Label-1.txt"));
50      }
51  
52      public void testSimpleWithLabelposition() throws Exception {
53          TestAction testAction = (TestAction) action;
54          testAction.setFoo("bar");
55  
56          LabelTag tag = new LabelTag();
57          tag.setPageContext(pageContext);
58          tag.setLabel("mylabel");
59          tag.setName("myname");
60          tag.setValue("%{foo}");
61          tag.setLabelposition("top");
62  
63          tag.doStartTag();
64          tag.doEndTag();
65  
66          verify(LabelTest.class.getResource("Label-3.txt"));
67      }
68  
69      /***
70       * Initialize a map of {@link org.apache.struts2.views.jsp.AbstractUITagTest.PropertyHolder} for generic tag
71       * property testing. Will be used when calling {@link #verifyGenericProperties(org.apache.struts2.views.jsp.ui.AbstractUITag,
72       * String, String[])} as properties to verify.<p/> This implementation extends testdata from AbstractUITag.
73       *
74       * @return A Map of PropertyHolders values bound to {@link org.apache.struts2.views.jsp.AbstractUITagTest.PropertyHolder#getName()}
75       *         as key.
76       */
77      protected Map initializedGenericTagTestProperties() {
78          Map result = new HashMap();
79          new PropertyHolder("title", "someTitle").addToMap(result);
80          new PropertyHolder("cssClass", "cssClass1", "class=\"cssClass1\"").addToMap(result);
81          new PropertyHolder("cssStyle", "cssStyle1", "style=\"cssStyle1\"").addToMap(result);
82          new PropertyHolder("id", "someId").addToMap(result);
83          new PropertyHolder("for", "someFor").addToMap(result);
84          return result;
85      }
86  
87      public void testWithNoValue() throws Exception {
88          TestAction testAction = (TestAction) action;
89          testAction.setFoo("baz");
90  
91          LabelTag tag = new LabelTag();
92          tag.setPageContext(pageContext);
93          tag.setLabel("mylabel");
94          tag.setName("foo");
95          tag.setFor("for");
96  
97          tag.doStartTag();
98          tag.doEndTag();
99  
100         verify(LabelTest.class.getResource("Label-5.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 testWithKeyNoValueFromStack() throws Exception {
114         TestAction testAction = (TestAction) action;
115         final String key = "labelKey";
116         final String value = "baz";
117         testAction.setText(key, value);
118 
119         testAction.setFoo("notToBeOutput");
120 
121         LabelTag tag = new LabelTag();
122         tag.setPageContext(pageContext);
123         tag.setLabel("mylabel");
124         tag.setFor("for");
125         tag.setName("foo2");
126         tag.setKey(key);
127 
128         tag.doStartTag();
129         tag.doEndTag();
130 
131         verify(LabelTest.class.getResource("Label-2.txt"));
132     }
133 
134      public void testWithKeyValueFromStack() throws Exception {
135         TestAction testAction = (TestAction) action;
136         final String key = "labelKey";
137         final String value = "baz";
138         testAction.setText(key, value);
139 
140         testAction.setFoo("output");
141 
142         LabelTag tag = new LabelTag();
143         tag.setPageContext(pageContext);
144         tag.setLabel("mylabel");
145         tag.setFor("for");
146         tag.setName("foo");
147         tag.setKey(key);
148 
149         tag.doStartTag();
150         tag.doEndTag();
151 
152         verify(LabelTest.class.getResource("Label-4.txt"));
153     }
154 
155 }