[Httpunit-commit] CVS: httpunit/test/com/meterware/servletunit HttpServletRequestTest.java,1.11,1.12
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2003-02-06 01:33:16
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/servletunit
In directory sc8-pr-cvs1:/tmp/cvs-serv20202/test/com/meterware/servletunit
Modified Files:
HttpServletRequestTest.java HttpServletResponseTest.java
NavigationTest.java
Log Message:
ServletUnit bug fixes
Index: HttpServletRequestTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/HttpServletRequestTest.java,v
retrieving revision 1.11
retrieving revision 1.12
diff -u -r1.11 -r1.12
--- HttpServletRequestTest.java 4 Feb 2003 19:17:33 -0000 1.11
+++ HttpServletRequestTest.java 6 Feb 2003 01:33:11 -0000 1.12
@@ -246,6 +246,36 @@
}
+ /**
+ * Verifies that a request for a session when the current one is invalid will result in a new session.
+ * @throws Exception
+ */
+ public void testSessionInvalidation() throws Exception {
+ WebRequest wr = new GetMethodWebRequest( "http://localhost/simple" );
+ ServletUnitContext context = new ServletUnitContext();
+
+ 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 );
+ String originalID = session.getId();
+ session.setAttribute( "Initial", new Integer(1) );
+
+ request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, context, new Hashtable(), NO_MESSAGE_BODY );
+ request.addCookie( new Cookie( ServletUnitHttpSession.SESSION_COOKIE_NAME, originalID ) );
+ session = request.getSession();
+ assertEquals( "Retrieved session ID", originalID, session.getId() );
+ assertEquals( "Attribute", new Integer(1), session.getAttribute( "Initial" ) );
+
+ session.invalidate();
+ request = new ServletUnitHttpRequest( NULL_SERVLET_REQUEST, wr, context, new Hashtable(), NO_MESSAGE_BODY );
+ request.addCookie( new Cookie( ServletUnitHttpSession.SESSION_COOKIE_NAME, originalID ) );
+ session = request.getSession();
+ assertNull( "Attribute should not exist", session.getAttribute( "Initial" ) );
+ assertFalse( "New session not created", originalID.equals( session.getId() ) );
+ }
+
+
public void testGetRequestURI() throws Exception {
ServletUnitContext context = new ServletUnitContext();
WebRequest wr = new GetMethodWebRequest( "http://localhost/simple" );
Index: HttpServletResponseTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/HttpServletResponseTest.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- HttpServletResponseTest.java 3 Nov 2002 18:18:20 -0000 1.6
+++ HttpServletResponseTest.java 6 Feb 2003 01:33:11 -0000 1.7
@@ -30,7 +30,6 @@
import javax.servlet.http.*;
import junit.framework.Test;
-import junit.framework.TestCase;
import junit.framework.TestSuite;
import com.meterware.httpunit.*;
@@ -127,6 +126,15 @@
fail( "Should have thrown IllegalStateException" );
} catch (IllegalStateException e) {
}
+ }
+
+
+ public void testUpdateAfterFlushBuffer() throws Exception {
+ ServletUnitHttpResponse servletResponse = new ServletUnitHttpResponse();
+ servletResponse.getWriter();
+ assertFalse( "Should not be committed yet", servletResponse.isCommitted() );
+ servletResponse.flushBuffer();
+ assertTrue( "Should be committed now", servletResponse.isCommitted() );
}
Index: NavigationTest.java
===================================================================
RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/NavigationTest.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- NavigationTest.java 22 Jan 2002 15:25:16 -0000 1.3
+++ NavigationTest.java 6 Feb 2003 01:33:11 -0000 1.4
@@ -2,7 +2,7 @@
/********************************************************************************************************************
* $Id$
*
-* Copyright (c) 2000-2001, Russell Gold
+* Copyright (c) 2000-2003, Russell Gold
*
* Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated
* documentation files (the "Software"), to deal in the Software without restriction, including without limitation
@@ -20,7 +20,6 @@
*
*******************************************************************************************************************/
import java.io.*;
-import java.net.HttpURLConnection;
import javax.servlet.ServletException;
import javax.servlet.http.*;
@@ -64,12 +63,14 @@
public void testForward() throws Exception {
- ServletRunner sr = new ServletRunner();
- sr.registerServlet( "target", TargetServlet.class.getName() );
- sr.registerServlet( "origin", FowarderServlet.class.getName() );
+ WebXMLString wxs = new WebXMLString();
+ wxs.addServlet( "/target", TargetServlet.class );
+ wxs.addServlet( "/origin", FowarderServlet.class );
+
+ ServletRunner sr = new ServletRunner( wxs.asInputStream(), "/context" );
WebClient wc = sr.newClient();
- WebResponse response = wc.getResponse( "http://localhost/origin" );
+ WebResponse response = wc.getResponse( "http://localhost/context/origin" );
assertNotNull( "No response received", response );
assertEquals( "requested resource", TargetServlet.RESPONSE_TEXT, response.getText() );
assertEquals( "Returned cookie count", 0, response.getNewCookieNames().length );
|