vmassol 01/08/30 05:57:31
Modified: cactus/src/sample/share/org/apache/commons/cactus/sample/unit
TestServletTestCase2.java
Log:
add test for testing server code that returns HTTP status code > 400
Revision Changes Path
1.11 +37 -1
jakarta-commons/cactus/src/sample/share/org/apache/commons/cactus/sample/unit/TestServletTestCase2.java
Index: TestServletTestCase2.java
===================================================================
RCS file:
/home/cvs/jakarta-commons/cactus/src/sample/share/org/apache/commons/cactus/sample/unit/TestServletTestCase2.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- TestServletTestCase2.java 2001/08/29 13:25:23 1.10
+++ TestServletTestCase2.java 2001/08/30 12:57:31 1.11
@@ -77,7 +77,7 @@
*
* @author <a href="mailto:[EMAIL PROTECTED]">Vincent Massol</a>
*
- * @version $Id: TestServletTestCase2.java,v 1.10 2001/08/29 13:25:23 vmassol Exp $
+ * @version $Id: TestServletTestCase2.java,v 1.11 2001/08/30 12:57:31 vmassol Exp $
*/
public class TestServletTestCase2 extends ServletTestCase
{
@@ -480,6 +480,42 @@
assertEquals("Found more than one log message", logs.size(), 1);
assert("Cannot find expected log message : [" + message + "]",
logs.contains("some test log"));
+ }
+
+ //-------------------------------------------------------------------------
+
+ /**
+ * Verify that we can assert HTTP status code when it is an error
+ * status code (> 400).
+ *
+ * Note: HttpURLConnection will return a FileNotFoundException if the
+ * status code is > 400 and the request does not end with a "/" ! In
+ * order to prevent, this ensure the Servlet Redirector URL in
+ * cactus.properties does end with a "/" and modify the servlet mapping
+ * in web.xml to include the trailing slash.
+ */
+ public void testStatusCode()
+ {
+ response.setStatus(HttpServletResponse.SC_UNAUTHORIZED);
+ }
+
+ /**
+ * Verify that we can assert HTTP status code when it is an error
+ * status code (> 400).
+ *
+ * Note: HttpURLConnection will return a FileNotFoundException if the
+ * status code is > 400 and the request does not end with a "/" ! In
+ * order to prevent, this ensure the Servlet Redirector URL in
+ * cactus.properties does end with a "/" and modify the servlet mapping
+ * in web.xml to include the trailing slash.
+ *
+ * @param theResponse the response from the server side.
+ */
+ public void endStatusCode(WebResponse theResponse)
+ throws IOException
+ {
+ assertEquals(HttpServletResponse.SC_UNAUTHORIZED,
+ theResponse.getConnection().getResponseCode());
}
}