Author: fmeschbe
Date: Thu Mar 25 09:05:05 2010
New Revision: 927311
URL: http://svn.apache.org/viewvc?rev=927311&view=rev
Log:
SLING-1456 Add integration validating presence and non-presence of request
attributes as per RequestDispatcher include and forward
Modified:
sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ForwardTest.java
sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/IncludeTest.java
sling/trunk/launchpad/testing/src/test/resources/integration-test/forward-forced.esp
sling/trunk/launchpad/testing/src/test/resources/integration-test/forward-test.esp
sling/trunk/launchpad/testing/src/test/resources/integration-test/include-test.esp
Modified:
sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ForwardTest.java
URL:
http://svn.apache.org/viewvc/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ForwardTest.java?rev=927311&r1=927310&r2=927311&view=diff
==============================================================================
---
sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ForwardTest.java
(original)
+++
sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/ForwardTest.java
Thu Mar 25 09:05:05 2010
@@ -103,6 +103,7 @@ import org.apache.sling.servlets.post.Sl
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 @@ import org.apache.sling.servlets.post.Sl
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 @@ import org.apache.sling.servlets.post.Sl
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 @@ import org.apache.sling.servlets.post.Sl
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);
}
}
Modified:
sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/IncludeTest.java
URL:
http://svn.apache.org/viewvc/sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/IncludeTest.java?rev=927311&r1=927310&r2=927311&view=diff
==============================================================================
---
sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/IncludeTest.java
(original)
+++
sling/trunk/launchpad/testing/src/test/java/org/apache/sling/launchpad/webapp/integrationtest/IncludeTest.java
Thu Mar 25 09:05:05 2010
@@ -102,6 +102,7 @@ import org.apache.sling.servlets.post.Sl
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 @@ import org.apache.sling.servlets.post.Sl
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 @@ import org.apache.sling.servlets.post.Sl
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 @@ import org.apache.sling.servlets.post.Sl
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 + "-"));
}
}
Modified:
sling/trunk/launchpad/testing/src/test/resources/integration-test/forward-forced.esp
URL:
http://svn.apache.org/viewvc/sling/trunk/launchpad/testing/src/test/resources/integration-test/forward-forced.esp?rev=927311&r1=927310&r2=927311&view=diff
==============================================================================
---
sling/trunk/launchpad/testing/src/test/resources/integration-test/forward-forced.esp
(original)
+++
sling/trunk/launchpad/testing/src/test/resources/integration-test/forward-forced.esp
Thu Mar 25 09:05:05 2010
@@ -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
Modified:
sling/trunk/launchpad/testing/src/test/resources/integration-test/forward-test.esp
URL:
http://svn.apache.org/viewvc/sling/trunk/launchpad/testing/src/test/resources/integration-test/forward-test.esp?rev=927311&r1=927310&r2=927311&view=diff
==============================================================================
---
sling/trunk/launchpad/testing/src/test/resources/integration-test/forward-test.esp
(original)
+++
sling/trunk/launchpad/testing/src/test/resources/integration-test/forward-test.esp
Thu Mar 25 09:05:05 2010
@@ -39,13 +39,37 @@ else
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><%
Modified:
sling/trunk/launchpad/testing/src/test/resources/integration-test/include-test.esp
URL:
http://svn.apache.org/viewvc/sling/trunk/launchpad/testing/src/test/resources/integration-test/include-test.esp?rev=927311&r1=927310&r2=927311&view=diff
==============================================================================
---
sling/trunk/launchpad/testing/src/test/resources/integration-test/include-test.esp
(original)
+++
sling/trunk/launchpad/testing/src/test/resources/integration-test/include-test.esp
Thu Mar 25 09:05:05 2010
@@ -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>
<%