KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * $Id: TestELFileTag.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.TestFormBean;
32 import org.apache.strutsel.taglib.utils.TestHelper;
33
34
35 public class TestELFileTag
36     extends JspTagTestCase {
37
38     protected static final String JavaDoc PROPERTY_ATTR_VALUE =
39         "stringProperty";
40     protected static final String JavaDoc REQUIRED_DISABLED_VALUE_KEY =
41             "RequiredDisabledValue";
42     protected static final String JavaDoc REQUIRED_TYPE_VALUE_KEY =
43             "RequiredTypeValue";
44     protected static final String JavaDoc REQUIRED_VALUE_VALUE_KEY =
45             "RequiredValueValue";
46     protected static final String JavaDoc REQUIRED_NAME_VALUE_KEY =
47             "RequiredNameValue";
48     protected ELFileTag elFileTag = null;
49
50     public TestELFileTag(String JavaDoc theName) {
51         super(theName);
52     }
53
54     public static void main(String JavaDoc[] args) {
55         junit.awtui.TestRunner.main(
56                 new String JavaDoc[] { TestELFileTag.class.getName() });
57     }
58
59     public static Test suite() {
60         return new TestSuite(TestELFileTag.class);
61     }
62
63     public void setUp() {
64         elFileTag = new ELFileTag();
65         elFileTag.setPageContext(pageContext);
66         elFileTag.setPropertyExpr(PROPERTY_ATTR_VALUE);
67     }
68
69     public void tearDown() {
70         elFileTag = null;
71     }
72
73     /**
74      * Tests a plain "file" tag, with all default attribute values.
75      */

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

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