incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r605922 - in /incubator/sling/trunk/microsling/microsling-core/src/test: java/org/apache/sling/microsling/integration/PostParameterTest.java resources/integration-test/post-test.esp
Date Thu, 20 Dec 2007 13:32:20 GMT
Author: bdelacretaz
Date: Thu Dec 20 05:32:18 2007
New Revision: 605922

URL: http://svn.apache.org/viewvc?rev=605922&view=rev
Log:
SLING-144 - multipart form support for microsling, thanks to Philipp Koch (add the two missing
files)

Added:
    incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/PostParameterTest.java
  (with props)
    incubator/sling/trunk/microsling/microsling-core/src/test/resources/integration-test/post-test.esp

Added: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/PostParameterTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/PostParameterTest.java?rev=605922&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/PostParameterTest.java
(added)
+++ incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/PostParameterTest.java
Thu Dec 20 05:32:18 2007
@@ -0,0 +1,71 @@
+package org.apache.sling.microsling.integration;
+
+import org.apache.commons.httpclient.methods.PostMethod;
+import org.apache.commons.httpclient.methods.MultipartPostMethod;
+import org.apache.commons.httpclient.NameValuePair;
+
+import javax.servlet.http.HttpServletResponse;
+import java.util.Map;
+import java.util.HashMap;
+import java.io.IOException;
+import java.io.File;
+import java.io.FileInputStream;
+import java.io.BufferedWriter;
+import java.io.FileWriter;
+
+/**
+ * Check if multipart post request are handled well
+ */
+public class PostParameterTest extends RenderingTestBase {
+
+    @Override
+    protected void setUp() throws Exception {
+        super.setUp();
+
+        // set test values
+        testText = "This is a test " + System.currentTimeMillis();
+
+        // create the test node, under a path that's specific to this class to allow collisions
+        final String url = HTTP_BASE_URL + "/" + getClass().getSimpleName() + "." + System.currentTimeMillis();
+        final Map<String,String> props = new HashMap<String,String>();
+        props.put("text", testText);
+        displayUrl = testClient.createNode(url, props);
+
+        // the rendering script goes under /sling/scripts in the repository
+        scriptPath = "/sling/scripts/nt/unstructured";
+        testClient.mkdirs(WEBDAV_BASE_URL, scriptPath);
+    }
+
+    public void testBinaryUpload() throws IOException {
+        final String toDelete = uploadTestScript("post-test.esp","POST.esp");
+        File f = null;
+        try {
+
+            MultipartPostMethod post = new MultipartPostMethod(displayUrl);
+            post.setFollowRedirects(false);
+
+            // create simple test file
+            f = File.createTempFile("posttest",".txt");
+            FileWriter fstream = new FileWriter(f.getAbsolutePath());
+            BufferedWriter out = new BufferedWriter(fstream);
+            out.write("Hello uSling");
+            out.close();
+
+            post.addParameter("file", f);
+
+            final int status = httpClient.executeMethod(post);
+            final String response = post.getResponseBodyAsString();
+
+            // check confirmed file length sent from script
+            assertEquals(200, status);
+            assertEquals(f.length(), (long) Double.parseDouble(response));
+
+            post.releaseConnection();
+        } finally {
+            if (f != null) {
+                f.delete();
+            }
+            testClient.delete(toDelete);
+        }
+    }
+}

Propchange: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/PostParameterTest.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/trunk/microsling/microsling-core/src/test/java/org/apache/sling/microsling/integration/PostParameterTest.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Added: incubator/sling/trunk/microsling/microsling-core/src/test/resources/integration-test/post-test.esp
URL: http://svn.apache.org/viewvc/incubator/sling/trunk/microsling/microsling-core/src/test/resources/integration-test/post-test.esp?rev=605922&view=auto
==============================================================================
--- incubator/sling/trunk/microsling/microsling-core/src/test/resources/integration-test/post-test.esp
(added)
+++ incubator/sling/trunk/microsling/microsling-core/src/test/resources/integration-test/post-test.esp
Thu Dec 20 05:32:18 2007
@@ -0,0 +1,19 @@
+<%
+var length = 0;
+if (request.getRequestParameter("file") != null) {
+    var file = null;
+    // store file
+    var reqPara = request.getRequestParameter("file");
+    var is = reqPara.getInputStream();
+    file = Packages.java.io.File.createTempFile("posttest", ".txt");
+    var fout = new Packages.java.io.FileOutputStream(file);
+    var c;
+    while ((c = is.read()) != -1) {
+        fout.write(c);
+    }
+    fout.close();
+
+    // read length
+    length = file.length();
+}
+%><%=  Packages.java.lang.String.valueOf(length) %>
\ No newline at end of file



Mime
View raw message