vmassol 2003/06/07 04:26:05
Modified: samples/servlet/src/test-cactus/share/org/apache/cactus/sample/unit
TestSetURL.java
framework/src/test/share/org/apache/cactus
TestServletURL.java
framework/src/java/share/org/apache/cactus ServletURL.java
framework/src/java/share/org/apache/cactus/server
AbstractHttpServletRequestWrapper.java
Log:
Verify that the path info used in the simulation URL has the correct format.
Revision Changes Path
1.7 +8 -19
jakarta-cactus/samples/servlet/src/test-cactus/share/org/apache/cactus/sample/unit/TestSetURL.java
Index: TestSetURL.java
===================================================================
RCS file:
/home/cvs/jakarta-cactus/samples/servlet/src/test-cactus/share/org/apache/cactus/sample/unit/TestSetURL.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- TestSetURL.java 7 Jun 2003 10:08:04 -0000 1.6
+++ TestSetURL.java 7 Jun 2003 11:26:05 -0000 1.7
@@ -87,16 +87,9 @@
*/
public void testSimulatedURLBasics()
{
- // Verify URI
assertEquals("/test/test.jsp", request.getRequestURI());
-
- // Verify server name
assertEquals("jakarta.apache.org", request.getServerName());
-
- // Returns 80 when no port is specified
assertEquals(80, request.getServerPort());
-
- // Return "" when no context path is defined
assertEquals("", request.getContextPath());
}
@@ -203,7 +196,6 @@
assertEquals(80, request.getServerPort());
assertEquals("/catalog", request.getContextPath());
assertEquals("/help/feedback.jsp", request.getServletPath());
- assertNull(request.getPathInfo());
}
//-------------------------------------------------------------------------
@@ -234,7 +226,6 @@
assertEquals(80, request.getServerPort());
assertEquals("/catalog", request.getContextPath());
assertEquals("/help/feedback.jsp", request.getServletPath());
- assertNull(request.getPathInfo());
assertEquals("PARAM1=param1&PARAM2=&PARAM3=param3",
request.getQueryString());
assertEquals(request.getParameter("PARAM1"), "param1");
@@ -245,27 +236,25 @@
//-------------------------------------------------------------------------
/**
- * Verify that if the context path and the servlet paths are null in
- * <code>setURL()</code> the real values coming from the Servlet
- * Redirector will be used instead.
+ * Verify values used by the framework when all values defined in
+ * <code>setURL()</code> are null.
*
* @param theRequest the request object that serves to initialize the
* HTTP connection to the server redirector.
*/
- public void beginSimulatedURLNullContextAndServletPaths(
- WebRequest theRequest)
+ public void beginSimulatedURLNullValues(WebRequest theRequest)
{
theRequest.setURL(null, null, null, null, null);
}
/**
- * Verify that if the context path and the servlet paths are null in
- * <code>setURL()</code> the real values coming from the Servlet
- * Redirector will be used instead.
+ * Verify values used by the framework when all values defined in
+ * <code>setURL()</code> are null.
*/
- public void testSimulatedURLNullContextAndServletPaths()
+ public void testSimulatedURLNullValues()
{
assertNotNull(request.getContextPath());
assertNotNull(request.getServletPath());
+ assertEquals("", request.getPathInfo());
}
}
1.12 +37 -1
jakarta-cactus/framework/src/test/share/org/apache/cactus/TestServletURL.java
Index: TestServletURL.java
===================================================================
RCS file:
/home/cvs/jakarta-cactus/framework/src/test/share/org/apache/cactus/TestServletURL.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- TestServletURL.java 7 Jun 2003 10:08:04 -0000 1.11
+++ TestServletURL.java 7 Jun 2003 11:26:05 -0000 1.12
@@ -159,6 +159,42 @@
}
/**
+ * Verify that if the path info is not null it must start with
+ * a "/" character.
+ */
+ public void testSetPathInfoFirstCharacterNotForwardSlash()
+ {
+ try
+ {
+ new ServletURL(null, null, null, "invalidpathinfo", null);
+ fail("The path info must start with a \"/\" character");
+ }
+ catch (IllegalArgumentException expected)
+ {
+ assertEquals("The Path Info must start with a \"/\" character.",
+ expected.getMessage());
+ }
+ }
+
+ /**
+ * Verify that the path info cannot be an empty string.
+ */
+ public void testSetPathInfoEmptyNotAllowed()
+ {
+ try
+ {
+ new ServletURL(null, null, null, "", null);
+ fail("The path info must not be an empty string");
+ }
+ catch (IllegalArgumentException expected)
+ {
+ assertEquals("The Path Info must not be an empty string. Use "
+ + "null if you don't want to have a path info.",
+ expected.getMessage());
+ }
+ }
+
+ /**
* Verify that the <code>getHost()</code> method is returning the correct
* host when a port is specified and that the <code>getPort()</code>
* method returns the specified port.
1.14 +24 -6
jakarta-cactus/framework/src/java/share/org/apache/cactus/ServletURL.java
Index: ServletURL.java
===================================================================
RCS file:
/home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/ServletURL.java,v
retrieving revision 1.13
retrieving revision 1.14
diff -u -r1.13 -r1.14
--- ServletURL.java 7 Jun 2003 10:08:04 -0000 1.13
+++ ServletURL.java 7 Jun 2003 11:26:05 -0000 1.14
@@ -235,7 +235,8 @@
* @param thePathInfo the path info in the URL to simulate, i.e. this is
* the name that will be returned by the
* <code>HttpServletRequest.getPathInfo()</code>. Can
- * be null. Format : "/" + name.
+ * be null. If null, then no extra path will be set.
+ * Format : "/" + name.
* @param theQueryString the Query string in the URL to simulate, i.e. this
* is the string that will be returned by the
* <code>HttpServletResquest.getQueryString()</code>.
@@ -278,7 +279,8 @@
* @param thePathInfo the path info in the URL to simulate, i.e. this is
* the name that will be returned by the
* <code>HttpServletRequest.getPathInfo()</code>. Can
- * be null. Format : "/" + name.
+ * be null. If null, then no extra path will be set.
+ * Format : "/" + name.
* @param theQueryString the Query string in the URL to simulate, i.e. this
* is the string that will be returned by the
* <code>HttpServletResquest.getQueryString()</code>.
@@ -472,7 +474,7 @@
/**
* Sets the servlet path in the URL to simulate, ie this is the name that
* will be returned by the <code>HttpServletRequest.getServletPath()</code>.
- * If not set, the servlet path from the Servlet Redirector will be
+ * If null then the servlet path from the Servlet Redirector will be
* returned. Format : "/" + name or an empty string.
*
* @param theServletPath the servlet path to simulate
@@ -501,14 +503,30 @@
/**
* Sets the path info in the URL to simulate, ie this is the name that will
- * be returned by the <code>HttpServletRequest.getPathInfo()</code>. If not
- * set, the path info from the Servlet Redirector will be returned.
+ * be returned by the <code>HttpServletRequest.getPathInfo()</code>.
+ * If null then no path info will be set (and the Path Info from the
+ * Servlet Redirector will <b>not</b> be used).
* Format : "/" + name.
*
* @param thePathInfo the path info to simulate
*/
public void setPathInfo(String thePathInfo)
{
+ if ((thePathInfo != null) && (thePathInfo.length() == 0))
+ {
+ throw new IllegalArgumentException("The Path Info must"
+ + " not be an empty string. Use null if you don't"
+ + " want to have a path info.");
+ }
+ else if (thePathInfo != null)
+ {
+ if (!thePathInfo.startsWith("/"))
+ {
+ throw new IllegalArgumentException("The Path Info must"
+ + " start with a \"/\" character.");
+ }
+ }
+
this.pathInfo = thePathInfo;
}
1.15 +12 -3
jakarta-cactus/framework/src/java/share/org/apache/cactus/server/AbstractHttpServletRequestWrapper.java
Index: AbstractHttpServletRequestWrapper.java
===================================================================
RCS file:
/home/cvs/jakarta-cactus/framework/src/java/share/org/apache/cactus/server/AbstractHttpServletRequestWrapper.java,v
retrieving revision 1.14
retrieving revision 1.15
diff -u -r1.14 -r1.15
--- AbstractHttpServletRequestWrapper.java 7 Jun 2003 10:08:04 -0000 1.14
+++ AbstractHttpServletRequestWrapper.java 7 Jun 2003 11:26:05 -0000 1.15
@@ -185,7 +185,9 @@
/**
* @return the path info from the simulated URL or the real path info
- * if a simulation URL has not been defined.
+ * if a simulation URL has not been defined. If the path info
+ * value defined in the simulated URL is null, return an empty
+ * string.
*/
public String getPathInfo()
{
@@ -193,7 +195,14 @@
if (this.url != null)
{
- result = this.url.getPathInfo();
+ if (this.url.getPathInfo() == null)
+ {
+ result = "";
+ }
+ else
+ {
+ result = this.url.getPathInfo();
+ }
LOGGER.debug("Using simulated PathInfo : [" + result + "]");
}
else
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]