Source Code Cross Referenced for TestWebRequest.java in  » Testing » jakarta-cactus » org » apache » cactus » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Testing » jakarta cactus » org.apache.cactus 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:         * ========================================================================
003:         * 
004:         * Copyright 2001-2004 The Apache Software Foundation.
005:         *
006:         * Licensed under the Apache License, Version 2.0 (the "License");
007:         * you may not use this file except in compliance with the License.
008:         * You may obtain a copy of the License at
009:         * 
010:         *   http://www.apache.org/licenses/LICENSE-2.0
011:         * 
012:         * Unless required by applicable law or agreed to in writing, software
013:         * distributed under the License is distributed on an "AS IS" BASIS,
014:         * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
015:         * See the License for the specific language governing permissions and
016:         * limitations under the License.
017:         * 
018:         * ========================================================================
019:         */
020:        package org.apache.cactus;
021:
022:        import java.util.Enumeration;
023:
024:        import junit.framework.TestCase;
025:
026:        import org.apache.cactus.internal.WebRequestImpl;
027:        import org.apache.cactus.internal.configuration.DefaultServletConfiguration;
028:        import org.apache.cactus.util.ChainedRuntimeException;
029:
030:        /**
031:         * Unit tests of the <code>WebRequest</code> class.
032:         *
033:         * @version $Id: TestWebRequest.java 238991 2004-05-22 11:34:50Z vmassol $
034:         */
035:        public class TestWebRequest extends TestCase {
036:            /**
037:             * Object to unit test.
038:             */
039:            private WebRequest request;
040:
041:            /**
042:             * @see TestCase#setUp()
043:             */
044:            protected void setUp() {
045:                request = new WebRequestImpl(new DefaultServletConfiguration());
046:            }
047:
048:            /**
049:             * Verify that an exception is thrown when an invalid HTTP METHOD is used
050:             * when adding an HTTP parameter.
051:             */
052:            public void testAddParameterInvalidMethod() {
053:                try {
054:                    request.addParameter("param1", "value1", "INVALIDMETHOD");
055:                    fail("Should have thrown an exception");
056:                } catch (ChainedRuntimeException e) {
057:                    assertEquals(
058:                            "The method need to be either \"POST\" or \"GET\"",
059:                            e.getMessage());
060:                }
061:            }
062:
063:            /**
064:             * Verify that <code>getParameterGet</code> returns the first parameter
065:             * that was added to the request.
066:             */
067:            public void testGetParametersGetOk() {
068:                request.addParameter("param1", "value1", WebRequest.GET_METHOD);
069:                request.addParameter("param1", "value2", WebRequest.GET_METHOD);
070:
071:                String result = request.getParameterGet("param1");
072:
073:                assertEquals("value1", result);
074:            }
075:
076:            /**
077:             * Verify that <code>getParameterGet</code> returns null if no parameter
078:             * of a given name was added to the request.
079:             */
080:            public void testGetParameterGetNull() {
081:                request
082:                        .addParameter("param1", "value1",
083:                                WebRequest.POST_METHOD);
084:
085:                String result = request.getParameterGet("param1");
086:
087:                assertNull(result);
088:            }
089:
090:            /**
091:             * Verify that <code>getParameterPost</code> returns the first parameter
092:             * that was added to the request.
093:             */
094:            public void testGetParametersPostOk() {
095:                request
096:                        .addParameter("param1", "value1",
097:                                WebRequest.POST_METHOD);
098:                request
099:                        .addParameter("param1", "value2",
100:                                WebRequest.POST_METHOD);
101:
102:                String result = request.getParameterPost("param1");
103:
104:                assertEquals("value1", result);
105:            }
106:
107:            /**
108:             * Verify that <code>getParameterPost</code> returns null if no parameter
109:             * of a given name was added to the request.
110:             */
111:            public void testGetParameterPostNull() {
112:                request.addParameter("param1", "value1", WebRequest.GET_METHOD);
113:
114:                String result = request.getParameterPost("param1");
115:
116:                assertNull(result);
117:            }
118:
119:            /**
120:             * Verify that <code>getHeader</code> returns the first header
121:             * that was added to the request.
122:             */
123:            public void testGetHeaderOk() {
124:                request.addHeader("header1", "value1");
125:                request.addHeader("header2", "value2");
126:
127:                String result = request.getHeader("header1");
128:
129:                assertEquals("value1", result);
130:            }
131:
132:            /**
133:             * Verify that <code>getHeader</code> returns null if no header
134:             * of a given name was added to the request.
135:             */
136:            public void testGetHeaderNull() {
137:                String result = request.getHeader("header1");
138:
139:                assertNull(result);
140:            }
141:
142:            /**
143:             * Verify that <Code>toString()</code> returns a nice string representation
144:             * of the <code>WebRequest</code>.
145:             */
146:            public void testToString() {
147:                request.addHeader("header1", "value1");
148:                request.addHeader("header1", "value2");
149:                request.addParameter("param1", "value1", WebRequest.GET_METHOD);
150:                request
151:                        .addParameter("param1", "value1",
152:                                WebRequest.POST_METHOD);
153:                request.addCookie("cookie1", "value1");
154:                request.setAutomaticSession(false);
155:                request.setURL("jakarta.apache.org:80", "/catalog", "/garden",
156:                        "/implements/", "param1=value1&param2=&param3=value3");
157:
158:                String result = request.toString();
159:
160:                assertEquals(
161:                        "simulation URL = [protocol = [http], host name = "
162:                                + "[jakarta.apache.org], port = [80], context path = [/catalog], "
163:                                + "servlet path = [/garden], path info = [/implements/], query "
164:                                + "string = [param1=value1&param2=&param3=value3]], automatic "
165:                                + "session = [false], cookies = [[name = [cookie1], value = "
166:                                + "[value1], domain = [localhost], path = [null], isSecure = "
167:                                + "[false], comment = [null], expiryDate = [null]]], headers = "
168:                                + "[[[header1] = [[value1], [value2]]]], GET parameters = "
169:                                + "[[[param3] = [[value3]]][[param2] = [[]]][[param1] = [[value1], "
170:                                + "[value1]]]], POST parameters = [[[param1] = [[value1]]]]",
171:                        result);
172:            }
173:
174:            /**
175:             * Verify that an error in the query string of <code>setURL()</code>
176:             * raises an exception.
177:             */
178:            public void testSetURLBadQueryString() {
179:                try {
180:                    request.setURL("jakarta.apache.org:80", "/catalog",
181:                            "/garden", "/implements/", "badquerystring");
182:                    fail("Failed to recognize invalid query string");
183:                } catch (RuntimeException e) {
184:                    assertEquals(
185:                            "Bad QueryString [badquerystring] NameValue pair: "
186:                                    + "[badquerystring]", e.getMessage());
187:                }
188:            }
189:
190:            /**
191:             * Verify that we can retrieve several POST parameters.
192:             */
193:            public void testGetPostParametersSeveral() {
194:                request
195:                        .addParameter("param1", "value1",
196:                                WebRequest.POST_METHOD);
197:                request
198:                        .addParameter("param2", "value2",
199:                                WebRequest.POST_METHOD);
200:                request
201:                        .addParameter("param3", "value3",
202:                                WebRequest.POST_METHOD);
203:
204:                Enumeration keys = request.getParameterNamesPost();
205:                while (keys.hasMoreElements()) {
206:                    String key = (String) keys.nextElement();
207:                    String[] values = request.getParameterValuesPost(key);
208:
209:                    assertEquals(1, values.length);
210:
211:                    if (!values[0].equals("value1")
212:                            && !values[0].equals("value2")
213:                            && !values[0].equals("value3")) {
214:                        fail("Return value was [" + values[0]
215:                                + "] but should have "
216:                                + "been one of [value1], [value2] or [value3]");
217:                    }
218:                }
219:            }
220:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.