You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@tomcat.apache.org by ma...@apache.org on 2016/04/11 12:28:37 UTC
svn commit: r1738564 -
/tomcat/trunk/test/org/apache/catalina/core/TestApplicationMapping.java
Author: markt
Date: Mon Apr 11 10:28:37 2016
New Revision: 1738564
URL: http://svn.apache.org/viewvc?rev=1738564&view=rev
Log:
Expand the tests to cover named dispatchers.
Modified:
tomcat/trunk/test/org/apache/catalina/core/TestApplicationMapping.java
Modified: tomcat/trunk/test/org/apache/catalina/core/TestApplicationMapping.java
URL: http://svn.apache.org/viewvc/tomcat/trunk/test/org/apache/catalina/core/TestApplicationMapping.java?rev=1738564&r1=1738563&r2=1738564&view=diff
==============================================================================
--- tomcat/trunk/test/org/apache/catalina/core/TestApplicationMapping.java (original)
+++ tomcat/trunk/test/org/apache/catalina/core/TestApplicationMapping.java Mon Apr 11 10:28:37 2016
@@ -94,7 +94,13 @@ public class TestApplicationMapping exte
doTestMappingInclude(contextPath, mapping, requestPath, matchValue, matchType);
tearDown();
setUp();
+ doTestMappingNamedInclude(contextPath, mapping, requestPath, matchValue, matchType);
+ tearDown();
+ setUp();
doTestMappingForward(contextPath, mapping, requestPath, matchValue, matchType);
+ tearDown();
+ setUp();
+ doTestMappingNamedForward(contextPath, mapping, requestPath, matchValue, matchType);
}
private void doTestMappingDirect(String contextPath, String mapping, String requestPath,
@@ -146,6 +152,29 @@ public class TestApplicationMapping exte
Assert.assertTrue(body, body.contains("IncludeServletName=[Mapping]"));
}
+ private void doTestMappingNamedInclude(String contextPath, String mapping, String requestPath,
+ String matchValue, String matchType) throws Exception {
+ Tomcat tomcat = getTomcatInstance();
+
+ // No file system docBase required
+ Context ctx = tomcat.addContext(contextPath, null);
+
+ Tomcat.addServlet(ctx, "Include", new NamedIncludeServlet());
+ ctx.addServletMapping(mapping, "Include");
+ Tomcat.addServlet(ctx, "Mapping", new MappingServlet());
+ ctx.addServletMapping("/mapping", "Mapping");
+
+ tomcat.start();
+
+ ByteChunk bc = getUrl("http://localhost:" + getPort() + contextPath + requestPath);
+ String body = bc.toString();
+
+ Assert.assertTrue(body, body.contains("MatchValue=[" + matchValue + "]"));
+ Assert.assertTrue(body, body.contains("Pattern=[" + mapping + "]"));
+ Assert.assertTrue(body, body.contains("MatchType=[" + matchType + "]"));
+ Assert.assertTrue(body, body.contains("ServletName=[Include]"));
+ }
+
private void doTestMappingForward(String contextPath, String mapping, String requestPath,
String matchValue, String matchType) throws Exception {
Tomcat tomcat = getTomcatInstance();
@@ -174,6 +203,29 @@ public class TestApplicationMapping exte
Assert.assertTrue(body, body.contains("ForwardServletName=[Forward]"));
}
+ private void doTestMappingNamedForward(String contextPath, String mapping, String requestPath,
+ String matchValue, String matchType) throws Exception {
+ Tomcat tomcat = getTomcatInstance();
+
+ // No file system docBase required
+ Context ctx = tomcat.addContext(contextPath, null);
+
+ Tomcat.addServlet(ctx, "Forward", new NamedForwardServlet());
+ ctx.addServletMapping(mapping, "Forward");
+ Tomcat.addServlet(ctx, "Mapping", new MappingServlet());
+ ctx.addServletMapping("/mapping", "Mapping");
+
+ tomcat.start();
+
+ ByteChunk bc = getUrl("http://localhost:" + getPort() + contextPath + requestPath);
+ String body = bc.toString();
+
+ Assert.assertTrue(body, body.contains("MatchValue=[" + matchValue + "]"));
+ Assert.assertTrue(body, body.contains("Pattern=[" + mapping + "]"));
+ Assert.assertTrue(body, body.contains("MatchType=[" + matchType + "]"));
+ Assert.assertTrue(body, body.contains("ServletName=[Forward]"));
+ }
+
private static class IncludeServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
@@ -186,6 +238,30 @@ public class TestApplicationMapping exte
}
}
+
+ private static class NamedIncludeServlet extends HttpServlet {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+ throws ServletException, IOException {
+ RequestDispatcher rd = req.getServletContext().getNamedDispatcher("Mapping");
+ rd.include(req, resp);
+ }
+ }
+
+
+ private static class NamedForwardServlet extends HttpServlet {
+ private static final long serialVersionUID = 1L;
+
+ @Override
+ protected void doGet(HttpServletRequest req, HttpServletResponse resp)
+ throws ServletException, IOException {
+ RequestDispatcher rd = req.getServletContext().getNamedDispatcher("Mapping");
+ rd.forward(req, resp);
+ }
+ }
+
private static class ForwardServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@tomcat.apache.org
For additional commands, e-mail: dev-help@tomcat.apache.org