SLING-1456 Add integration validating presence and non-presence of request attributes as per RequestDispatcher include and forward
git-svn-id: https://svn.apache.org/repos/asf/sling/trunk@927311 13f79535-47bb-0310-9956-ffa450edef68
diff --git a/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ForwardTest.java b/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ForwardTest.java
index ef20344..31935f7 100644
--- a/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ForwardTest.java
+++ b/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ForwardTest.java
@@ -103,6 +103,7 @@
final String content = getContent(nodeUrlA + ".html", CONTENT_TYPE_HTML);
assertTrue("Content includes ESP marker",content.contains("ESP template"));
assertTrue("Content contains formatted test text",content.contains("<p class=\"main\">" + testTextA + "</p>"));
+ IncludeTest.assertNoIncludeRequestAttributes(content);
}
public void testWithForward() throws IOException {
@@ -110,6 +111,7 @@
assertTrue("Content includes ESP marker",content.contains("ESP template"));
assertTrue("Content contains formatted test text",content.contains("<p class=\"main\">" + testTextA + "</p>"));
assertTrue("Text of node A is not included (" + content + ")",!content.contains(testTextB));
+ IncludeTest.assertNoIncludeRequestAttributes(content);
}
public void testWithForwardAndExtension() throws IOException {
@@ -117,6 +119,7 @@
assertTrue("Content includes ESP marker",content.contains("ESP template"));
assertTrue("Content contains formatted test text",content.contains("<p class=\"main\">" + testTextA + "</p>"));
assertTrue("Text of node A is not included (" + content + ")",!content.contains(testTextB));
+ IncludeTest.assertNoIncludeRequestAttributes(content);
}
public void testInfiniteLoopDetection() throws IOException {
@@ -141,5 +144,6 @@
assertTrue("Content contains formatted test text",content.contains("<p class=\"main\">" + testTextA + "</p>"));
assertTrue("Text of node A is included (" + content + ")",!content.contains(testTextB));
assertTrue("Resource type has been forced (" + content + ")",content.contains("Forced resource type:" + forcedResourceType));
+ IncludeTest.assertNoIncludeRequestAttributes(content);
}
}
diff --git a/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/IncludeTest.java b/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/IncludeTest.java
index 0465043..4694707 100644
--- a/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/IncludeTest.java
+++ b/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/IncludeTest.java
@@ -102,6 +102,7 @@
assertTrue("Content includes ESP marker",content.contains("ESP template"));
assertTrue("Content contains formatted test text",content.contains("<p class=\"main\">" + testTextA + "</p>"));
assertFalse("Nothing has been included",content.contains("<p>Including"));
+ assertNoIncludeRequestAttributes(content);
}
public void testWithInclude() throws IOException {
@@ -110,6 +111,7 @@
assertTrue("Content contains formatted test text",content.contains("<p class=\"main\">" + testTextB + "</p>"));
assertTrue("Include has been used",content.contains("<p>Including"));
assertTrue("Text of node A is included (" + content + ")",content.contains(testTextA));
+ assertIncludeRequestAttributes(content);
}
public void testWithIncludeAndExtension() throws IOException {
@@ -118,6 +120,7 @@
assertTrue("Content contains formatted test text",content.contains("<p class=\"main\">" + testTextB + "</p>"));
assertTrue("Include has been used",content.contains("<p>Including"));
assertTrue("Text of node A is included (" + content + ")",content.contains(testTextA));
+ assertIncludeRequestAttributes(content);
}
public void testInfiniteLoopDetection() throws IOException {
@@ -143,5 +146,47 @@
assertTrue("Include has been used",content.contains("<p>Including"));
assertTrue("Text of node A is included (" + content + ")",content.contains(testTextA));
assertTrue("Resource type has been forced (" + content + ")",content.contains("Forced resource type:" + testTextA));
+ assertIncludeRequestAttributes(content);
+ }
+
+ // also used by ForwardTest
+ static void assertIncludeRequestAttributes(final String content) {
+ assertIncludeRequestAttributes(content, "");
+ }
+
+ // also used by ForwardTest
+ static void assertNoIncludeRequestAttributes(final String content) {
+ assertIncludeRequestAttributes(content, "no");
+ }
+
+ private static void assertIncludeRequestAttributes(final String content, final String tag) {
+
+ // Servlet API attributes set on include
+ // except javax.servlet.include.query_string which not be set in request
+
+ assertRequestAttribute(content, tag,
+ "javax.servlet.include.request_uri");
+ assertRequestAttribute(content, tag,
+ "javax.servlet.include.context_path");
+ assertRequestAttribute(content, tag,
+ "javax.servlet.include.servlet_path");
+ assertRequestAttribute(content, tag, "javax.servlet.include.path_info");
+ assertRequestAttribute(content, tag,
+ "javax.servlet.include.request_uri");
+ assertRequestAttribute(content, tag,
+ "javax.servlet.include.request_uri");
+ assertRequestAttribute(content, tag,
+ "org.apache.sling.api.include.servlet");
+ assertRequestAttribute(content, tag,
+ "org.apache.sling.api.include.resource");
+ assertRequestAttribute(content, tag,
+ "org.apache.sling.api.include.request_path_info");
+ }
+
+ private static void assertRequestAttribute(final String content,
+ final String tag,
+ final String attrName) {
+ assertTrue("Expected content contains '-" + tag + "-" + attrName + "-'",
+ content.contains("-" + tag + "-" + attrName + "-"));
}
}
diff --git a/src/test/resources/integration-test/forward-forced.esp b/src/test/resources/integration-test/forward-forced.esp
index 90670f5..ff3370f 100644
--- a/src/test/resources/integration-test/forward-forced.esp
+++ b/src/test/resources/integration-test/forward-forced.esp
@@ -19,6 +19,11 @@
* under the License.
*/
+function testRequestAttribute(/* String */ name) {
+ var tag = (request.getAttribute(name) != null) ? "" : "no";
+ out.println("<p>-" + tag + "-" + name + "-</p>");
+}
+
// used by ForwardTest
%><html>
<body>
@@ -27,5 +32,20 @@
<div>
Forced resource type:<%= resource.resourceType %></p>.
</div>
+ <%
+ // Servlet API request include attributes
+ testRequestAttribute( "javax.servlet.include.request_uri" );
+ testRequestAttribute( "javax.servlet.include.context_path" );
+ testRequestAttribute( "javax.servlet.include.servlet_path" );
+ testRequestAttribute( "javax.servlet.include.path_info" );
+ testRequestAttribute( "javax.servlet.include.query_string" );
+ testRequestAttribute( "javax.servlet.include.request_uri" );
+ testRequestAttribute( "javax.servlet.include.request_uri" );
+
+ // Sling API request include attributes
+ testRequestAttribute( "org.apache.sling.api.include.servlet" );
+ testRequestAttribute( "org.apache.sling.api.include.resource" );
+ testRequestAttribute( "org.apache.sling.api.include.request_path_info" );
+ %>
</body>
</html>
\ No newline at end of file
diff --git a/src/test/resources/integration-test/forward-test.esp b/src/test/resources/integration-test/forward-test.esp
index fcf29d6..c70bf97 100644
--- a/src/test/resources/integration-test/forward-test.esp
+++ b/src/test/resources/integration-test/forward-test.esp
@@ -39,13 +39,37 @@
if(currentNode.testInfiniteLoop) {
// try to include the item itself, to cause an infinite loop
sling.forward(resource.getPath());
-} else {
+}
+
+else
+
+{
+
+function testRequestAttribute(/* String */ name) {
+ var tag = (request.getAttribute(name) != null) ? "" : "no";
+ out.println("<p>-" + tag + "-" + name + "-</p>");
+}
// Test 0: No Forward
%><html>
<body>
<h1>ESP template</h1>
<p class="main"><%= currentNode.text %></p>
+ <%
+ // Servlet API request include attributes
+ testRequestAttribute( "javax.servlet.include.request_uri" );
+ testRequestAttribute( "javax.servlet.include.context_path" );
+ testRequestAttribute( "javax.servlet.include.servlet_path" );
+ testRequestAttribute( "javax.servlet.include.path_info" );
+ testRequestAttribute( "javax.servlet.include.query_string" );
+ testRequestAttribute( "javax.servlet.include.request_uri" );
+ testRequestAttribute( "javax.servlet.include.request_uri" );
+
+ // Sling API request include attributes
+ testRequestAttribute( "org.apache.sling.api.include.servlet" );
+ testRequestAttribute( "org.apache.sling.api.include.resource" );
+ testRequestAttribute( "org.apache.sling.api.include.request_path_info" );
+ %>
</body>
</html><%
diff --git a/src/test/resources/integration-test/include-test.esp b/src/test/resources/integration-test/include-test.esp
index 15095b6..7aacc99 100644
--- a/src/test/resources/integration-test/include-test.esp
+++ b/src/test/resources/integration-test/include-test.esp
@@ -17,11 +17,34 @@
* under the License.
*/
+<%
+ function testRequestAttribute(/* String */ name) {
+ var tag = (request.getAttribute(name) != null) ? "" : "no";
+ out.println("<p>-" + tag + "-" + name + "-</p>");
+ }
+%>
+
<%-- used by IncludeTest --%>
<html>
<body>
<h1>ESP template</h1>
<p class="main"><%= currentNode.text %></p>
+
+ <%
+ // Servlet API request include attributes
+ testRequestAttribute( "javax.servlet.include.request_uri" );
+ testRequestAttribute( "javax.servlet.include.context_path" );
+ testRequestAttribute( "javax.servlet.include.servlet_path" );
+ testRequestAttribute( "javax.servlet.include.path_info" );
+ testRequestAttribute( "javax.servlet.include.query_string" );
+ testRequestAttribute( "javax.servlet.include.request_uri" );
+ testRequestAttribute( "javax.servlet.include.request_uri" );
+
+ // Sling API request include attributes
+ testRequestAttribute( "org.apache.sling.api.include.servlet" );
+ testRequestAttribute( "org.apache.sling.api.include.resource" );
+ testRequestAttribute( "org.apache.sling.api.include.request_path_info" );
+ %>
<h2>Test 1</h2>
<%