KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > strutsel > taglib > html > TestELCancelTag


1 /*
2  * $Id: TestELCancelTag.java 54933 2004-10-16 17:04:52Z germuska $
3  *
4  * Copyright 1999-2004 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
19 package org.apache.strutsel.taglib.html;
20
21 import java.util.HashMap JavaDoc;
22
23 import javax.servlet.ServletException JavaDoc;
24 import javax.servlet.http.HttpServletResponse JavaDoc;
25 import javax.servlet.jsp.JspException JavaDoc;
26 import junit.framework.Test;
27 import junit.framework.TestSuite;
28
29 import org.apache.strutsel.taglib.utils.DOMHelper;
30 import org.apache.strutsel.taglib.utils.JspTagTestCase;
31 import org.apache.strutsel.taglib.utils.TestHelper;
32
33
34 public class TestELCancelTag
35     extends JspTagTestCase {
36
37     protected static final String JavaDoc PROPERTY_ATTR_VALUE = "stuff";
38     protected static final String JavaDoc REQUIRED_DISABLED_VALUE_KEY =
39             "RequiredDisabledValue";
40     protected static final String JavaDoc REQUIRED_TYPE_VALUE_KEY =
41             "RequiredTypeValue";
42     protected static final String JavaDoc REQUIRED_VALUE_VALUE_KEY =
43             "RequiredValueValue";
44     protected static final String JavaDoc REQUIRED_NAME_VALUE_KEY =
45             "RequiredNameValue";
46     protected ELCancelTag elCancelTag = null;
47
48     public TestELCancelTag(String JavaDoc theName) {
49         super(theName);
50     }
51
52     public static void main(String JavaDoc[] args) {
53         junit.awtui.TestRunner.main(
54                 new String JavaDoc[] { TestELCancelTag.class.getName() });
55     }
56
57     public static Test suite() {
58         return new TestSuite(TestELCancelTag.class);
59     }
60
61     public void setUp() {
62         elCancelTag = new ELCancelTag();
63         elCancelTag.setPageContext(pageContext);
64         elCancelTag.setPropertyExpr(PROPERTY_ATTR_VALUE);
65     }
66
67     public void tearDown() {
68         elCancelTag = null;
69     }
70
71     /**
72      * Tests a plain "cancel" tag, with all default attribute values.
73      */

74     public void testPlain()
75                    throws ServletException JavaDoc, JspException JavaDoc {
76         HttpServletResponse JavaDoc response = (HttpServletResponse JavaDoc)pageContext.getResponse();
77
78         String JavaDoc requiredNameValue = PROPERTY_ATTR_VALUE;
79         response.addHeader(REQUIRED_NAME_VALUE_KEY, requiredNameValue);
80         String JavaDoc requiredTypeValue = "submit";
81         response.addHeader(REQUIRED_TYPE_VALUE_KEY, requiredTypeValue);
82
83         String JavaDoc requiredValueValue = "Cancel";
84         response.addHeader(REQUIRED_VALUE_VALUE_KEY, requiredValueValue);
85
86         int startTagReturn = elCancelTag.doStartTag();
87         int afterBodyReturn = elCancelTag.doAfterBody();
88         int endTagReturn = elCancelTag.doEndTag();
89     }
90
91     public void endPlain(com.meterware.httpunit.WebResponse testResponse) {
92         try {
93             TestHelper.printResponse(testResponse);
94
95             org.w3c.dom.Document JavaDoc document = testResponse.getDOM();
96             DOMHelper.printNode(document.getDocumentElement());
97
98             HashMap JavaDoc attrMap = new HashMap JavaDoc();
99             DOMHelper.recordFoundAttributes(testResponse.getDOM(),
100                                             "/html/body/input", attrMap);
101             DOMHelper.verifyAttributesPresent(attrMap,
102                                               new String JavaDoc[] {
103                 "name", "type", "value", "onclick" },
104                                               false);
105
106             checkAttrValue(attrMap, testResponse, REQUIRED_NAME_VALUE_KEY,
107                            "cancel", "name");
108             checkAttrValue(attrMap, testResponse, REQUIRED_TYPE_VALUE_KEY,
109                            "cancel", "type");
110             checkAttrValue(attrMap, testResponse, REQUIRED_VALUE_VALUE_KEY,
111                            "cancel", "value");
112         } catch (Exception JavaDoc ex) {
113             ex.printStackTrace();
114             fail();
115         }
116     }
117
118     /**
119      * Tests the "disabled" attribute.
120      */

121     public void testDisabled()
122                       throws ServletException JavaDoc, JspException JavaDoc {
123
124         elCancelTag.setDisabledExpr("true");
125
126         String JavaDoc requiredDisabledValue = "disabled";
127         response.addHeader(REQUIRED_DISABLED_VALUE_KEY, requiredDisabledValue);
128
129         int startTagReturn = elCancelTag.doStartTag();
130         int afterBodyReturn = elCancelTag.doAfterBody();
131         int endTagReturn = elCancelTag.doEndTag();
132     }
133
134     public void endDisabled(com.meterware.httpunit.WebResponse testResponse) {
135         try {
136             TestHelper.printResponse(testResponse);
137
138             org.w3c.dom.Document JavaDoc document = testResponse.getDOM();
139             DOMHelper.printNode(document.getDocumentElement());
140
141             HashMap JavaDoc attrMap = new HashMap JavaDoc();
142             DOMHelper.recordFoundAttributes(testResponse.getDOM(),
143                                             "/html/body/input", attrMap);
144             DOMHelper.verifyAttributesPresent(attrMap,
145                                               new String JavaDoc[] { "disabled" },
146                                               true);
147             checkAttrValue(attrMap, testResponse, REQUIRED_DISABLED_VALUE_KEY,
148                            "cancel", "disabled");
149         } catch (Exception JavaDoc ex) {
150             ex.printStackTrace();
151             fail();
152         }
153     }
154 }
155
Popular Tags