This is an automated email from the ASF dual-hosted git repository. bdelacretaz pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-servlets-resolver.git
commit 9c32130c82f67508290c73715cd872e8cb84094f Author: Bertrand Delacretaz <bdelacre...@apache.org> AuthorDate: Wed Jan 15 11:07:48 2020 +0100 SLING-8936 - add testAllExceptPathsIgnored --- .../resolver/it/ServletResolverTestSupport.java | 20 ++++++++++++---- .../servlets/resolver/it/ServletSelectionIT.java | 28 ++++++++++++++++++++++ .../sling/servlets/resolver/it/TestServlet.java | 5 ++++ 3 files changed, 49 insertions(+), 4 deletions(-) diff --git a/src/test/java/org/apache/sling/servlets/resolver/it/ServletResolverTestSupport.java b/src/test/java/org/apache/sling/servlets/resolver/it/ServletResolverTestSupport.java index 198701e..4634785 100644 --- a/src/test/java/org/apache/sling/servlets/resolver/it/ServletResolverTestSupport.java +++ b/src/test/java/org/apache/sling/servlets/resolver/it/ServletResolverTestSupport.java @@ -109,11 +109,19 @@ public class ServletResolverTestSupport extends TestSupport { fail("Did not get a " + expectedStatus + " status at " + path + " got " + statuses); } - protected MockSlingHttpServletResponse executeRequest(final String path, final int expectedStatus) throws Exception { + return executeRequest("GET", path, expectedStatus); + } + + protected MockSlingHttpServletResponse executeRequest(final String method, final String path, final int expectedStatus) throws Exception { final ResourceResolver resourceResolver = resourceResolverFactory.getAdministrativeResourceResolver(null); assertNotNull("Expecting ResourceResolver", resourceResolver); - final MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(resourceResolver); + final MockSlingHttpServletRequest request = new MockSlingHttpServletRequest(resourceResolver) { + @Override + public String getMethod() { + return method; + } + }; request.setPathInfo(path); final MockSlingHttpServletResponse response = new MockSlingHttpServletResponse(); @@ -144,8 +152,12 @@ public class ServletResolverTestSupport extends TestSupport { return response; } - protected void assertTestServlet(final String path, final String servletName) throws Exception { - final String output = executeRequest(path, 200).getOutputAsString(); + protected void assertTestServlet(String path, String servletName) throws Exception { + assertTestServlet("GET", path, servletName); + } + + protected void assertTestServlet(final String method, final String path, final String servletName) throws Exception { + final String output = executeRequest(method, path, 200).getOutputAsString(); final String expected = TestServlet.SERVED_BY_PREFIX + servletName; assertTrue("Expecting output to contain " + expected + ", got " + output, output.contains(expected)); } diff --git a/src/test/java/org/apache/sling/servlets/resolver/it/ServletSelectionIT.java b/src/test/java/org/apache/sling/servlets/resolver/it/ServletSelectionIT.java index 9ffa5ac..b28b762 100644 --- a/src/test/java/org/apache/sling/servlets/resolver/it/ServletSelectionIT.java +++ b/src/test/java/org/apache/sling/servlets/resolver/it/ServletSelectionIT.java @@ -39,12 +39,26 @@ public class ServletSelectionIT extends ServletResolverTestSupport { .with("sling.servlet.paths", "/foo") .register(bundleContext); + new TestServlet("AllExceptPathsIgnored") + .with("sling.servlet.paths", "/allprops") + .with("sling.servlet.resourceTypes", "allresource") + .with("sling.servlet.methods", "allmethod") + .with("sling.servlet.extensions", "allext") + .with("sling.servlet.selectors", "allsel") + .register(bundleContext); + new TestServlet("ExtServlet") .with("sling.servlet.resourceTypes", "sling/servlet/default") .with("sling.servlet.methods", "GET") .with("sling.servlet.extensions", "testext") .register(bundleContext); + new TestServlet("ExtPostServlet") + .with("sling.servlet.resourceTypes", "sling/servlet/default") + .with("sling.servlet.methods", "POST") + .with("sling.servlet.extensions", "testext") + .register(bundleContext); + new TestServlet("ExtSelServlet") .with("sling.servlet.resourceTypes", "sling/servlet/default") .with("sling.servlet.methods", "GET") @@ -100,4 +114,18 @@ public class ServletSelectionIT extends ServletResolverTestSupport { public void testNoServletForExtension() throws Exception { executeRequest("/.yapas", 404); } + + @Test + public void testExtPostServlet() throws Exception { + assertTestServlet("POST", "/.testext", "ExtPostServlet"); + } + + @Test + public void testAllExceptPathsIgnored() throws Exception { + assertTestServlet("/allprops", "AllExceptPathsIgnored"); + assertTestServlet("/allprops.one.two", "AllExceptPathsIgnored"); + assertTestServlet("POST", "/allprops.three.four", "AllExceptPathsIgnored"); + assertTestServlet("/allprops.five.six/suffix", "AllExceptPathsIgnored"); + assertTestServlet("POST", "/allprops.seven.eight/suffix", "AllExceptPathsIgnored"); + } } \ No newline at end of file diff --git a/src/test/java/org/apache/sling/servlets/resolver/it/TestServlet.java b/src/test/java/org/apache/sling/servlets/resolver/it/TestServlet.java index 11c08ea..c6f7776 100644 --- a/src/test/java/org/apache/sling/servlets/resolver/it/TestServlet.java +++ b/src/test/java/org/apache/sling/servlets/resolver/it/TestServlet.java @@ -46,6 +46,11 @@ public class TestServlet extends HttpServlet { resp.getWriter().write(SERVED_BY_PREFIX + name); } + @Override + public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException { + doGet(req, resp); + } + TestServlet with(String key, Object value) { properties.put(key, value); return this;