This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-servlet-helpers.git
commit 421908339e72563f9e99e3fc6f24f2599fa1c7e0 Author: Stefan Seifert <[email protected]> AuthorDate: Thu Jun 15 09:50:41 2017 +0000 SLING-6947 add setPathInfo method to allow setting a custom pathinfo git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@1798814 13f79535-47bb-0310-9956-ffa450edef68 --- .../servlethelpers/MockSlingHttpServletRequest.java | 9 +++++++++ .../org/apache/sling/servlethelpers/package-info.java | 2 +- .../servlethelpers/MockSlingHttpServletRequestTest.java | 17 +++++++++++++++++ 3 files changed, 27 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/apache/sling/servlethelpers/MockSlingHttpServletRequest.java b/src/main/java/org/apache/sling/servlethelpers/MockSlingHttpServletRequest.java index 66c9f69..94a2ba6 100644 --- a/src/main/java/org/apache/sling/servlethelpers/MockSlingHttpServletRequest.java +++ b/src/main/java/org/apache/sling/servlethelpers/MockSlingHttpServletRequest.java @@ -89,6 +89,7 @@ public class MockSlingHttpServletRequest extends SlingAdaptable implements Sling private String serverName = "localhost"; private int serverPort = 80; private String servletPath = StringUtils.EMPTY; + private String pathInfo = null; private String method = HttpConstants.METHOD_GET; private final HeaderSupport headerSupport = new HeaderSupport(); private final CookieSupport cookieSupport = new CookieSupport(); @@ -658,6 +659,10 @@ public class MockSlingHttpServletRequest extends SlingAdaptable implements Sling @Override public String getPathInfo() { + if (this.pathInfo != null) { + return this.pathInfo; + } + RequestPathInfo requestPathInfo = this.getRequestPathInfo(); if (StringUtils.isEmpty(requestPathInfo.getResourcePath())) { @@ -684,6 +689,10 @@ public class MockSlingHttpServletRequest extends SlingAdaptable implements Sling return pathInfo.toString(); } + + public void setPathInfo(String pathInfo) { + this.pathInfo = pathInfo; + } @Override public String getRequestURI() { diff --git a/src/main/java/org/apache/sling/servlethelpers/package-info.java b/src/main/java/org/apache/sling/servlethelpers/package-info.java index 7e1c68d..e8477bd 100644 --- a/src/main/java/org/apache/sling/servlethelpers/package-info.java +++ b/src/main/java/org/apache/sling/servlethelpers/package-info.java @@ -19,5 +19,5 @@ /** * Mock implementation of selected Servlet-related Sling APIs. */ [email protected]("1.1") [email protected]("1.2") package org.apache.sling.servlethelpers; diff --git a/src/test/java/org/apache/sling/servlethelpers/MockSlingHttpServletRequestTest.java b/src/test/java/org/apache/sling/servlethelpers/MockSlingHttpServletRequestTest.java index e1bd3b6..26e5f51 100644 --- a/src/test/java/org/apache/sling/servlethelpers/MockSlingHttpServletRequestTest.java +++ b/src/test/java/org/apache/sling/servlethelpers/MockSlingHttpServletRequestTest.java @@ -387,4 +387,21 @@ public class MockSlingHttpServletRequestTest { assertEquals(1234, request.getRemotePort()); } + @Test + public void testServletPathWithPathInfo() throws Exception { + request.setServletPath("/my/path"); + request.setPathInfo("/myinfo");; + + assertEquals("/my/path", request.getServletPath()); + assertEquals("/myinfo", request.getPathInfo()); + } + + @Test + public void testServletPathWithOutPathInfo() throws Exception { + request.setServletPath("/my/path"); + + assertEquals("/my/path", request.getServletPath()); + assertNull(request.getPathInfo()); + } + } -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
