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 org.apache.cactus.ServletTestCase;
023: import org.apache.cactus.WebRequest;
024:
025: /**
026: * Test the {@link WebRequest#setURL} method.
027: *
028: * @version $Id: TestSetURL.java 238816 2004-02-29 16:36:46Z vmassol $
029: */
030: public class TestSetURL extends ServletTestCase {
031: /**
032: * Verify that we can simulate the basic parts of the URL : server name,
033: * default server port of 80, root servlet context, URI.
034: *
035: * @param theRequest the request object that serves to initialize the
036: * HTTP connection to the server redirector.
037: */
038: public void beginSimulatedURLBasics(WebRequest theRequest) {
039: theRequest.setURL("jakarta.apache.org", "", "/test/test.jsp",
040: null, null);
041: }
042:
043: /**
044: * Verify that we can simulate the basic parts of the URL : server name,
045: * default server port of 80, no servlet context, servlet path.
046: */
047: public void testSimulatedURLBasics() {
048: assertEquals("/test/test.jsp", request.getRequestURI());
049: assertEquals("jakarta.apache.org", request.getServerName());
050: assertEquals(80, request.getServerPort());
051: assertEquals("", request.getContextPath());
052: }
053:
054: //-------------------------------------------------------------------------
055:
056: /**
057: * Verify that we can simulate different parts of the URL.
058: *
059: * @param theRequest the request object that serves to initialize the
060: * HTTP connection to the server redirector.
061: */
062: public void beginSimulatedURL1(WebRequest theRequest) {
063: theRequest.setURL("jakarta.apache.org", "/mywebapp",
064: "/test/test.jsp", null, null);
065: }
066:
067: /**
068: * Verify that we can simulate different parts of the URL.
069: */
070: public void testSimulatedURL1() {
071: assertEquals("/mywebapp/test/test.jsp", request.getRequestURI());
072: assertEquals("jakarta.apache.org", request.getServerName());
073: assertEquals(80, request.getServerPort());
074: assertEquals("/mywebapp", request.getContextPath());
075: }
076:
077: //-------------------------------------------------------------------------
078:
079: /**
080: * Verify that we can simulate different parts of the URL.
081: *
082: * @param theRequest the request object that serves to initialize the
083: * HTTP connection to the server redirector.
084: */
085: public void beginSimulatedURL2(WebRequest theRequest) {
086: theRequest.setURL("jakarta.apache.org", "/catalog", "/lawn",
087: "/index.html", null);
088: }
089:
090: /**
091: * Verify that we can simulate different parts of the URL.
092: */
093: public void testSimulatedURL2() {
094: assertEquals("jakarta.apache.org", request.getServerName());
095: assertEquals("/catalog/lawn/index.html", request
096: .getRequestURI());
097: assertEquals(80, request.getServerPort());
098: assertEquals("/catalog", request.getContextPath());
099: assertEquals("/lawn", request.getServletPath());
100: assertEquals("/index.html", request.getPathInfo());
101: }
102:
103: //-------------------------------------------------------------------------
104:
105: /**
106: * Verify that we can simulate different parts of the URL.
107: *
108: * @param theRequest the request object that serves to initialize the
109: * HTTP connection to the server redirector.
110: */
111: public void beginSimulatedURL3(WebRequest theRequest) {
112: theRequest.setURL("jakarta.apache.org", "/catalog", "/garden",
113: "/implements/", null);
114: }
115:
116: /**
117: * Verify that we can simulate different parts of the URL.
118: */
119: public void testSimulatedURL3() {
120: assertEquals("jakarta.apache.org", request.getServerName());
121: assertEquals("/catalog/garden/implements/", request
122: .getRequestURI());
123: assertEquals(80, request.getServerPort());
124: assertEquals("/catalog", request.getContextPath());
125: assertEquals("/garden", request.getServletPath());
126: assertEquals("/implements/", request.getPathInfo());
127: }
128:
129: //-------------------------------------------------------------------------
130:
131: /**
132: * Verify that we can simulate different parts of the URL.
133: *
134: * @param theRequest the request object that serves to initialize the
135: * HTTP connection to the server redirector.
136: */
137: public void beginSimulatedURL4(WebRequest theRequest) {
138: theRequest.setURL("jakarta.apache.org", "/catalog",
139: "/help/feedback.jsp", null, null);
140: }
141:
142: /**
143: * Verify that we can simulate different parts of the URL.
144: */
145: public void testSimulatedURL4() {
146: assertEquals("jakarta.apache.org", request.getServerName());
147: assertEquals("/catalog/help/feedback.jsp", request
148: .getRequestURI());
149: assertEquals(80, request.getServerPort());
150: assertEquals("/catalog", request.getContextPath());
151: assertEquals("/help/feedback.jsp", request.getServletPath());
152: }
153:
154: //-------------------------------------------------------------------------
155:
156: /**
157: * Verify that we can simulate different parts of the URL. Also verify
158: * that HTTP parameters put in the simulation URL will be
159: * available on the server side as real HTTP parameters.
160: *
161: * @param theRequest the request object that serves to initialize the
162: * HTTP connection to the server redirector.
163: */
164: public void beginSimulatedURL5(WebRequest theRequest) {
165: theRequest.setURL("jakarta.apache.org", "/catalog",
166: "/help/feedback.jsp", null,
167: "PARAM1=param1&PARAM2=&PARAM3=param3");
168: }
169:
170: /**
171: * Verify that we can simulate different parts of the URL. Also verify
172: * that HTTP parameters put in the simulation URL will be
173: * available on the server side as real HTTP parameters.
174: */
175: public void testSimulatedURL5() {
176: assertEquals("jakarta.apache.org", request.getServerName());
177: assertEquals("/catalog/help/feedback.jsp", request
178: .getRequestURI());
179: assertEquals(80, request.getServerPort());
180: assertEquals("/catalog", request.getContextPath());
181: assertEquals("/help/feedback.jsp", request.getServletPath());
182: assertEquals("PARAM1=param1&PARAM2=&PARAM3=param3", request
183: .getQueryString());
184: assertEquals(request.getParameter("PARAM1"), "param1");
185: assertEquals(request.getParameter("PARAM2"), "");
186: assertEquals(request.getParameter("PARAM3"), "param3");
187: }
188:
189: //-------------------------------------------------------------------------
190:
191: /**
192: * Verify values used by the framework when all values defined in
193: * <code>setURL()</code> are null.
194: *
195: * @param theRequest the request object that serves to initialize the
196: * HTTP connection to the server redirector.
197: */
198: public void beginSimulatedURLNullValues(WebRequest theRequest) {
199: theRequest.setURL(null, null, null, null, null);
200: }
201:
202: /**
203: * Verify values used by the framework when all values defined in
204: * <code>setURL()</code> are null.
205: */
206: public void testSimulatedURLNullValues() {
207: assertNotNull(request.getServerName());
208: assertTrue(request.getServerPort() > 0);
209: assertNotNull(request.getContextPath());
210: assertNotNull(request.getServletPath());
211: assertNull(request.getPathInfo());
212: assertNull(request.getQueryString());
213: }
214: }
|