[Httpunit-commit] CVS: httpunit/test/com/meterware/servletunit JUnitServletTest.java,1.10,1.11 State
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2004-09-09 00:16:55
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/servletunit In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv19281/test/com/meterware/servletunit Modified Files: JUnitServletTest.java StatefulTest.java Log Message: Support HttpSession access from ServletUnit client Index: JUnitServletTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/JUnitServletTest.java,v retrieving revision 1.10 retrieving revision 1.11 diff -u -r1.10 -r1.11 --- JUnitServletTest.java 13 Jun 2004 20:57:28 -0000 1.10 +++ JUnitServletTest.java 9 Sep 2004 00:16:40 -0000 1.11 @@ -31,6 +31,7 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; +import javax.servlet.http.HttpSession; import javax.xml.parsers.DocumentBuilder; import junit.framework.TestCase; @@ -255,5 +256,10 @@ public InvocationContext newInvocation( ServletUnitClient client, FrameSelector targetFrame, WebRequest request, Dictionary clientHeaders, byte[] messageBody ) throws IOException, MalformedURLException { return new InvocationContextImpl( client, _runner, targetFrame, request, clientHeaders, messageBody ); } + + + public HttpSession getSession( String sessionId, boolean create ) { + return null; + } } } Index: StatefulTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/StatefulTest.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- StatefulTest.java 25 Feb 2003 17:17:29 -0000 1.5 +++ StatefulTest.java 9 Sep 2004 00:16:40 -0000 1.6 @@ -2,7 +2,7 @@ /******************************************************************************************************************** * $Id$ * -* Copyright (c) 2000-2003, Russell Gold +* Copyright (c) 2000-2004, 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 @@ -105,6 +105,42 @@ } + public void testSessionPreloading() throws Exception { + final String resourceName1 = "something/interesting/start"; + final String resourceName2 = "something/continue"; + + ServletRunner sr = new ServletRunner(); + sr.registerServlet( resourceName1, StatefulServlet.class.getName() ); + sr.registerServlet( resourceName2, StatefulServlet.class.getName() ); + ServletUnitClient wc = sr.newClient(); + + wc.getSession( true ).setAttribute( "color", "green" ); + WebRequest request = new GetMethodWebRequest( "http://localhost/" + resourceName2 ); + WebResponse response = wc.getResponse( request ); + assertNotNull( "No response received", response ); + assertEquals( "content type", "text/plain", response.getContentType() ); + assertEquals( "requested resource", "You posted green", response.getText() ); + assertEquals( "Returned cookie count", 0, response.getNewCookieNames().length ); + } + + + public void testSessionAccess() throws Exception { + final String resourceName1 = "something/interesting/start"; + final String resourceName2 = "something/continue"; + + ServletRunner sr = new ServletRunner(); + sr.registerServlet( resourceName1, StatefulServlet.class.getName() ); + sr.registerServlet( resourceName2, StatefulServlet.class.getName() ); + + WebRequest request = new PostMethodWebRequest( "http://localhost/" + resourceName1 ); + request.setParameter( "color", "yellow" ); + sr.getResponse( request ); + + assertNotNull( "No session was created", sr.getSession( false ) ); + assertEquals( "Color attribute in session", "yellow", sr.getSession( false ).getAttribute( "color" ) ); + } + + public void testInvocationContext() throws Exception { final String resourceName = "something/interesting"; |