Author: sseifert Date: Thu Jun 15 10:18:30 2017 New Revision: 1798816 URL: http://svn.apache.org/viewvc?rev=1798816&view=rev Log: SLING-6947 add setPathInfo method to allow setting a custom pathinfo
Modified: sling/branches/testing/mocks/servlet-helpers-1.0.x/src/main/java/org/apache/sling/servlethelpers/MockSlingHttpServletRequest.java sling/branches/testing/mocks/servlet-helpers-1.0.x/src/test/java/org/apache/sling/servlethelpers/MockSlingHttpServletRequestTest.java Modified: sling/branches/testing/mocks/servlet-helpers-1.0.x/src/main/java/org/apache/sling/servlethelpers/MockSlingHttpServletRequest.java URL: http://svn.apache.org/viewvc/sling/branches/testing/mocks/servlet-helpers-1.0.x/src/main/java/org/apache/sling/servlethelpers/MockSlingHttpServletRequest.java?rev=1798816&r1=1798815&r2=1798816&view=diff ============================================================================== --- sling/branches/testing/mocks/servlet-helpers-1.0.x/src/main/java/org/apache/sling/servlethelpers/MockSlingHttpServletRequest.java (original) +++ sling/branches/testing/mocks/servlet-helpers-1.0.x/src/main/java/org/apache/sling/servlethelpers/MockSlingHttpServletRequest.java Thu Jun 15 10:18:30 2017 @@ -88,6 +88,7 @@ public class MockSlingHttpServletRequest 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(); @@ -645,6 +646,10 @@ public class MockSlingHttpServletRequest @Override public String getPathInfo() { + if (this.pathInfo != null) { + return this.pathInfo; + } + RequestPathInfo requestPathInfo = this.getRequestPathInfo(); if (StringUtils.isEmpty(requestPathInfo.getResourcePath())) { @@ -671,6 +676,10 @@ public class MockSlingHttpServletRequest return pathInfo.toString(); } + + public void setPathInfo(String pathInfo) { + this.pathInfo = pathInfo; + } @Override public String getRequestURI() { Modified: sling/branches/testing/mocks/servlet-helpers-1.0.x/src/test/java/org/apache/sling/servlethelpers/MockSlingHttpServletRequestTest.java URL: http://svn.apache.org/viewvc/sling/branches/testing/mocks/servlet-helpers-1.0.x/src/test/java/org/apache/sling/servlethelpers/MockSlingHttpServletRequestTest.java?rev=1798816&r1=1798815&r2=1798816&view=diff ============================================================================== --- sling/branches/testing/mocks/servlet-helpers-1.0.x/src/test/java/org/apache/sling/servlethelpers/MockSlingHttpServletRequestTest.java (original) +++ sling/branches/testing/mocks/servlet-helpers-1.0.x/src/test/java/org/apache/sling/servlethelpers/MockSlingHttpServletRequestTest.java Thu Jun 15 10:18:30 2017 @@ -387,4 +387,21 @@ public class MockSlingHttpServletRequest 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()); + } + }