You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@sling.apache.org by bd...@apache.org on 2013/10/29 14:31:45 UTC
svn commit: r1536704 - in
/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest:
JspForwardTest.java JspIncludeTest.java JspScriptingTest.java
Author: bdelacretaz
Date: Tue Oct 29 13:31:44 2013
New Revision: 1536704
URL: http://svn.apache.org/r1536704
Log:
SLING-3215 - use RetryRule in JSP integration tests
Modified:
sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/JspForwardTest.java
sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/JspIncludeTest.java
sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/JspScriptingTest.java
Modified: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/JspForwardTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/JspForwardTest.java?rev=1536704&r1=1536703&r2=1536704&view=diff
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/JspForwardTest.java (original)
+++ sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/JspForwardTest.java Tue Oct 29 13:31:44 2013
@@ -16,6 +16,8 @@
*/
package org.apache.sling.launchpad.webapp.integrationtest;
+import static org.junit.Assert.assertTrue;
+
import java.io.IOException;
import java.util.HashMap;
import java.util.HashSet;
@@ -23,11 +25,18 @@ import java.util.Map;
import java.util.Set;
import org.apache.commons.httpclient.methods.GetMethod;
+import org.apache.sling.commons.testing.integration.HttpTest;
+import org.apache.sling.commons.testing.junit.Retry;
+import org.apache.sling.commons.testing.junit.RetryRule;
import org.apache.sling.servlets.post.SlingPostConstants;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
/** Test the {link ScriptHelper#forward) functionality */
- public class JspForwardTest extends JspTestBase {
+ public class JspForwardTest {
private String nodeUrlA;
private String testTextA;
@@ -41,101 +50,117 @@ import org.apache.sling.servlets.post.Sl
private String forcedResourceType;
private Set<String> toDelete = new HashSet<String>();
- @Override
- protected void setUp() throws Exception {
- super.setUp();
+ /** HTTP tests helper */
+ private final HttpTest H = new HttpTest();
+
+ @Rule
+ public RetryRule retryRule = new RetryRule();
+
+ @Before
+ public void setUp() throws Exception {
+ H.setUp();
// Create the test nodes under a path that's specific to this class to
// allow collisions
- final String url = HTTP_BASE_URL + "/" + getClass().getSimpleName() + "/" + System.currentTimeMillis() + SlingPostConstants.DEFAULT_CREATE_SUFFIX;
+ final String url = HttpTest.HTTP_BASE_URL + "/" + getClass().getSimpleName() + "/" + System.currentTimeMillis() + SlingPostConstants.DEFAULT_CREATE_SUFFIX;
final Map<String,String> props = new HashMap<String,String>();
// Create two test nodes and store their paths
testTextA = "Text A " + System.currentTimeMillis();
props.put("text", testTextA);
- nodeUrlA = testClient.createNode(url, props);
- String pathToInclude = nodeUrlA.substring(HTTP_BASE_URL.length());
+ nodeUrlA = H.getTestClient().createNode(url, props);
+ String pathToInclude = nodeUrlA.substring(HttpTest.HTTP_BASE_URL.length());
// Node B stores the path of A, so that the test script can
// forward A when rendering B
testTextB = "Text B " + System.currentTimeMillis();
props.put("text", testTextB);
props.put("pathToInclude", pathToInclude);
- nodeUrlB = testClient.createNode(url, props);
+ nodeUrlB = H.getTestClient().createNode(url, props);
// Node E is like B but with an extension on the forward path
props.put("pathToInclude", pathToInclude + ".html");
- nodeUrlE = testClient.createNode(url, props);
+ nodeUrlE = H.getTestClient().createNode(url, props);
// Node F is like E but uses jsp:include
props.put("pathToInclude", pathToInclude + ".html");
props.put("forwardStyle", "jsp");
- nodeUrlF = testClient.createNode(url, props);
+ nodeUrlF = H.getTestClient().createNode(url, props);
// Node C is used for the infinite loop detection test
props.remove("pathToInclude");
props.remove("forwardStyle");
props.put("testInfiniteLoop","true");
- nodeUrlC = testClient.createNode(url, props);
+ nodeUrlC = H.getTestClient().createNode(url, props);
// Node D is used for the "force resource type" test
forcedResourceType = getClass().getSimpleName() + "/" + System.currentTimeMillis();
props.remove("testInfiniteLoop");
props.put("forceResourceType", forcedResourceType);
props.put("pathToInclude", pathToInclude);
- nodeUrlD = testClient.createNode(url, props);
+ nodeUrlD = H.getTestClient().createNode(url, props);
// Script for forced resource type
scriptPath = "/apps/" + forcedResourceType;
- testClient.mkdirs(WEBDAV_BASE_URL, scriptPath);
- toDelete.add(uploadTestScript(scriptPath,"forward-forced.jsp","html.jsp"));
+ H.getTestClient().mkdirs(HttpTest.WEBDAV_BASE_URL, scriptPath);
+ toDelete.add(H.uploadTestScript(scriptPath,"forward-forced.jsp","html.jsp"));
// The main rendering script goes under /apps in the repository
scriptPath = "/apps/nt/unstructured";
- testClient.mkdirs(WEBDAV_BASE_URL, scriptPath);
- toDelete.add(uploadTestScript(scriptPath,"forward-test.jsp","html.jsp"));
+ H.getTestClient().mkdirs(HttpTest.WEBDAV_BASE_URL, scriptPath);
+ toDelete.add(H.uploadTestScript(scriptPath,"forward-test.jsp","html.jsp"));
}
- @Override
- protected void tearDown() throws Exception {
- super.tearDown();
+ @After
+ public void tearDown() throws Exception {
+ H.tearDown();
for(String script : toDelete) {
- testClient.delete(script);
+ H.getTestClient().delete(script);
}
}
+ @Test
+ @Retry
public void testWithoutForward() throws IOException {
- final String content = getContent(nodeUrlA + ".html", CONTENT_TYPE_HTML);
+ final String content = H.getContent(nodeUrlA + ".html", HttpTest.CONTENT_TYPE_HTML);
assertTrue("Content includes JSP marker",content.contains("JSP template"));
assertTrue("Content contains formatted test text",content.contains("<p class=\"main\">" + testTextA + "</p>"));
}
+ @Test
+ @Retry
public void testWithForward() throws IOException {
- final String content = getContent(nodeUrlB + ".html", CONTENT_TYPE_HTML);
+ final String content = H.getContent(nodeUrlB + ".html", HttpTest.CONTENT_TYPE_HTML);
assertTrue("Content includes JSP marker",content.contains("JSP 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));
}
+ @Test
+ @Retry
public void testWithForwardAndExtension() throws IOException {
- final String content = getContent(nodeUrlE + ".html", CONTENT_TYPE_HTML);
+ final String content = H.getContent(nodeUrlE + ".html", HttpTest.CONTENT_TYPE_HTML);
assertTrue("Content includes JSP marker",content.contains("JSP 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));
}
+ @Test
+ @Retry
public void testWithJspForward() throws IOException {
- final String content = getContent(nodeUrlF + ".html", CONTENT_TYPE_HTML);
+ final String content = H.getContent(nodeUrlF + ".html", HttpTest.CONTENT_TYPE_HTML);
assertTrue("Content includes JSP marker",content.contains("JSP 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));
}
+ @Test
+ @Retry
public void testInfiniteLoopDetection() throws IOException {
// Node C has a property that causes an infinite include loop,
// Sling must indicate the problem in its response
final GetMethod get = new GetMethod(nodeUrlC + ".html");
- httpClient.executeMethod(get);
+ H.getHttpClient().executeMethod(get);
final String content = get.getResponseBodyAsString();
assertTrue(
"Response contains infinite loop error message",
@@ -147,8 +172,10 @@ import org.apache.sling.servlets.post.Sl
// assertEquals("Status is 500 for infinite loop",HttpServletResponse.SC_INTERNAL_SERVER_ERROR, status);
}
+ @Test
+ @Retry
public void testForcedResourceType() throws IOException {
- final String content = getContent(nodeUrlD + ".html", CONTENT_TYPE_HTML);
+ final String content = H.getContent(nodeUrlD + ".html", HttpTest.CONTENT_TYPE_HTML);
assertTrue("Content includes JSP marker",content.contains("JSP template"));
assertTrue("Content contains formatted test text",content.contains("<p class=\"main\">" + testTextA + "</p>"));
assertTrue("Text of node A is included (" + content + ")",!content.contains(testTextB));
Modified: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/JspIncludeTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/JspIncludeTest.java?rev=1536704&r1=1536703&r2=1536704&view=diff
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/JspIncludeTest.java (original)
+++ sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/JspIncludeTest.java Tue Oct 29 13:31:44 2013
@@ -27,18 +27,17 @@ import java.util.Set;
import org.apache.commons.httpclient.methods.GetMethod;
import org.apache.sling.commons.testing.integration.HttpTest;
+import org.apache.sling.commons.testing.junit.Retry;
+import org.apache.sling.commons.testing.junit.RetryRule;
import org.apache.sling.servlets.post.SlingPostConstants;
import org.junit.After;
import org.junit.Before;
+import org.junit.Rule;
import org.junit.Test;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
/** Test the {link ScriptHelper#include) functionality */
public class JspIncludeTest {
- private static final Logger log = LoggerFactory.getLogger(JspIncludeTest.class);
-
private String nodeUrlA;
private String testTextA;
private String nodeUrlB;
@@ -56,6 +55,9 @@ import org.slf4j.LoggerFactory;
/** HTTP tests helper */
private final HttpTest H = new HttpTest();
+ @Rule
+ public RetryRule retryRule = new RetryRule();
+
@Before
public void setUp() throws Exception {
H.setUp();
@@ -146,14 +148,18 @@ import org.slf4j.LoggerFactory;
}
}
- @Test public void testWithoutInclude() throws IOException {
+ @Test
+ @Retry
+ public void testWithoutInclude() throws IOException {
final String content = H.getContent(nodeUrlA + ".html", HttpTest.CONTENT_TYPE_HTML);
assertTrue("Content includes JSP marker",content.contains("JSP template"));
assertTrue("Content contains formatted test text",content.contains("<p class=\"main\">" + testTextA + "</p>"));
assertFalse("Nothing has been included",content.contains("<p>Including"));
}
- @Test public void testWithInclude() throws IOException {
+ @Test
+ @Retry
+ public void testWithInclude() throws IOException {
final String content = H.getContent(nodeUrlB + ".html", HttpTest.CONTENT_TYPE_HTML);
assertTrue("Content includes JSP marker",content.contains("JSP template"));
assertTrue("Content contains formatted test text",content.contains("<p class=\"main\">" + testTextB + "</p>"));
@@ -161,7 +167,9 @@ import org.slf4j.LoggerFactory;
assertTrue("Text of node A is included (" + content + ")",content.contains(testTextA));
}
- @Test public void testWithIncludeAndExtension() throws IOException {
+ @Test
+ @Retry
+ public void testWithIncludeAndExtension() throws IOException {
final String content = H.getContent(nodeUrlE + ".html", HttpTest.CONTENT_TYPE_HTML);
assertTrue("Content includes JSP marker",content.contains("JSP template"));
assertTrue("Content contains formatted test text",content.contains("<p class=\"main\">" + testTextB + "</p>"));
@@ -169,7 +177,9 @@ import org.slf4j.LoggerFactory;
assertTrue("Text of node A is included (" + content + ")",content.contains(testTextA));
}
- @Test public void testInfiniteLoopDetection() throws IOException {
+ @Test
+ @Retry
+ public void testInfiniteLoopDetection() throws IOException {
// Node C has a property that causes an infinite include loop,
// Sling must indicate the problem in its response
final GetMethod get = new GetMethod(nodeUrlC + ".html");
@@ -185,7 +195,9 @@ import org.slf4j.LoggerFactory;
// assertEquals("Status is 500 for infinite loop",HttpServletResponse.SC_INTERNAL_SERVER_ERROR, status);
}
- @Test public void testMaxCallsDetection() throws IOException {
+ @Test
+ @Retry
+ public void testMaxCallsDetection() throws IOException {
// Node F has a property that causes over 1000 includes
// Sling must indicate the problem in its response
final GetMethod get = new GetMethod(nodeUrlF + ".html");
@@ -201,7 +213,9 @@ import org.slf4j.LoggerFactory;
// assertEquals("Status is 500 for infinite loop",HttpServletResponse.SC_INTERNAL_SERVER_ERROR, status);
}
- @Test public void testForcedResourceType() throws IOException {
+ @Test
+ @Retry
+ public void testForcedResourceType() throws IOException {
final String content = H.getContent(nodeUrlD + ".html", HttpTest.CONTENT_TYPE_HTML);
assertTrue("Content includes JSP marker",content.contains("JSP template"));
assertTrue("Content contains formatted test text",content.contains("<p class=\"main\">" + testTextB + "</p>"));
@@ -210,7 +224,9 @@ import org.slf4j.LoggerFactory;
assertTrue("Resource type has been forced (" + content + ")",content.contains("Forced resource type:" + forcedResourceType));
}
- @Test public void testCall() throws IOException {
+ @Test
+ @Retry
+ public void testCall() throws IOException {
final String content = H.getContent(nodeUrlG + ".html", HttpTest.CONTENT_TYPE_HTML);
assertTrue("Content includes JSP marker",content.contains("JSP template"));
assertTrue("Content contains formatted test text",content.contains("<p class=\"main\">" + testTextB + "</p>"));
@@ -218,17 +234,18 @@ import org.slf4j.LoggerFactory;
assertTrue("Call has been made",content.contains("called"));
}
- @Test public void testCallToSupertype() throws IOException {
- System.out.println(nodeUrlH);
+ @Test
+ @Retry
+ public void testCallToSupertype() throws IOException {
final String content = H.getContent(nodeUrlH + ".html", HttpTest.CONTENT_TYPE_HTML);
assertTrue("Content includes JSP marker",content.contains("JSP template"));
assertTrue("Call has been made",content.contains("called"));
}
- @Test public void testVarInclude() throws IOException{
- log.info("testVarInclude");
+ @Test
+ @Retry
+ public void testVarInclude() throws IOException{
final String content = H.getContent(nodeUrlI + ".html", HttpTest.CONTENT_TYPE_HTML);
- log.info("Loaded content: "+content);
assertTrue("Content includes Loaded test content:",content.contains("Loaded test content:"));
}
-}
+}
\ No newline at end of file
Modified: sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/JspScriptingTest.java
URL: http://svn.apache.org/viewvc/sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/JspScriptingTest.java?rev=1536704&r1=1536703&r2=1536704&view=diff
==============================================================================
--- sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/JspScriptingTest.java (original)
+++ sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest/JspScriptingTest.java Tue Oct 29 13:31:44 2013
@@ -20,10 +20,14 @@ import static org.junit.Assert.assertTru
import org.apache.sling.commons.testing.integration.HttpTest;
import org.apache.sling.commons.testing.integration.HttpTestNode;
+import org.apache.sling.commons.testing.junit.Retry;
+import org.apache.sling.commons.testing.junit.RetryRule;
import org.apache.sling.servlets.post.SlingPostConstants;
import org.apache.sling.testing.tools.retry.RetryLoop;
import org.apache.sling.testing.tools.retry.RetryLoop.Condition;
import org.junit.Before;
+import org.junit.Rule;
+import org.junit.Test;
/** Test JSP scripting
* TODO this class can be generalized to be used for any scripting language,
@@ -40,6 +44,9 @@ public class JspScriptingTest {
/** HTTP tests helper */
private final HttpTest H = new HttpTest();
+
+ @Rule
+ public RetryRule retryRule = new RetryRule();
@Before
public void setUp() throws Exception {
@@ -57,18 +64,24 @@ public class JspScriptingTest {
H.tearDown();
}
+ @Test
+ @Retry
public void testRtNoScript() throws Exception {
final String content = H.getContent(rtNode.nodeUrl + ".txt", HttpTest.CONTENT_TYPE_PLAIN);
assertTrue(content.contains("PlainTextRendererServlet"));
assertTrue("Content contains " + rtNode.testText + " (" + content + ")", content.contains(rtNode.testText));
}
+ @Test
+ @Retry
public void testUnstructuredNoScript() throws Exception {
final String content = H.getContent(unstructuredNode.nodeUrl + ".txt", HttpTest.CONTENT_TYPE_PLAIN);
assertTrue(content.contains("PlainTextRendererServlet"));
assertTrue("Content contains " + unstructuredNode.testText + " (" + content + ")", content.contains(unstructuredNode.testText));
}
+ @Test
+ @Retry
public void testRtJsp() throws Exception {
final String toDelete = H.uploadTestScript(rtNode.scriptPath, "rendering-test.jsp", "html.jsp");
try {
@@ -80,6 +93,8 @@ public class JspScriptingTest {
}
}
+ @Test
+ @Retry
public void testUnstructuredJsp() throws Exception {
final String toDelete = H.uploadTestScript(unstructuredNode.scriptPath, "rendering-test.jsp", "html.jsp");
try {
@@ -91,6 +106,8 @@ public class JspScriptingTest {
}
}
+ @Test
+ @Retry
public void testTagFile() throws Exception {
String tagFile = null;
String tagUsingScript = null;
@@ -114,6 +131,7 @@ public class JspScriptingTest {
/* Verify that overwriting a JSP script changes the output within a reasonable time
* (might not be immediate as there's some observation and caching involved) */
+ @Test
public void testChangingJsp() throws Exception {
String toDelete = null;
@@ -144,6 +162,8 @@ public class JspScriptingTest {
}
}
+ @Test
+ @Retry
public void testEnum() throws Exception {
String toDelete = null;
try {
@@ -160,27 +180,15 @@ public class JspScriptingTest {
}
private void checkContent(final HttpTestNode tn) throws Exception {
- final Condition c = new Condition() {
-
- public String getDescription() {
- return "Check content of " + tn.nodeUrl;
- }
-
- public boolean isTrue() throws Exception {
- final String content = H.getContent(tn.nodeUrl + ".html", HttpTest.CONTENT_TYPE_HTML);
- assertTrue("JSP script executed as expected (" + content + ")", content.contains("<h1>JSP rendering result</h1>"));
-
- final String [] expected = {
- "using resource.adaptTo:" + tn.testText,
- "using currentNode:" + tn.testText,
- };
- for(String exp : expected) {
- assertTrue("Content contains " + exp + "(" + content + ")", content.contains(exp));
- }
- return true;
- }
- };
+ final String content = H.getContent(tn.nodeUrl + ".html", HttpTest.CONTENT_TYPE_HTML);
+ assertTrue("JSP script executed as expected (" + content + ")", content.contains("<h1>JSP rendering result</h1>"));
- new RetryLoop(c, CHECK_CONTENT_TIMEOUT_SECONDS, CHECK_CONTENT_INTERVAL_MSEC);
+ final String [] expected = {
+ "using resource.adaptTo:" + tn.testText,
+ "using currentNode:" + tn.testText,
+ };
+ for(String exp : expected) {
+ assertTrue("Content contains " + exp + "(" + content + ")", content.contains(exp));
+ }
}
-}
+}
\ No newline at end of file