[Httpunit-commit] CVS: httpunit/test/com/meterware/servletunit StatelessTest.java,1.5,1.6 WebXMLTest
Brought to you by:
russgold
From: Russell G. <rus...@us...> - 2002-05-16 19:31:51
|
Update of /cvsroot/httpunit/httpunit/test/com/meterware/servletunit In directory usw-pr-cvs1:/tmp/cvs-serv6000/test/com/meterware/servletunit Modified Files: StatelessTest.java WebXMLTest.java Log Message: Support servlet class name as URL Index: StatelessTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/StatelessTest.java,v retrieving revision 1.5 retrieving revision 1.6 diff -u -r1.5 -r1.6 --- StatelessTest.java 16 May 2002 17:44:20 -0000 1.5 +++ StatelessTest.java 16 May 2002 19:04:13 -0000 1.6 @@ -4,12 +4,12 @@ * * Copyright (c) 2000-2001, 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 +* 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 * the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and * to permit persons to whom the Software is furnished to do so, subject to the following conditions: * -* The above copyright notice and this permission notice shall be included in all copies or substantial portions +* The above copyright notice and this permission notice shall be included in all copies or substantial portions * of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO @@ -38,8 +38,8 @@ public static void main(String args[]) { junit.textui.TestRunner.run( suite() ); } - - + + public static Test suite() { return new TestSuite( StatelessTest.class ); } @@ -72,6 +72,17 @@ WebRequest request = new GetMethodWebRequest( "http://localhost/" + resourceName ); assertEquals( "First reply", "1", sr.getResponse( request ).getText().trim() ); assertEquals( "Second reply", "2", sr.getResponse( request ).getText().trim() ); + } + + + public void testServletAccessByClassName() throws Exception { + ServletRunner sr = new ServletRunner(); + + WebRequest request = new GetMethodWebRequest( "http://localhost/" + SimpleGetServlet.class.getName() ); + WebResponse response = sr.getResponse( request ); + assertNotNull( "No response received", response ); + assertEquals( "content type", "text/html", response.getContentType() ); + assertEquals( "requested resource", SimpleGetServlet.RESPONSE_TEXT, response.getText() ); } Index: WebXMLTest.java =================================================================== RCS file: /cvsroot/httpunit/httpunit/test/com/meterware/servletunit/WebXMLTest.java,v retrieving revision 1.7 retrieving revision 1.8 diff -u -r1.7 -r1.8 --- WebXMLTest.java 3 Mar 2002 23:00:00 -0000 1.7 +++ WebXMLTest.java 16 May 2002 19:04:13 -0000 1.8 @@ -31,7 +31,6 @@ import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; -import javax.servlet.Servlet; import javax.servlet.ServletException; import org.xml.sax.SAXException; @@ -165,9 +164,8 @@ ServletRunner sr = new ServletRunner( toInputStream( wxs.asText() ) ); ServletUnitClient wc = sr.newClient(); - WebResponse response = null; try { - response = wc.getResponse( "http://localhost/SimpleServlet" ); + wc.getResponse( "http://localhost/SimpleServlet" ); fail( "Did not insist on validation for access to servlet" ); } catch (AuthorizationRequiredException e) { assertEquals( "Realm", "Sample Realm", e.getAuthenticationParameter( "realm" ) ); @@ -251,7 +249,7 @@ try { ic = wc.newInvocation( "http://localhost/SimpleServlet" ); - Servlet servlet = ic.getServlet(); + ic.getServlet(); fail("Attempt to access url outside of the webapp context path should have thrown a 404"); } catch (com.meterware.httpunit.HttpNotFoundException e) {} } @@ -277,7 +275,7 @@ assertTrue(ic.getServlet() instanceof Servlet3); try { ic = wc.newInvocation("http://localhost/catalog/index.html"); - Servlet servlet = ic.getServlet(); + ic.getServlet(); fail("Should have gotten a 404"); } catch (HttpNotFoundException e) {} ic = wc.newInvocation("http://localhost/catalog/racecar.bop"); @@ -286,9 +284,6 @@ assertTrue(ic.getServlet() instanceof Servlet4); } - private final static String DOCTYPE = "<!DOCTYPE web-app PUBLIC " + - " \"-//Sun Microsystems, Inc.//DTD WebApplication 2.2//EN\" " + - " \"http://java.sun/com/j2ee/dtds/web-app_2_2.dtd\">"; //=============================================================================================================== @@ -343,6 +338,7 @@ static class Servlet2 extends SimpleGetServlet {} static class Servlet3 extends SimpleGetServlet {} static class Servlet4 extends SimpleGetServlet {} + static class Servlet5 extends SimpleGetServlet {} } |