Source Code Cross Referenced for TestServletURL.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-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;
021:
022:        import junit.framework.TestCase;
023:
024:        /**
025:         * Unit tests of the <code>ServletURL</code> class.
026:         *
027:         * @version $Id: TestServletURL.java 238991 2004-05-22 11:34:50Z vmassol $
028:         */
029:        public class TestServletURL extends TestCase {
030:            /**
031:             * Verify that if the context path is not empty or null it must start with
032:             * a "/" character.
033:             */
034:            public void testSetContextPathFirstCharacterNotForwardSlash() {
035:                try {
036:                    new ServletURL(null, "invalidcontextpath", null, null, null);
037:                    fail("The context path must start with a \"/\" character");
038:                } catch (IllegalArgumentException expected) {
039:                    assertEquals(
040:                            "The Context Path must start with a \"/\" character.",
041:                            expected.getMessage());
042:                }
043:            }
044:
045:            /**
046:             * Verify that if the context path is not empty or null it must not end 
047:             * with the "/" character. 
048:             */
049:            public void testSetContextPathLastCharacterNotForwardSlash() {
050:                try {
051:                    new ServletURL(null, "/invalidcontextpath/", null, null,
052:                            null);
053:                    fail("The context path must not end with a \"/\" character");
054:                } catch (IllegalArgumentException expected) {
055:                    assertEquals("The Context Path must not end with a \"/\""
056:                            + " character.", expected.getMessage());
057:                }
058:            }
059:
060:            /**
061:             * Verify that the context path can be an empty string.
062:             */
063:            public void testSetContextPathEmptyString() {
064:                ServletURL servletURL = new ServletURL(null, "", null, null,
065:                        null);
066:                assertEquals("", servletURL.getContextPath());
067:            }
068:
069:            /**
070:             * Verify that if the servlet path is not empty or null it must start with
071:             * a "/" character.
072:             */
073:            public void testSetServletPathFirstCharacterNotForwardSlash() {
074:                try {
075:                    new ServletURL(null, null, "invalidservletpath", null, null);
076:                    fail("The servlet path must start with a \"/\" character");
077:                } catch (IllegalArgumentException expected) {
078:                    assertEquals(
079:                            "The Servlet Path must start with a \"/\" character.",
080:                            expected.getMessage());
081:                }
082:            }
083:
084:            /**
085:             * Verify that the servlet path can be an empty string.
086:             */
087:            public void testSetServletPathEmptyString() {
088:                ServletURL servletURL = new ServletURL(null, null, "", null,
089:                        null);
090:                assertEquals("", servletURL.getServletPath());
091:            }
092:
093:            /**
094:             * Verify that if the path info is not null it must start with
095:             * a "/" character.
096:             */
097:            public void testSetPathInfoFirstCharacterNotForwardSlash() {
098:                try {
099:                    new ServletURL(null, null, null, "invalidpathinfo", null);
100:                    fail("The path info must start with a \"/\" character");
101:                } catch (IllegalArgumentException expected) {
102:                    assertEquals(
103:                            "The Path Info must start with a \"/\" character.",
104:                            expected.getMessage());
105:                }
106:            }
107:
108:            /**
109:             * Verify that the path info cannot be an empty string.
110:             */
111:            public void testSetPathInfoEmptyNotAllowed() {
112:                try {
113:                    new ServletURL(null, null, null, "", null);
114:                    fail("The path info must not be an empty string");
115:                } catch (IllegalArgumentException expected) {
116:                    assertEquals(
117:                            "The Path Info must not be an empty string. Use "
118:                                    + "null if you don't want to have a path info.",
119:                            expected.getMessage());
120:                }
121:            }
122:
123:            /**
124:             * Verify that the <code>getHost()</code> method is returning the correct
125:             * host when a port is specified and that the <code>getPort()</code>
126:             * method returns the specified port.
127:             */
128:            public void testGetHostWithPort() {
129:                ServletURL servletURL = new ServletURL(
130:                        "jakarta.apache.org:8080", null, null, null, null);
131:
132:                assertEquals("jakarta.apache.org", servletURL.getHost());
133:                assertEquals(8080, servletURL.getPort());
134:            }
135:
136:            /**
137:             * Verify that <code>getPort()</code> returns -1 when the port is invalid.
138:             */
139:            public void testGetPortInvalidPortNumber() {
140:                ServletURL servletURL = new ServletURL();
141:
142:                servletURL.setServerName("jakarta.apache.org:invalidPort80");
143:
144:                int port = servletURL.getPort();
145:
146:                assertEquals(-1, port);
147:            }
148:
149:            /**
150:             * Verify that an invalid protocol raises an exception.
151:             */
152:            public void testSetProtocolInvalidProtocol() {
153:                ServletURL servletURL = new ServletURL();
154:
155:                try {
156:                    servletURL.setProtocol("invalid protocol");
157:                    fail("Should have raised an invalid protocol error");
158:                } catch (RuntimeException e) {
159:                    assertEquals(
160:                            "Invalid protocol [invalid protocol]. Currently "
161:                                    + "supported protocols are [http] and [https].",
162:                            e.getMessage());
163:                }
164:            }
165:
166:            /**
167:             * Verify that a valid protocol works.
168:             */
169:            public void testSetProtocolOk() {
170:                ServletURL servletURL = new ServletURL();
171:
172:                servletURL.setProtocol(ServletURL.PROTOCOL_HTTP);
173:                assertEquals(ServletURL.PROTOCOL_HTTP, servletURL.getProtocol());
174:
175:                servletURL.setProtocol(ServletURL.PROTOCOL_HTTPS);
176:                assertEquals(ServletURL.PROTOCOL_HTTPS, servletURL
177:                        .getProtocol());
178:            }
179:
180:            /**
181:             * Verify <code>getPath()</code> is ok when all parts are filled.
182:             */
183:            public void testGetPath() {
184:                ServletURL servletURL = new ServletURL();
185:
186:                servletURL.setQueryString("param1=value1");
187:                servletURL.setContextPath("/context");
188:                servletURL.setServletPath("/servletPath");
189:                servletURL.setPathInfo("/pathInfo");
190:
191:                String path = servletURL.getPath();
192:
193:                assertEquals("/context/servletPath/pathInfo", path);
194:            }
195:
196:            /**
197:             * Verify <code>getPath()</code> returns null when no parts are filled.
198:             */
199:            public void testGetPathNull() {
200:                ServletURL servletURL = new ServletURL();
201:
202:                String path = servletURL.getPath();
203:
204:                assertNull(path);
205:            }
206:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.