View Javadoc

1   /*
2    * $Id: LabelTest.java 446875 2006-09-16 13:49:55Z tmjee $
3    *
4    * Copyright 2006 The Apache Software Foundation.
5    *
6    * Licensed under the Apache License, Version 2.0 (the "License");
7    * you may not use this file except in compliance with the License.
8    * You may obtain a copy of the License at
9    *
10   *      http://www.apache.org/licenses/LICENSE-2.0
11   *
12   * Unless required by applicable law or agreed to in writing, software
13   * distributed under the License is distributed on an "AS IS" BASIS,
14   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15   * See the License for the specific language governing permissions and
16   * limitations under the License.
17   */
18  package org.apache.struts2.views.jsp.ui;
19  
20  import java.util.HashMap;
21  import java.util.Map;
22  
23  import org.apache.struts2.TestAction;
24  import org.apache.struts2.views.jsp.AbstractUITagTest;
25  
26  
27  /***
28   */
29  public class LabelTest extends AbstractUITagTest {
30  
31      public void testSimple() throws Exception {
32          TestAction testAction = (TestAction) action;
33          testAction.setFoo("bar");
34  
35          LabelTag tag = new LabelTag();
36          tag.setPageContext(pageContext);
37          tag.setLabel("mylabel");
38          tag.setName("myname");
39          tag.setTitle("mytitle");
40          tag.setValue("%{foo}");
41  
42          tag.doStartTag();
43          tag.doEndTag();
44  
45          verify(LabelTest.class.getResource("Label-1.txt"));
46      }
47  
48      public void testSimpleWithLabelposition() throws Exception {
49          TestAction testAction = (TestAction) action;
50          testAction.setFoo("bar");
51  
52          LabelTag tag = new LabelTag();
53          tag.setPageContext(pageContext);
54          tag.setLabel("mylabel");
55          tag.setName("myname");
56          tag.setValue("%{foo}");
57          tag.setLabelposition("top");
58  
59          tag.doStartTag();
60          tag.doEndTag();
61  
62          verify(LabelTest.class.getResource("Label-3.txt"));
63      }
64  
65      /***
66       * Initialize a map of {@link org.apache.struts2.views.jsp.AbstractUITagTest.PropertyHolder} for generic tag
67       * property testing. Will be used when calling {@link #verifyGenericProperties(org.apache.struts2.views.jsp.ui.AbstractUITag,
68       * String, String[])} as properties to verify.<p/> This implementation extends testdata from AbstractUITag.
69       *
70       * @return A Map of PropertyHolders values bound to {@link org.apache.struts2.views.jsp.AbstractUITagTest.PropertyHolder#getName()}
71       *         as key.
72       */
73      protected Map initializedGenericTagTestProperties() {
74          Map result = new HashMap();
75          new PropertyHolder("title", "someTitle").addToMap(result);
76          new PropertyHolder("cssClass", "cssClass1", "class=\"cssClass1\"").addToMap(result);
77          new PropertyHolder("cssStyle", "cssStyle1", "style=\"cssStyle1\"").addToMap(result);
78          new PropertyHolder("id", "someId").addToMap(result);
79          new PropertyHolder("for", "someFor").addToMap(result);
80          return result;
81      }
82  
83      public void testWithNoValue() throws Exception {
84          TestAction testAction = (TestAction) action;
85          testAction.setFoo("baz");
86  
87          LabelTag tag = new LabelTag();
88          tag.setPageContext(pageContext);
89          tag.setLabel("mylabel");
90          tag.setName("foo");
91          tag.setFor("for");
92  
93          tag.doStartTag();
94          tag.doEndTag();
95  
96          verify(LabelTest.class.getResource("Label-2.txt"));
97      }
98  
99      public void testGenericSimple() throws Exception {
100         LabelTag tag = new LabelTag();
101         verifyGenericProperties(tag, "simple", null);
102     }
103 
104     public void testGenericXhtml() throws Exception {
105         LabelTag tag = new LabelTag();
106         verifyGenericProperties(tag, "xhtml", null);
107     }
108 
109     public void testGenericAjax() throws Exception {
110         LabelTag tag = new LabelTag();
111         verifyGenericProperties(tag, "ajax", null);
112     }
113 
114 }