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 2009/08/05 18:54:51 UTC

svn commit: r801300 - /sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/integration/HttpTestBase.java

Author: bdelacretaz
Date: Wed Aug  5 16:54:51 2009
New Revision: 801300

URL: http://svn.apache.org/viewvc?rev=801300&view=rev
Log:
HttpTestBase.executeScript(...) added

Modified:
    sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/integration/HttpTestBase.java

Modified: sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/integration/HttpTestBase.java
URL: http://svn.apache.org/viewvc/sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/integration/HttpTestBase.java?rev=801300&r1=801299&r2=801300&view=diff
==============================================================================
--- sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/integration/HttpTestBase.java (original)
+++ sling/trunk/bundles/commons/testing/src/main/java/org/apache/sling/commons/testing/integration/HttpTestBase.java Wed Aug  5 16:54:51 2009
@@ -62,6 +62,9 @@
     
     public static final String SLING_POST_SERVLET_CREATE_SUFFIX = "/";
 	public static final String DEFAULT_EXT = ".txt";
+	
+	public static final String EXECUTE_RESOURCE_TYPE = "SlingTesting" + HttpTestBase.class.getSimpleName();
+	private static int executeCounter;
 
     protected SlingIntegrationTestClient testClient;
     protected HttpClient httpClient;
@@ -348,6 +351,44 @@
         }
         return url;
     }
+    
+    /** Upload script, execute with no parameters and return content */
+    protected String executeScript(String localFilename) throws Exception {
+        return executeScript(localFilename, null);
+    }
+    
+    /** Upload script, execute with given parameters (optional) and return content */
+    protected String executeScript(String localFilename, List<NameValuePair> params) throws Exception {
+        
+        // Use unique resource type
+        int counter = 0;
+        synchronized (getClass()) {
+            counter = ++executeCounter;
+        }
+        final String resourceType = EXECUTE_RESOURCE_TYPE + counter;
+        final String scriptPath = "/apps/" + resourceType;
+        testClient.mkdirs(WEBDAV_BASE_URL , scriptPath);
+        
+        final int pos = localFilename.lastIndexOf(".");
+        if(pos < 1) {
+            throw new IllegalArgumentException("localFilename must have extension (" + localFilename + ")");
+        }
+        final String ext = localFilename.substring(pos + 1);
+        final List<String> toDelete = new LinkedList<String>(); 
+        try {
+            toDelete.add(uploadTestScript(scriptPath, localFilename, "txt." + ext));
+            final Map<String, String> props = new HashMap<String, String>();
+            props.put(SLING_RESOURCE_TYPE, resourceType);
+            final String nodePath = scriptPath + "/node" + counter;
+            final String nodeUrl = testClient.createNode(HTTP_BASE_URL + nodePath, props);
+            toDelete.add(nodeUrl);
+            return getContent(nodeUrl + ".txt", CONTENT_TYPE_DONTCARE, params);
+        } finally {
+            for(String url : toDelete) {
+                testClient.delete(url);
+            }
+        }
+    }
 
     protected void assertJavascript(String expectedOutput, String jsonData, String code) throws IOException {
         assertJavascript(expectedOutput, jsonData, code, null);