View Javadoc

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