Author: kkolinko
Date: Sun Jul 13 13:11:07 2014
New Revision: 1610188

URL: http://svn.apache.org/r1610188
Log:
Combine similar tests into same file. No functional change.
ContextRoot and WelcomeFile mapper tests are moved into TestMapperWebapps class.

Removed:
    tomcat/trunk/test/org/apache/catalina/mapper/TestMapperContextRoot.java
    tomcat/trunk/test/org/apache/catalina/mapper/TestMapperWelcomeFiles.java
Modified:
    tomcat/trunk/test/org/apache/catalina/mapper/TestMapperWebapps.java

Modified: tomcat/trunk/test/org/apache/catalina/mapper/TestMapperWebapps.java
URL: 
http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/mapper/TestMapperWebapps.java?rev=1610188&r1=1610187&r2=1610188&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/mapper/TestMapperWebapps.java 
(original)
+++ tomcat/trunk/test/org/apache/catalina/mapper/TestMapperWebapps.java Sun Jul 
13 13:11:07 2014
@@ -17,10 +17,20 @@
 package org.apache.catalina.mapper;
 
 import java.io.File;
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+
+import javax.servlet.ServletException;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
 
 import org.junit.Assert;
 import org.junit.Test;
 
+import org.apache.catalina.Context;
+import org.apache.catalina.core.StandardContext;
 import org.apache.catalina.startup.Tomcat;
 import org.apache.catalina.startup.TomcatBaseTest;
 import org.apache.tomcat.util.buf.ByteChunk;
@@ -32,7 +42,51 @@ import org.apache.tomcat.websocket.serve
 public class TestMapperWebapps extends TomcatBaseTest{
 
     @Test
-    public void testContextReload_56658() throws Exception {
+    public void testContextRoot_Bug53339() throws Exception {
+        Tomcat tomcat = getTomcatInstance();
+        tomcat.enableNaming();
+
+        // Must have a real docBase - just use temp
+        Context ctx =
+            tomcat.addContext("", System.getProperty("java.io.tmpdir"));
+
+        Tomcat.addServlet(ctx, "Bug53356", new Bug53356Servlet());
+        ctx.addServletMapping("", "Bug53356");
+
+        tomcat.start();
+
+        ByteChunk body = getUrl("http://localhost:"; + getPort());
+
+        Assert.assertEquals("OK", body.toString());
+    }
+
+    private static class Bug53356Servlet extends HttpServlet {
+
+        private static final long serialVersionUID = 1L;
+
+        @Override
+        protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+                throws ServletException, IOException {
+            // Confirm behaviour as per Servlet 12.2
+            boolean pass = "/".equals(req.getPathInfo());
+            if (pass) {
+                pass = "".equals(req.getServletPath());
+            }
+            if (pass) {
+                pass = "".equals(req.getContextPath());
+            }
+
+            resp.setContentType("text/plain");
+            if (pass) {
+                resp.getWriter().write("OK");
+            } else {
+                resp.getWriter().write("FAIL");
+            }
+        }
+    }
+
+    @Test
+    public void testContextReload_Bug56658() throws Exception {
         Tomcat tomcat = getTomcatInstance();
 
         File appDir = new File(getBuildDirectory(), "webapps/examples");
@@ -77,4 +131,62 @@ public class TestMapperWebapps extends T
         text = res.toString();
         Assert.assertTrue(text, text.contains("<title>Apache Tomcat 
Examples</title>"));
     }
+
+    @Test
+    public void testWelcomeFileNotStrict() throws Exception {
+
+        Tomcat tomcat = getTomcatInstance();
+
+        File appDir = new File("test/webapp");
+
+        StandardContext ctxt = (StandardContext) tomcat.addWebapp(null, 
"/test",
+                appDir.getAbsolutePath());
+        ctxt.setReplaceWelcomeFiles(true);
+        ctxt.addWelcomeFile("index.jsp");
+        // Mapping for *.do is defined in web.xml
+        ctxt.addWelcomeFile("index.do");
+
+        tomcat.start();
+        ByteChunk bc = new ByteChunk();
+        int rc = getUrl("http://localhost:"; + getPort() +
+                "/test/welcome-files", bc, new HashMap<String,List<String>>());
+        Assert.assertEquals(HttpServletResponse.SC_OK, rc);
+        Assert.assertTrue(bc.toString().contains("JSP"));
+
+        rc = getUrl("http://localhost:"; + getPort() +
+                "/test/welcome-files/sub", bc,
+                new HashMap<String,List<String>>());
+        Assert.assertEquals(HttpServletResponse.SC_OK, rc);
+        Assert.assertTrue(bc.toString().contains("Servlet"));
+    }
+
+    @Test
+    public void testWelcomeFileStrict() throws Exception {
+
+        Tomcat tomcat = getTomcatInstance();
+
+        File appDir = new File("test/webapp");
+
+        StandardContext ctxt = (StandardContext) tomcat.addWebapp(null, 
"/test",
+                appDir.getAbsolutePath());
+        ctxt.setReplaceWelcomeFiles(true);
+        ctxt.addWelcomeFile("index.jsp");
+        // Mapping for *.do is defined in web.xml
+        ctxt.addWelcomeFile("index.do");
+
+        // Simulate STRICT_SERVLET_COMPLIANCE
+        ctxt.setResourceOnlyServlets("");
+
+        tomcat.start();
+        ByteChunk bc = new ByteChunk();
+        int rc = getUrl("http://localhost:"; + getPort() +
+                "/test/welcome-files", bc, new HashMap<String,List<String>>());
+        Assert.assertEquals(HttpServletResponse.SC_OK, rc);
+        Assert.assertTrue(bc.toString().contains("JSP"));
+
+        rc = getUrl("http://localhost:"; + getPort() +
+                "/test/welcome-files/sub", bc,
+                new HashMap<String,List<String>>());
+        Assert.assertEquals(HttpServletResponse.SC_NOT_FOUND, rc);
+    }
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscr...@tomcat.apache.org
For additional commands, e-mail: dev-h...@tomcat.apache.org

Reply via email to