[Httpunit-commit] CVS: httpunit/test/com/meterware/servletunit HttpServletRequestTest.java,1.6,1.7 W
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2002-06-19 13:47:25
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/servletunit
In directory usw-pr-cvs1:/tmp/cvs-serv14187/test/com/meterware/servletunit
Modified Files:
HttpServletRequestTest.java WebXMLTest.java
Log Message:
implemented getServerPath and getPathInfo
Index: HttpServletRequestTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/HttpServletRequestTest.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- HttpServletRequestTest.java 20 May 2002 16:00:13 -0000 1.6
+++ HttpServletRequestTest.java 19 Jun 2002 13:47:20 -0000 1.7
@@ -25,6 +25,8 @@
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
+import javax.servlet.Servlet;
+import javax.servlet.ServletException;
import com.meterware.httpunit.GetMethodWebRequest;
import com.meterware.httpunit.WebRequest;
@@ -54,7 +56,7 @@
public void testGetDefaultProperties() throws Exception {
WebRequest wr = new GetMethodWebRequest( "http://localhost/simple" );
- HttpServletRequest request = new ServletUnitHttpRequest( wr, new ServletUnitContext(), new Hashtable(), NO_MESSAGE_BODY );
+ HttpServletRequest request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, new ServletUnitContext(), new Hashtable(), NO_MESSAGE_BODY );
assertNull( "Authorization incorrectly specified", request.getAuthType() );
assertNull( "Character encoding incorrectly specified", request.getCharacterEncoding() );
assertEquals( "Parameters unexpectedly specified", "", request.getQueryString() );
@@ -66,7 +68,7 @@
WebRequest wr = new GetMethodWebRequest( "http://localhost/simple" );
wr.setParameter( "age", "12" );
wr.setParameter( "color", new String[] { "red", "blue" } );
- HttpServletRequest request = new ServletUnitHttpRequest( wr, new ServletUnitContext(), new Hashtable(), NO_MESSAGE_BODY );
+ HttpServletRequest request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, new ServletUnitContext(), new Hashtable(), NO_MESSAGE_BODY );
assertEquals( "age parameter", "12", request.getParameter( "age" ) );
assertNull( "unset parameter should be null", request.getParameter( "unset" ) );
@@ -77,7 +79,7 @@
WebRequest wr = new GetMethodWebRequest( "http://localhost/simple" );
wr.setParameter( "age", "12" );
wr.setParameter( "color", new String[] { "red", "blue" } );
- HttpServletRequest request = new ServletUnitHttpRequest( wr, new ServletUnitContext(), new Hashtable(), NO_MESSAGE_BODY );
+ HttpServletRequest request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, new ServletUnitContext(), new Hashtable(), NO_MESSAGE_BODY );
assertMatchingSet( "age parameter", new String[] { "12" }, request.getParameterValues( "age" ) );
assertMatchingSet( "color parameter", new String[] { "red", "blue" }, request.getParameterValues( "color" ) );
@@ -89,7 +91,7 @@
WebRequest wr = new GetMethodWebRequest( "http://localhost/simple" );
wr.setParameter( "age", "12" );
wr.setParameter( "color", new String[] { "red", "blue" } );
- HttpServletRequest request = new ServletUnitHttpRequest( wr, new ServletUnitContext(), new Hashtable(), NO_MESSAGE_BODY );
+ HttpServletRequest request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, new ServletUnitContext(), new Hashtable(), NO_MESSAGE_BODY );
assertEquals( "query string", "color=red&color=blue&age=12", request.getQueryString() );
}
@@ -97,7 +99,7 @@
public void testInlineSingleValuedParameter() throws Exception {
WebRequest wr = new GetMethodWebRequest( "http://localhost/simple?color=red&color=blue&age=12" );
- HttpServletRequest request = new ServletUnitHttpRequest( wr, new ServletUnitContext(), new Hashtable(), NO_MESSAGE_BODY );
+ HttpServletRequest request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, new ServletUnitContext(), new Hashtable(), NO_MESSAGE_BODY );
assertEquals( "age parameter", "12", request.getParameter( "age" ) );
assertNull( "unset parameter should be null", request.getParameter( "unset" ) );
@@ -106,7 +108,7 @@
public void testInlineMultiValuedParameter() throws Exception {
WebRequest wr = new GetMethodWebRequest( "http://localhost/simple?color=red&color=blue&age=12" );
- HttpServletRequest request = new ServletUnitHttpRequest( wr, new ServletUnitContext(), new Hashtable(), NO_MESSAGE_BODY );
+ HttpServletRequest request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, new ServletUnitContext(), new Hashtable(), NO_MESSAGE_BODY );
assertMatchingSet( "age parameter", new String[] { "12" }, request.getParameterValues( "age" ) );
assertMatchingSet( "color parameter", new String[] { "red", "blue" }, request.getParameterValues( "color" ) );
@@ -116,7 +118,7 @@
public void notestInlineQueryString() throws Exception {
WebRequest wr = new GetMethodWebRequest( "http://localhost/simple?color=red&color=blue&age=12" );
- HttpServletRequest request = new ServletUnitHttpRequest( wr, new ServletUnitContext(), new Hashtable(), NO_MESSAGE_BODY );
+ HttpServletRequest request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, new ServletUnitContext(), new Hashtable(), NO_MESSAGE_BODY );
assertEquals( "query string", "color=red&color=blue&age=12", request.getQueryString() );
}
@@ -124,7 +126,7 @@
public void testDefaultAttributes() throws Exception {
WebRequest wr = new GetMethodWebRequest( "http://localhost/simple" );
- HttpServletRequest request = new ServletUnitHttpRequest( wr, new ServletUnitContext(), new Hashtable(), NO_MESSAGE_BODY );
+ HttpServletRequest request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, new ServletUnitContext(), new Hashtable(), NO_MESSAGE_BODY );
assertNull( "attribute should not be defined yet", request.getAttribute( "unset" ) );
assertTrue( "attribute enumeration should be empty", !request.getAttributeNames().hasMoreElements() );
@@ -133,7 +135,7 @@
public void testNonDefaultAttributes() throws Exception {
WebRequest wr = new GetMethodWebRequest( "http://localhost/simple" );
- HttpServletRequest request = new ServletUnitHttpRequest( wr, new ServletUnitContext(), new Hashtable(), NO_MESSAGE_BODY );
+ HttpServletRequest request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, new ServletUnitContext(), new Hashtable(), NO_MESSAGE_BODY );
Object value = new Integer(1);
request.setAttribute( "one", value );
@@ -149,7 +151,7 @@
public void testDuplicateAttributes() throws Exception {
WebRequest wr = new GetMethodWebRequest( "http://localhost/simple" );
- HttpServletRequest request = new ServletUnitHttpRequest( wr, new ServletUnitContext(), new Hashtable(), NO_MESSAGE_BODY );
+ HttpServletRequest request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, new ServletUnitContext(), new Hashtable(), NO_MESSAGE_BODY );
Object value = new Integer(1);
request.setAttribute( "one", value );
@@ -164,7 +166,7 @@
public void testSessionCreation() throws Exception {
WebRequest wr = new GetMethodWebRequest( "http://localhost/simple" );
- HttpServletRequest request = new ServletUnitHttpRequest( wr, new ServletUnitContext(), new Hashtable(), NO_MESSAGE_BODY );
+ HttpServletRequest request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, new ServletUnitContext(), new Hashtable(), NO_MESSAGE_BODY );
HttpSession session = request.getSession( /* create */ false );
assertNull( "Unexpected session found", session );
@@ -177,7 +179,7 @@
public void testDefaultCookies() throws Exception {
WebRequest wr = new GetMethodWebRequest( "http://localhost/simple" );
- HttpServletRequest request = new ServletUnitHttpRequest( wr, new ServletUnitContext(), new Hashtable(), NO_MESSAGE_BODY );
+ HttpServletRequest request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, new ServletUnitContext(), new Hashtable(), NO_MESSAGE_BODY );
Cookie[] cookies = request.getCookies();
assertNull( "Unexpected cookies found", cookies );
}
@@ -185,7 +187,7 @@
public void testSetCookies() throws Exception {
WebRequest wr = new GetMethodWebRequest( "http://localhost/simple" );
- ServletUnitHttpRequest request = new ServletUnitHttpRequest( wr, new ServletUnitContext(), new Hashtable(), NO_MESSAGE_BODY );
+ ServletUnitHttpRequest request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, new ServletUnitContext(), new Hashtable(), NO_MESSAGE_BODY );
request.addCookie( new Cookie( "flavor", "vanilla" ) );
Cookie[] cookies = request.getCookies();
@@ -200,7 +202,7 @@
WebRequest wr = new GetMethodWebRequest( "http://localhost/simple" );
ServletUnitContext context = new ServletUnitContext();
- ServletUnitHttpRequest request = new ServletUnitHttpRequest( wr, context, new Hashtable(), NO_MESSAGE_BODY );
+ ServletUnitHttpRequest request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, context, new Hashtable(), NO_MESSAGE_BODY );
request.addCookie( new Cookie( ServletUnitHttpSession.SESSION_COOKIE_NAME, context.newSession().getId() ) );
HttpSession session = request.getSession( /* create */ false );
@@ -212,16 +214,33 @@
ServletUnitContext context = new ServletUnitContext();
WebRequest wr = new GetMethodWebRequest( "http://localhost/simple" );
- ServletUnitHttpRequest request = new ServletUnitHttpRequest( wr, context, new Hashtable(), NO_MESSAGE_BODY );
+ ServletUnitHttpRequest request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, context, new Hashtable(), NO_MESSAGE_BODY );
assertEquals("/simple", request.getRequestURI());
wr = new GetMethodWebRequest( "http://localhost/simple?foo=bar" );
- request = new ServletUnitHttpRequest( wr, context, new Hashtable(), NO_MESSAGE_BODY);
+ request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, context, new Hashtable(), NO_MESSAGE_BODY );
assertEquals("/simple", request.getRequestURI());
}
private final static byte[] NO_MESSAGE_BODY = new byte[0];
+
+ private final static ServletRequest NULL_SERVLET_REQUEST = new ServletRequest() {
+
+ public Servlet getServlet() throws ServletException {
+ return null;
+ }
+
+
+ public String getServletPath() {
+ return null;
+ }
+
+
+ public String getPathInfo() {
+ return null;
+ }
+ };
}
Index: WebXMLTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/WebXMLTest.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- WebXMLTest.java 21 May 2002 20:43:31 -0000 1.9
+++ WebXMLTest.java 19 Jun 2002 13:47:20 -0000 1.10
@@ -264,8 +264,8 @@
ServletRunner sr = new ServletRunner( toInputStream( wxs.asText() ) );
ServletUnitClient wc = sr.newClient();
- checkMapping( wc, "http://localhost/foo/bar/index.html", Servlet1.class, "/foo/bar", "/index.html" );
- checkMapping( wc, "http://localhost/foo/bar/index.bop", Servlet1.class, "/foo/bar", "/index.bop" );
+ checkMapping( wc, "http://localhost/foo/bar/index.html", Servlet1.class, "/foo/bar", "/index.html" );
+ checkMapping( wc, "http://localhost/foo/bar/index.bop", Servlet1.class, "/foo/bar", "/index.bop" );
checkMapping( wc, "http://localhost/baz", Servlet2.class, "/baz", null );
checkMapping( wc, "http://localhost/baz/index.html", Servlet2.class, "/baz", "/index.html" );
checkMapping( wc, "http://localhost/catalog", Servlet3.class, "/catalog", null );
@@ -283,8 +283,8 @@
private void checkMapping( ServletUnitClient wc, final String url, final Class servletClass, final String expectedPath, final String expectedInfo ) throws IOException, ServletException {
InvocationContext ic = wc.newInvocation( url );
assertTrue( servletClass.isInstance( ic.getServlet() ) );
-// assertEquals( "ServletPath", expectedPath, ic.getRequest().getServletPath() );
-// assertEquals( "ServletInfo", expectedInfo, ic.getRequest().getPathInfo() );
+ assertEquals( "ServletPath for " + url, expectedPath, ic.getRequest().getServletPath() );
+ assertEquals( "ServletInfo for " + url, expectedInfo, ic.getRequest().getPathInfo() );
}
|