Author: markt Date: Mon Sep 21 10:54:36 2009 New Revision: 817201 URL: http://svn.apache.org/viewvc?rev=817201&view=rev Log: Add a test case for https://issues.apache.org/bugzilla/show_bug.cgi?id=47866 Fix a couple of places where expected and actual were the wrong way around
Modified: tomcat/trunk/test/org/apache/catalina/startup/TestTomcat.java Modified: tomcat/trunk/test/org/apache/catalina/startup/TestTomcat.java URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/startup/TestTomcat.java?rev=817201&r1=817200&r2=817201&view=diff ============================================================================== --- tomcat/trunk/test/org/apache/catalina/startup/TestTomcat.java (original) +++ tomcat/trunk/test/org/apache/catalina/startup/TestTomcat.java Mon Sep 21 10:54:36 2009 @@ -52,7 +52,7 @@ } /** - * Simple servlet to test iJNDI + * Simple servlet to test JNDI */ public static class HelloWorldJndi extends HttpServlet { @@ -77,6 +77,26 @@ } } + /** + * Servlet that tries to obtain a URL for WEB-INF/web.xml + */ + public static class GetResource extends HttpServlet { + + private static final long serialVersionUID = 1L; + + public void doGet(HttpServletRequest req, HttpServletResponse res) + throws IOException { + URL url = req.getServletContext().getResource("/WEB-INF/web.xml"); + + res.getWriter().write("The URL obtained for /WEB-INF/web.xml was "); + if (url == null) { + res.getWriter().write("null"); + } else { + res.getWriter().write(url.toString()); + } + } + } + /** * Start tomcat with a single context and one * servlet - all programmatic, no server.xml or @@ -99,13 +119,12 @@ tomcat.start(); ByteChunk res = getUrl("http://localhost:" + getPort() + "/"); - assertEquals(res.toString(), "Hello world"); + assertEquals("Hello world", res.toString()); } public void testSingleWebapp() throws Exception { Tomcat tomcat = getTomcatInstance(); - // Currently in sandbox/tomcat-lite File appDir = new File("output/build/webapps/examples"); // app dir is relative to server home @@ -155,11 +174,33 @@ tomcat.start(); ByteChunk res = getUrl("http://localhost:" + getPort() + "/"); - assertEquals(res.toString(), "Hello, Tomcat User"); + assertEquals("Hello, Tomcat User", res.toString()); } /** + * Test for https://issues.apache.org/bugzilla/show_bug.cgi?id=47866 + */ + public void testGetResource() throws Exception { + Tomcat tomcat = getTomcatInstance(); + + // Must have a real docBase - just use temp + StandardContext ctx = + tomcat.addContext("/", System.getProperty("java.io.tmpdir")); + // You can customize the context by calling + // its API + + Tomcat.addServlet(ctx, "myServlet", new GetResource()); + ctx.addServletMapping("/", "myServlet"); + + tomcat.start(); + + int rc =getUrl("http://localhost:" + getPort() + "/", new ByteChunk(), + null); + assertEquals(HttpServletResponse.SC_OK, rc); + } + + /** * Wrapper for getting the response. */ public static ByteChunk getUrl(String path) throws IOException { --------------------------------------------------------------------- To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org For additional commands, e-mail: dev-h...@tomcat.apache.org