incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r588583 - in /incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration: FileUploadTest.java helpers/HttpAnyMethod.java helpers/MicroslingIntegrationTestClient.java
Date Fri, 26 Oct 2007 09:41:04 GMT
Author: bdelacretaz
Date: Fri Oct 26 02:41:03 2007
New Revision: 588583

URL: http://svn.apache.org/viewvc?rev=588583&view=rev
Log:
SLING-82 - MicroslingIntegrationTestClient.mkdir() implemented and tested

Added:
    incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/helpers/HttpAnyMethod.java
  (with props)
Modified:
    incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/FileUploadTest.java
    incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/helpers/MicroslingIntegrationTestClient.java

Modified: incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/FileUploadTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/FileUploadTest.java?rev=588583&r1=588582&r2=588583&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/FileUploadTest.java
(original)
+++ incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/FileUploadTest.java
Fri Oct 26 02:41:03 2007
@@ -33,7 +33,6 @@
         final InputStream data = getClass().getResourceAsStream(testFile);
         assertNotNull("Local test file " + testFile + " must be found",data);
         
-        // TODO should not use a path at the root, but for now we have no "mkdir" client

         final String webdavUrl = WEBDAV_BASE_URL + "/FileUploadTest." + System.currentTimeMillis()
+ ".txt";
         
         // Upload a file via WebDAV, verify, delete and verify
@@ -43,5 +42,31 @@
         assertHttpStatus(webdavUrl, 200, "Resource " + webdavUrl + " must exist after upload");
         testClient.delete(webdavUrl);
         assertHttpStatus(webdavUrl, 404, "Resource " + webdavUrl + " must not exist anymore
after deleting");
+    }
+    
+    /** Try creating a directory via WebDAV */
+    public void testMkdir() throws IOException {
+        final String testDirUrl = WEBDAV_BASE_URL + "/microsling-integration-test." + System.currentTimeMillis();
+        
+        assertHttpStatus(testDirUrl, 404, testDirUrl);
+        
+        try {
+            testClient.mkdir(testDirUrl);
+        } catch(IOException ioe) {
+            fail(ioe.getMessage());
+        }
+        
+        assertHttpStatus(testDirUrl, 200, testDirUrl);
+        
+        try {
+            testClient.mkdir(testDirUrl);
+        } catch(IOException ioe) {
+            fail("mkdir must succeed on an existing directory, got IOException:" + ioe);
+        }
+        
+        assertHttpStatus(testDirUrl, 200, testDirUrl);
+        
+        testClient.delete(testDirUrl);
+        assertHttpStatus(testDirUrl, 404, testDirUrl + " must be gone after DELETE");
     }
 }

Added: incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/helpers/HttpAnyMethod.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/helpers/HttpAnyMethod.java?rev=588583&view=auto
==============================================================================
--- incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/helpers/HttpAnyMethod.java
(added)
+++ incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/helpers/HttpAnyMethod.java
Fri Oct 26 02:41:03 2007
@@ -0,0 +1,34 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.sling.microsling.integration.helpers;
+
+import org.apache.commons.httpclient.HttpMethodBase;
+
+/** Allows any HTTP method for HtttpClient */
+public class HttpAnyMethod extends HttpMethodBase {
+    private final String methodName;
+    
+    public HttpAnyMethod(String methodName, String uri) {
+        super(uri);
+        this.methodName = methodName;
+    }
+
+    @Override
+    public String getName() {
+        return methodName;
+    }
+}

Propchange: incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/helpers/HttpAnyMethod.java
------------------------------------------------------------------------------
    svn:eol-style = native

Propchange: incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/helpers/HttpAnyMethod.java
------------------------------------------------------------------------------
    svn:keywords = Author Date Id Revision Rev URL

Modified: incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/helpers/MicroslingIntegrationTestClient.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/helpers/MicroslingIntegrationTestClient.java?rev=588583&r1=588582&r2=588583&view=diff
==============================================================================
--- incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/helpers/MicroslingIntegrationTestClient.java
(original)
+++ incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/helpers/MicroslingIntegrationTestClient.java
Fri Oct 26 02:41:03 2007
@@ -21,15 +21,16 @@
 
 import org.apache.commons.httpclient.HttpClient;
 import org.apache.commons.httpclient.methods.DeleteMethod;
+import org.apache.commons.httpclient.methods.GetMethod;
 import org.apache.commons.httpclient.methods.InputStreamRequestEntity;
 import org.apache.commons.httpclient.methods.PutMethod;
 
 /** Client functions to interact with microsling in integration tests */ 
 public class MicroslingIntegrationTestClient {
-    private final HttpClient client;
+    private final HttpClient httpClient;
     
     public MicroslingIntegrationTestClient(HttpClient client) {
-        this.client = client;
+        this.httpClient = client;
     }
     
     /** Upload a file to the microsling repository 
@@ -38,7 +39,7 @@
     public int upload(String toUrl, InputStream is) throws IOException {
         final PutMethod put = new PutMethod(toUrl);
         put.setRequestEntity(new InputStreamRequestEntity(is));
-        return client.executeMethod(put);
+        return httpClient.executeMethod(put);
     }
     
     /** Delete a file from the microsling repository 
@@ -46,6 +47,18 @@
      */
     public int delete(String url) throws IOException {
         final DeleteMethod delete = new DeleteMethod(url);
-        return client.executeMethod(delete);
+        return httpClient.executeMethod(delete);
+    }
+    
+    /** Create the given directory, if needed, under given URL */
+    public void mkdir(String url) throws IOException {
+        int status = 0;
+        status = httpClient.executeMethod(new GetMethod(url));
+        if(status != 200) {
+            status = httpClient.executeMethod(new HttpAnyMethod("MKCOL",url));
+            if(status!=201) {
+                throw new IOException("mkdir(" + url + ") failed, status code=" + status);
+            }
+        }
     }
 }



Mime
View raw message