[Httpunit-commit] CVS: httpunit/test/com/meterware/servletunit ConfigTest.java,1.4,1.5 ServletUnitTe
Brought to you by:
russgold
|
From: Russell G. <rus...@us...> - 2004-03-03 01:32:54
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/servletunit In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv20921/test/com/meterware/servletunit Modified Files: ConfigTest.java ServletUnitTest.java SessionTest.java Log Message: servlet unit patches: null session attribute, context mime types Index: ConfigTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/ConfigTest.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- ConfigTest.java 19 Feb 2003 19:17:59 -0000 1.4 +++ ConfigTest.java 3 Mar 2004 01:12:51 -0000 1.5 @@ -87,6 +87,25 @@ } + public void testFileMimeType() throws Exception { + final String servlet1Name = "something/interesting"; + + ServletRunner sr = new ServletRunner(); + sr.registerServlet( servlet1Name, ConfigServlet.class.getName() ); + ServletUnitClient wc = sr.newClient(); + InvocationContext ic1 = wc.newInvocation( "http://localhost/" + servlet1Name ); + ServletContext context = ic1.getServlet().getServletConfig().getServletContext(); + checkMimeType( context, "sample.txt", "text/plain" ); + checkMimeType( context, "sample.html", "text/html" ); + checkMimeType( context, "sample.gif", "image/gif" ); + } + + + private void checkMimeType( ServletContext context, String fileName, String expectedMimeType ) { + assertEquals( "mime type for " + fileName, expectedMimeType, context.getMimeType( fileName ) ); + } + + static class ConfigServlet extends HttpServlet { static String RESPONSE_TEXT = "the desired content\r\n"; Index: ServletUnitTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/ServletUnitTest.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- ServletUnitTest.java 20 Aug 2003 12:06:15 -0000 1.4 +++ ServletUnitTest.java 3 Mar 2004 01:12:51 -0000 1.5 @@ -20,6 +20,8 @@ * *******************************************************************************************************************/ import java.util.Vector; +import java.util.Enumeration; +import java.util.ArrayList; import junit.framework.TestCase; @@ -36,6 +38,13 @@ //------------------------------------ protected members ------------------------------------------ + protected Object[] toArray( Enumeration e ) { + ArrayList result = new ArrayList(); + while (e.hasMoreElements()) result.add( e.nextElement() ); + return result.toArray(); + } + + protected void assertMatchingSet( String comment, Object[] expected, Object[] found ) { Vector expectedItems = new Vector(); Vector foundItems = new Vector(); Index: SessionTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/SessionTest.java,v retrieving revision 1.4 retrieving revision 1.5 diff -u -r1.4 -r1.5 --- SessionTest.java 20 Aug 2003 12:06:15 -0000 1.4 +++ SessionTest.java 3 Mar 2004 01:12:51 -0000 1.5 @@ -66,7 +66,7 @@ long accessedAt = session.getLastAccessedTime(); assertTrue( "Session is not marked as new", session.isNew() ); try { Thread.sleep( 50 ); } catch (InterruptedException e) {}; - assertEquals( "Initial access time", accessedAt, context.getSession( session.getId() ).getLastAccessedTime() ); + assertEquals( "Initial access time", accessedAt, context.getSession( session.getId() ).getLastAccessedTime() ); session.access(); assertTrue( "Last access time not changed", accessedAt != context.getSession( session.getId() ).getLastAccessedTime() ); assertTrue( "Session is still marked as new", !context.getSession( session.getId() ).isNew() ); @@ -74,6 +74,21 @@ } + public void testSessionAttributes() throws Exception { + ServletUnitContext context = new ServletUnitContext(); + ServletUnitHttpSession session = context.newSession(); + session.setAttribute( "first", new Integer(1) ); + session.setAttribute( "second", "two" ); + session.setAttribute( "third", "III" ); + + assertMatchingSet( "Attribute names", new String[] { "first", "second", "third" }, toArray( session.getAttributeNames() )); + + session.removeAttribute( "third" ); + session.setAttribute( "first", null ); + assertMatchingSet( "Attribute names", new String[] { "second" }, toArray( session.getAttributeNames() )); + } + + } |