View Javadoc

1   /*
2    * $Id: ResetTest.java 651946 2008-04-27 13:41:38Z apetrelli $
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   * Reset Component Test.
32   *
33   */
34  public class ResetTest extends AbstractUITagTest {
35  
36      public void testDefaultValues() throws Exception {
37          TestAction testAction = (TestAction) action;
38          testAction.setFoo("bar");
39  
40          ResetTag tag = new ResetTag();
41          tag.setPageContext(pageContext);
42          tag.setLabel("mylabel");
43          tag.setName("myname");
44          tag.setTitle("mytitle");
45  
46          tag.doStartTag();
47          tag.doEndTag();
48  
49          verify(TextFieldTag.class.getResource("Reset-2.txt"));
50      }
51  
52      public void testSimple() throws Exception {
53          TestAction testAction = (TestAction) action;
54          testAction.setFoo("bar");
55  
56          ResetTag tag = new ResetTag();
57          tag.setPageContext(pageContext);
58          tag.setLabel("mylabel");
59          tag.setAlign("left");
60          tag.setName("myname");
61          tag.setValue("%{foo}");
62  
63          tag.doStartTag();
64          tag.doEndTag();
65  
66          verify(TextFieldTag.class.getResource("Reset-1.txt"));
67      }
68  
69      public void testButtonSimple() throws Exception {
70          TestAction testAction = (TestAction) action;
71          testAction.setFoo("bar");
72  
73          ResetTag tag = new ResetTag();
74          tag.setPageContext(pageContext);
75          tag.setType("button");
76          tag.setName("myname");
77          tag.setValue("%{foo}");
78  
79          tag.doStartTag();
80          tag.doEndTag();
81  
82          verify(TextFieldTag.class.getResource("Reset-3.txt"));
83      }
84  
85      public void testButtonWithLabel() throws Exception {
86          TestAction testAction = (TestAction) action;
87          testAction.setFoo("bar");
88  
89          ResetTag tag = new ResetTag();
90          tag.setPageContext(pageContext);
91          tag.setLabel("mylabel");
92          tag.setType("button");
93          tag.setAlign("left");
94          tag.setName("myname");
95          tag.setValue("%{foo}");
96  
97          tag.doStartTag();
98          tag.doEndTag();
99  
100         verify(TextFieldTag.class.getResource("Reset-4.txt"));
101     }
102 
103     /***
104      * Initialize a map of {@link org.apache.struts2.views.jsp.AbstractUITagTest.PropertyHolder} for generic tag
105      * property testing. Will be used when calling {@link #verifyGenericProperties(AbstractUITag,
106      * String, String[])} as properties to verify.<p/> This implementation extends testdata from AbstractUITag.
107      *
108      * @return A Map of PropertyHolders values bound to {@link org.apache.struts2.views.jsp.AbstractUITagTest.PropertyHolder#getName()}
109      *         as key.
110      */
111     protected Map initializedGenericTagTestProperties() {
112         Map result = new HashMap();
113         new PropertyHolder("title", "someTitle").addToMap(result);
114         new PropertyHolder("cssClass", "cssClass1", "class=\"cssClass1\"").addToMap(result);
115         new PropertyHolder("cssStyle", "cssStyle1", "style=\"cssStyle1\"").addToMap(result);
116         new PropertyHolder("name", "someName").addToMap(result);
117         new PropertyHolder("value", "someValue").addToMap(result);
118         return result;
119     }
120 
121     public void testGenericSimple() throws Exception {
122         ResetTag tag = new ResetTag();
123         verifyGenericProperties(tag, "simple", null);
124     }
125 
126     public void testGenericXhtml() throws Exception {
127         ResetTag tag = new ResetTag();
128         verifyGenericProperties(tag, "xhtml", null);
129     }
130 }