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 13:51:15 UTC

svn commit: r1536694 - in /sling/trunk/launchpad/integration-tests/src/main/java/org/apache/sling/launchpad/webapp/integrationtest: JspIncludeTest.java JspScriptingTest.java

Author: bdelacretaz
Date: Tue Oct 29 12:51:15 2013
New Revision: 1536694

URL: http://svn.apache.org/r1536694
Log:
SLING-3215 - switch to JUnit4-style tests, to be able to use RetryRule later

Modified:
    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/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=1536694&r1=1536693&r2=1536694&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 12:51:15 2013
@@ -16,6 +16,9 @@
  */
 package org.apache.sling.launchpad.webapp.integrationtest;
 
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
 import java.io.IOException;
 import java.util.HashMap;
 import java.util.HashSet;
@@ -23,14 +26,16 @@ 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.servlets.post.SlingPostConstants;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.Test;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
-
-
 /** Test the {link ScriptHelper#include) functionality */
- public class JspIncludeTest extends JspTestBase {
+ public class JspIncludeTest {
 	 
 	private static final Logger log = LoggerFactory.getLogger(JspIncludeTest.class);
 
@@ -48,54 +53,57 @@ import org.slf4j.LoggerFactory;
     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();
+
+    @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
         // include 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 include path
         props.put("pathToInclude", pathToInclude + ".html");
-        nodeUrlE = testClient.createNode(url, props);
+        nodeUrlE = H.getTestClient().createNode(url, props);
 
         // Node F is used for the max calls detection test
         props.put("testMaxCalls","true");
-        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("testMaxCalls");
         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);
 
         // Node G is used for the basic "call" test
         props.remove("forceResourceType");
         props.remove("pathToInclude");
         props.put("testCallScript", "called-test.jsp");
-        nodeUrlG = testClient.createNode(url, props);
+        nodeUrlG = H.getTestClient().createNode(url, props);
         
         // Node I is used for the "var" test
         props.remove("forceResourceType");
@@ -103,69 +111,69 @@ import org.slf4j.LoggerFactory;
         props.put("testVarInclude","true"); 
         props.put("pathToInclude", pathToInclude);
         props.put("VAR_INCLUDE", "VALUE");
-        nodeUrlI = testClient.createNode(url, props);
+        nodeUrlI = H.getTestClient().createNode(url, props);
 
         // Script for forced resource type
-        scriptPath = "/apps/" + forcedResourceType;
-        testClient.mkdirs(WEBDAV_BASE_URL, scriptPath);
-        toDelete.add(uploadTestScript(scriptPath,"include-forced.jsp","html.jsp"));
+        H.setScriptPath("/apps/" + forcedResourceType);
+        H.getTestClient().mkdirs(HttpTest.WEBDAV_BASE_URL, H.getScriptPath());
+        toDelete.add(H.uploadTestScript(H.getScriptPath(),"include-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,"include-test.jsp","html.jsp"));
-        toDelete.add(uploadTestScript(scriptPath,"called-test.jsp","called-test.jsp"));
+        H.setScriptPath("/apps/nt/unstructured");
+        H.getTestClient().mkdirs(HttpTest.WEBDAV_BASE_URL, H.getScriptPath());
+        toDelete.add(H.uploadTestScript(H.getScriptPath(),"include-test.jsp","html.jsp"));
+        toDelete.add(H.uploadTestScript(H.getScriptPath(),"called-test.jsp","called-test.jsp"));
 
         // Node H is used for "call" test where the called script is inherited from the supertype
         String nodeHResourceType = getClass().getSimpleName() + "/" + System.currentTimeMillis();
         String nodeHSuperResourceType = getClass().getSimpleName() + "/super" + System.currentTimeMillis();
         props.put("sling:resourceType", nodeHResourceType);
         props.put("sling:resourceSuperType", nodeHSuperResourceType);
-        nodeUrlH = testClient.createNode(url, props);
-        scriptPath = "/apps/" + nodeHResourceType;
-        testClient.mkdirs(WEBDAV_BASE_URL, scriptPath);
-        toDelete.add(uploadTestScript(scriptPath,"calling-test.jsp","html.jsp"));
-        scriptPath = "/apps/" + nodeHSuperResourceType;
-        testClient.mkdirs(WEBDAV_BASE_URL, scriptPath);
-        toDelete.add(uploadTestScript(scriptPath,"called-test.jsp","called-test.jsp"));
+        nodeUrlH = H.getTestClient().createNode(url, props);
+        H.setScriptPath("/apps/" + nodeHResourceType);
+        H.getTestClient().mkdirs(HttpTest.WEBDAV_BASE_URL, H.getScriptPath());
+        toDelete.add(H.uploadTestScript(H.getScriptPath(),"calling-test.jsp","html.jsp"));
+        H.setScriptPath("/apps/" + nodeHSuperResourceType);
+        H.getTestClient().mkdirs(HttpTest.WEBDAV_BASE_URL, H.getScriptPath());
+        toDelete.add(H.uploadTestScript(H.getScriptPath(),"called-test.jsp","called-test.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);
         }
     }
 
-    public void testWithoutInclude() throws IOException {
-        final String content = getContent(nodeUrlA + ".html", CONTENT_TYPE_HTML);
+    @Test 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"));
     }
 
-    public void testWithInclude() throws IOException {
-        final String content = getContent(nodeUrlB + ".html", CONTENT_TYPE_HTML);
+    @Test 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>"));
         assertTrue("Include has been used",content.contains("<p>Including"));
         assertTrue("Text of node A is included (" + content + ")",content.contains(testTextA));
     }
 
-    public void testWithIncludeAndExtension() throws IOException {
-        final String content = getContent(nodeUrlE + ".html", CONTENT_TYPE_HTML);
+    @Test 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>"));
         assertTrue("Include has been used",content.contains("<p>Including"));
         assertTrue("Text of node A is included (" + content + ")",content.contains(testTextA));
     }
 
-    public void testInfiniteLoopDetection() throws IOException {
+    @Test 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",
@@ -177,11 +185,11 @@ import org.slf4j.LoggerFactory;
         // assertEquals("Status is 500 for infinite loop",HttpServletResponse.SC_INTERNAL_SERVER_ERROR, status);
     }
 
-    public void testMaxCallsDetection() throws IOException {
+    @Test 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");
-        httpClient.executeMethod(get);
+        H.getHttpClient().executeMethod(get);
         final String content = get.getResponseBodyAsString();
         assertTrue(
             "Response contains infinite loop error message",
@@ -193,8 +201,8 @@ import org.slf4j.LoggerFactory;
         // assertEquals("Status is 500 for infinite loop",HttpServletResponse.SC_INTERNAL_SERVER_ERROR, status);
     }
 
-    public void testForcedResourceType() throws IOException {
-        final String content = getContent(nodeUrlD + ".html", CONTENT_TYPE_HTML);
+    @Test 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>"));
         assertTrue("Include has been used",content.contains("<p>Including"));
@@ -202,24 +210,24 @@ import org.slf4j.LoggerFactory;
         assertTrue("Resource type has been forced (" + content + ")",content.contains("Forced resource type:" + forcedResourceType));
     }
 
-    public void testCall() throws IOException {
-        final String content = getContent(nodeUrlG + ".html", CONTENT_TYPE_HTML);
+    @Test 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>"));
         assertTrue("Call has been used",content.contains("<p>Calling"));
         assertTrue("Call has been made",content.contains("called"));
     }
 
-    public void testCallToSupertype() throws IOException {
+    @Test public void testCallToSupertype() throws IOException {
         System.out.println(nodeUrlH);
-        final String content = getContent(nodeUrlH + ".html", CONTENT_TYPE_HTML);
+        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"));
     }
     
-    public void testVarInclude() throws IOException{
+    @Test public void testVarInclude() throws IOException{
     	log.info("testVarInclude");
-        final String content = getContent(nodeUrlI + ".html", CONTENT_TYPE_HTML);
+        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:"));
     }

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=1536694&r1=1536693&r2=1536694&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 12:51:15 2013
@@ -16,69 +16,77 @@
  */
 package org.apache.sling.launchpad.webapp.integrationtest;
 
+import static org.junit.Assert.assertTrue;
+
+import org.apache.sling.commons.testing.integration.HttpTest;
+import org.apache.sling.commons.testing.integration.HttpTestNode;
 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;
 
 /** Test JSP scripting
  *  TODO this class can be generalized to be used for any scripting language,
  *  that would help in testing all scripting engines.
  */
-public class JspScriptingTest extends JspTestBase {
+public class JspScriptingTest {
 
     private String testRootUrl;
-    private TestNode rtNode;
-    private TestNode unstructuredNode;
+    private HttpTestNode rtNode;
+    private HttpTestNode unstructuredNode;
     
     public static final int CHECK_CONTENT_TIMEOUT_SECONDS = 5;
     public static final int CHECK_CONTENT_INTERVAL_MSEC = 500;
 
-    @Override
-    protected void setUp() throws Exception {
-        super.setUp();
-
-        final String testRootPath = HTTP_BASE_URL + "/" + getClass().getSimpleName() + "/" + System.currentTimeMillis();
-        testRootUrl = testClient.createNode(testRootPath + SlingPostConstants.DEFAULT_CREATE_SUFFIX, null);
-        rtNode = new TestNode(testRootPath + "/rt", null);
-        unstructuredNode = new TestNode(testRootPath + "/unstructured", null);
-    }
+    /** HTTP tests helper */
+    private final HttpTest H = new HttpTest();
 
-    @Override
-    protected void tearDown() throws Exception {
-        testClient.delete(testRootUrl);
-        super.tearDown();
+    @Before
+    public void setUp() throws Exception {
+        H.setUp();
+
+        final String testRootPath = HttpTest.HTTP_BASE_URL + "/" + getClass().getSimpleName() + "/" + System.currentTimeMillis();
+        testRootUrl = H.getTestClient().createNode(testRootPath + SlingPostConstants.DEFAULT_CREATE_SUFFIX, null);
+        rtNode = new HttpTestNode(H.getTestClient(), testRootPath + "/rt", null);
+        unstructuredNode = new HttpTestNode(H.getTestClient(), testRootPath + "/unstructured", null);
+    }
+
+    @Before
+    public void tearDown() throws Exception {
+        H.getTestClient().delete(testRootUrl);
+        H.tearDown();
     }
 
     public void testRtNoScript() throws Exception {
-        final String content = getContent(rtNode.nodeUrl + ".txt", CONTENT_TYPE_PLAIN);
+        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));
     }
 
     public void testUnstructuredNoScript() throws Exception {
-        final String content = getContent(unstructuredNode.nodeUrl + ".txt", CONTENT_TYPE_PLAIN);
+        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));
     }
 
     public void testRtJsp() throws Exception {
-        final String toDelete = uploadTestScript(rtNode.scriptPath, "rendering-test.jsp", "html.jsp");
+        final String toDelete = H.uploadTestScript(rtNode.scriptPath, "rendering-test.jsp", "html.jsp");
         try {
             checkContent(rtNode);
         } finally {
             if(toDelete != null) {
-                testClient.delete(toDelete);
+                H.getTestClient().delete(toDelete);
             }
         }
     }
 
     public void testUnstructuredJsp() throws Exception {
-        final String toDelete = uploadTestScript(unstructuredNode.scriptPath, "rendering-test.jsp", "html.jsp");
+        final String toDelete = H.uploadTestScript(unstructuredNode.scriptPath, "rendering-test.jsp", "html.jsp");
         try {
             checkContent(unstructuredNode);
         } finally {
             if(toDelete != null) {
-                testClient.delete(toDelete);
+                H.getTestClient().delete(toDelete);
             }
         }
     }
@@ -87,19 +95,19 @@ public class JspScriptingTest extends Js
         String tagFile = null;
         String tagUsingScript = null;
         try {
-            testClient.mkdirs(WEBDAV_BASE_URL, "/apps/testing/tags");
-            tagFile = uploadTestScript("/apps/testing/tags", "example.tag", "example.tag");
-            tagUsingScript = uploadTestScript(unstructuredNode.scriptPath, "withtag.jsp", "html.jsp");
+            H.getTestClient().mkdirs(HttpTest.WEBDAV_BASE_URL, "/apps/testing/tags");
+            tagFile = H.uploadTestScript("/apps/testing/tags", "example.tag", "example.tag");
+            tagUsingScript = H.uploadTestScript(unstructuredNode.scriptPath, "withtag.jsp", "html.jsp");
 
-            final String content = getContent(unstructuredNode.nodeUrl + ".html", CONTENT_TYPE_HTML);
+            final String content = H.getContent(unstructuredNode.nodeUrl + ".html", HttpTest.CONTENT_TYPE_HTML);
             assertTrue("JSP script executed as expected (" + content + ")", content.contains("<h1>Hello, Sling User</h1>"));
 
         } finally {
             if (tagFile != null) {
-                testClient.delete(tagFile);
+                H.getTestClient().delete(tagFile);
             }
             if (tagUsingScript != null) {
-                testClient.delete(tagUsingScript);
+                H.getTestClient().delete(tagUsingScript);
             }
         }
     }
@@ -112,7 +120,7 @@ public class JspScriptingTest extends Js
         try {
             final String [] scripts = { "jsp1.jsp", "jsp2.jsp" };
             for(String script : scripts) {
-                toDelete = uploadTestScript(unstructuredNode.scriptPath, script, "html.jsp");
+                toDelete = H.uploadTestScript(unstructuredNode.scriptPath, script, "html.jsp");
                 final String expected = "text from " + script + ":" + unstructuredNode.testText;
                 
                 final Condition c = new Condition() {
@@ -122,7 +130,7 @@ public class JspScriptingTest extends Js
                     }
 
                     public boolean isTrue() throws Exception {
-                        final String content = getContent(unstructuredNode.nodeUrl + ".html", CONTENT_TYPE_HTML);
+                        final String content = H.getContent(unstructuredNode.nodeUrl + ".html", HttpTest.CONTENT_TYPE_HTML);
                         return content.contains(expected);
                     }
                 };
@@ -131,7 +139,7 @@ public class JspScriptingTest extends Js
             }
         } finally {
             if(toDelete != null) {
-                testClient.delete(toDelete);
+                H.getTestClient().delete(toDelete);
             }
         }
     }
@@ -139,19 +147,19 @@ public class JspScriptingTest extends Js
     public void testEnum() throws Exception {
         String toDelete = null;
         try {
-            toDelete = uploadTestScript(unstructuredNode.scriptPath, "enum-test.jsp", "txt.jsp");
-            final String content = getContent(unstructuredNode.nodeUrl + ".txt", CONTENT_TYPE_PLAIN);
+            toDelete = H.uploadTestScript(unstructuredNode.scriptPath, "enum-test.jsp", "txt.jsp");
+            final String content = H.getContent(unstructuredNode.nodeUrl + ".txt", HttpTest.CONTENT_TYPE_PLAIN);
             for(String expected : new String[] { "FOO=FOO", "BAR=BAR"}) {
                 assertTrue("Content contains '" + expected + "'(" + content + ")", content.contains(expected));
             }
         } finally {
             if(toDelete != null) {
-                testClient.delete(toDelete);
+                H.getTestClient().delete(toDelete);
             }
         }
     }
 
-    private void checkContent(final TestNode tn) throws Exception {
+    private void checkContent(final HttpTestNode tn) throws Exception {
         final Condition c = new Condition() {
 
             public String getDescription() {
@@ -159,7 +167,7 @@ public class JspScriptingTest extends Js
             }
 
             public boolean isTrue() throws Exception {
-                final String content = getContent(tn.nodeUrl + ".html", CONTENT_TYPE_HTML);
+                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 = {