Author: bdelacretaz
Date: Tue Sep 1 14:14:10 2015
New Revision: 1700561
URL: http://svn.apache.org/r1700561
Log:
SLING-4804 - add an integration test for getRequestURI and getRequestURL
Added:
sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/resolution/RequestObjectTest.java
Modified:
sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/resolution/ResolutionTestBase.java
sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/servlets/TestServlet.java
Added: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/resolution/RequestObjectTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/resolution/RequestObjectTest.java?rev=1700561&view=auto
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/resolution/RequestObjectTest.java
(added)
+++ sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/resolution/RequestObjectTest.java
Tue Sep 1 14:14:10 2015
@@ -0,0 +1,69 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.launchpad.webapp.integrationtest.servlets.resolution;
+
+import java.io.IOException;
+import java.util.Properties;
+
+import org.apache.sling.commons.testing.integration.HttpTestBase;
+
+/** Test the values returned by the HttpServletRequest object server-side,
+ * created for SLING-4804 */
+public class RequestObjectTest extends ResolutionTestBase {
+
+ private String path;
+ private final String extension = ".TEST_SEL_1.txt";
+
+ private static class TestItem {
+ final String requestSuffix;
+ final String expectedURISuffix;
+ final String expectedURLSuffix;
+
+ TestItem(String s,String uri,String url) {
+ requestSuffix = s;
+ expectedURISuffix = uri;
+ expectedURLSuffix = url;
+ }
+
+ public String info(String msg) {
+ return msg + ":TestItem with suffix [" + requestSuffix + "]";
+ }
+ };
+
+ final TestItem [] TESTS = {
+ new TestItem("","",""),
+ new TestItem(";v=1.1",";v=1.1",";v=1.1"),
+ new TestItem(";v=1.1?foo=bar",";v=1.1",";v=1.1"),
+ new TestItem(";v=1.1?foo=bar&ga+bu=zo+meu",";v=1.1",";v=1.1")
+ };
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ path = testNodeNORT.nodeUrl.substring(HttpTestBase.HTTP_BASE_URL.length()) + extension;
+ }
+
+ public void testRequestPathInfo() throws IOException {
+ for(TestItem t : TESTS) {
+ final String content = getContent(testNodeNORT.nodeUrl + ".TEST_SEL_1.txt" +
t.requestSuffix, CONTENT_TYPE_PLAIN);
+ final Properties props = getTestServletProperties(content);
+ assertEquals(t.info("path"), path, props.get("http.request.pathInfo"));
+ assertEquals(t.info("URI"), path + t.expectedURISuffix, props.get("http.request.requestURI"));
+ assertEquals(t.info("URL"), testNodeNORT.nodeUrl + extension + t.expectedURLSuffix,
props.get("http.request.requestURL"));
+ }
+ }
+}
Modified: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/resolution/ResolutionTestBase.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/resolution/ResolutionTestBase.java?rev=1700561&r1=1700560&r2=1700561&view=diff
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/resolution/ResolutionTestBase.java
(original)
+++ sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/servlets/resolution/ResolutionTestBase.java
Tue Sep 1 14:14:10 2015
@@ -67,9 +67,7 @@ class ResolutionTestBase extends HttpTes
* expected suffix
*/
protected void assertServlet(String content, String expectedSuffix) throws IOException
{
- final Properties props = new Properties();
- final InputStream is = new ByteArrayInputStream(content.getBytes());
- props.load(is);
+ final Properties props = getTestServletProperties(content);
assertTrue(
"Content represents a non-empty Properties object (" + content + ")",
props.size() > 0);
@@ -81,6 +79,13 @@ class ResolutionTestBase extends HttpTes
CLASS_PROP + " property value (" + clazz + ") ends with " + expectedSuffix,
clazz.endsWith(expectedSuffix));
}
+
+ protected Properties getTestServletProperties(String content) throws IOException {
+ final Properties props = new Properties();
+ final InputStream is = new ByteArrayInputStream(content.getBytes());
+ props.load(is);
+ return props;
+ }
/** Assert that content does not contain TEST_SERVLET_MARKER
*/
Modified: sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/servlets/TestServlet.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/servlets/TestServlet.java?rev=1700561&r1=1700560&r2=1700561&view=diff
==============================================================================
--- sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/servlets/TestServlet.java
(original)
+++ sling/trunk/launchpad/test-services/src/main/java/org/apache/sling/launchpad/testservices/servlets/TestServlet.java
Tue Sep 1 14:14:10 2015
@@ -57,6 +57,9 @@ class TestServlet extends SlingAllMethod
props.put("sling.resource.path", r == null ? "" : r.getPath());
props.put("sling.resource.type", r == null ? "" : r.getResourceType());
props.put("http.request.method", request.getMethod());
+ props.put("http.request.pathInfo", request.getPathInfo());
+ props.put("http.request.requestURI", request.getRequestURI());
+ props.put("http.request.requestURL", request.getRequestURL().toString());
setCustomProperties(props);
props.store(response.getOutputStream(), "Data created by " + getClass().getName() + "
at " + new Date());
|