Source Code Cross Referenced for TestHttpRequest.java in  » Testing » jakarta-cactus » org » apache » cactus » sample » servlet » unit » 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.sample.servlet.unit 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* 
002:         * ========================================================================
003:         * 
004:         * Copyright 2001-2003 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.sample.servlet.unit;
021:
022:        import java.io.BufferedReader;
023:        import java.io.ByteArrayInputStream;
024:        import java.io.ByteArrayOutputStream;
025:        import java.io.File;
026:        import java.io.InputStream;
027:        import java.io.ObjectInputStream;
028:        import java.io.ObjectOutputStream;
029:
030:        import org.apache.cactus.ServletTestCase;
031:        import org.apache.cactus.WebRequest;
032:
033:        /**
034:         * Tests that exercise the HTTP request.
035:         *
036:         * @version $Id: TestHttpRequest.java 239170 2005-05-06 12:22:24Z vmassol $
037:         */
038:        public class TestHttpRequest extends ServletTestCase {
039:            /**
040:             * Verify that <code>HttpServletRequestWrapper.getPathTranslated()</code>
041:             * takes into account the simulated URL (if any).
042:             *
043:             * @param theRequest the request object that serves to initialize the
044:             *                   HTTP connection to the server redirector.
045:             */
046:            public void beginGetPathTranslated(WebRequest theRequest) {
047:                theRequest.setURL("jakarta.apache.org", "/mywebapp",
048:                        "/myservlet", "/test1/test2", "PARAM1=value1");
049:            }
050:
051:            /**
052:             * Verify that <code>HttpServletRequestWrapper.getPathTranslated()</code>
053:             * takes into account the simulated URL (if any) or null in situations
054:             * where the servlet container cannot determine a valid file path for
055:             * these methods, such as when the web application is executed from an
056:             * archive, on a remote file system not accessible locally, or in a
057:             * database (see section SRV.4.5 of the Servlet 2.3 spec).
058:             */
059:            public void testGetPathTranslated() {
060:                String nativePathInfo = File.separator + "test1"
061:                        + File.separator + "test2";
062:
063:                String pathTranslated = request.getPathTranslated();
064:
065:                // Should be null if getRealPath("/") is null
066:                if (request.getRealPath("/") == null) {
067:                    assertNull("Should have been null", pathTranslated);
068:                } else {
069:                    assertNotNull("Should not be null", pathTranslated);
070:                    assertTrue("Should end with [" + nativePathInfo
071:                            + "] but got [" + pathTranslated + "] instead",
072:                            pathTranslated.endsWith(nativePathInfo));
073:                }
074:            }
075:
076:            //-------------------------------------------------------------------------
077:
078:            /**
079:             * Verify that we can send arbitrary data in the request body and read the
080:             * data back on the server side using a Reader.
081:             *
082:             * @param theRequest the request object that serves to initialize the
083:             *                   HTTP connection to the server redirector.
084:             */
085:            public void beginSendUserDataAndReadWithReader(WebRequest theRequest) {
086:                ByteArrayInputStream bais = new ByteArrayInputStream(
087:                        "<data>some data to send in the body</data>".getBytes());
088:
089:                theRequest.setUserData(bais);
090:                theRequest.setContentType("text/xml");
091:            }
092:
093:            /**
094:             * Verify that we can send arbitrary data in the request body and read the
095:             * data back on the server side using a Reader.
096:             * 
097:             * @exception Exception on test failure
098:             */
099:            public void testSendUserDataAndReadWithReader() throws Exception {
100:                String buffer;
101:                StringBuffer body = new StringBuffer();
102:
103:                BufferedReader reader = request.getReader();
104:
105:                while ((buffer = reader.readLine()) != null) {
106:                    body.append(buffer);
107:                }
108:
109:                assertEquals("<data>some data to send in the body</data>", body
110:                        .toString());
111:                assertEquals("text/xml", request.getContentType());
112:            }
113:
114:            //-------------------------------------------------------------------------
115:
116:            /**
117:             * Verify that we can send arbitrary data in the request body and read the
118:             * data back on the server side using an ObjectInputStream.
119:             *
120:             * @param theRequest the request object that serves to initialize the
121:             *                   HTTP connection to the server redirector.
122:             * @exception Exception on test failure
123:             */
124:            public void beginSendUserDataAndReadWithObjectInputStream(
125:                    WebRequest theRequest) throws Exception {
126:                ByteArrayOutputStream baos = new ByteArrayOutputStream();
127:                ObjectOutputStream oos = new ObjectOutputStream(baos);
128:                oos.writeObject("Test with a String object");
129:                oos.flush();
130:
131:                theRequest.setUserData(new ByteArrayInputStream(baos
132:                        .toByteArray()));
133:                theRequest.setContentType("application/octet-stream");
134:            }
135:
136:            /**
137:             * Verify that we can send arbitrary data in the request body and read the
138:             * data back on the server side using an ObjectInputStream.
139:             * 
140:             * @exception Exception on test failure
141:             */
142:            public void testSendUserDataAndReadWithObjectInputStream()
143:                    throws Exception {
144:                InputStream in = request.getInputStream();
145:                ObjectInputStream ois = new ObjectInputStream(in);
146:                String data = (String) ois.readObject();
147:                assertNotNull(data);
148:                assertEquals("Test with a String object", data);
149:            }
150:
151:            //-------------------------------------------------------------------------
152:
153:            /**
154:             * Verify that we can simulate the client remote IP address and the client
155:             * remote host name.
156:             */
157:            public void testRemoteClientCheck() {
158:                request.setRemoteIPAddress("192.168.0.1");
159:                request.setRemoteHostName("atlantis");
160:                request.setRemoteUser("george");
161:
162:                assertEquals("192.168.0.1", request.getRemoteAddr());
163:                assertEquals("atlantis", request.getRemoteHost());
164:                assertEquals("george", request.getRemoteUser());
165:            }
166:
167:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.