incubator-sling-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From bdelacre...@apache.org
Subject svn commit: r588683 - in /incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration: FileUploadTest.java MkdirTest.java helpers/MicroslingIntegrationTestClient.java
Date Fri, 26 Oct 2007 15:20:29 GMT
Author: bdelacretaz
Date: Fri Oct 26 08:20:28 2007
New Revision: 588683

URL: http://svn.apache.org/viewvc?rev=588683&view=rev
Log:
SLING-82, MkdirTest added

Added:
    incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/MkdirTest.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=588683&r1=588682&r2=588683&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 08:20:28 2007
@@ -43,30 +43,4 @@
         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/MkdirTest.java
URL: http://svn.apache.org/viewvc/incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/MkdirTest.java?rev=588683&view=auto
==============================================================================
--- incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/MkdirTest.java
(added)
+++ incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/MkdirTest.java
Fri Oct 26 08:20:28 2007
@@ -0,0 +1,62 @@
+/*
+ * 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;
+
+import java.io.IOException;
+
+/** Test the MicroslingIntegrationTestClient's mkdir functions */ 
+public class MkdirTest extends MicroslingHttpTestBase {
+    
+    /** Try creating a directory via WebDAV */
+    public void testMkdir() throws IOException {
+        final String testDirUrl = WEBDAV_BASE_URL + TEST_PATH + 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");
+    }
+    
+    /** Try creating a deep directory structure */
+    public void testMkdirDeep() throws IOException {
+        final String path = TEST_PATH + "/mkdir-test-" + System.currentTimeMillis() + "/something";
+        final String url = WEBDAV_BASE_URL + path;
+        assertHttpStatus(url,404,url + " must not exist before test");
+        try {
+            testClient.mkdirs(WEBDAV_BASE_URL, path);
+        } catch(IOException ioe) {
+            fail("mkdirs failed:" + ioe);
+        }
+        assertHttpStatus(url,200,url + " must exist after test");
+    }
+}

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

Propchange: incubator/sling/whiteboard/microsling/src/test/java/org/apache/sling/microsling/integration/MkdirTest.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=588683&r1=588682&r2=588683&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 08:20:28 2007
@@ -52,7 +52,7 @@
         return httpClient.executeMethod(delete);
     }
     
-    /** Create the given directory, if needed, under given URL */
+    /** Create the given directory via WebDAV, if needed, under given URL */
     public void mkdir(String url) throws IOException {
         int status = 0;
         status = httpClient.executeMethod(new GetMethod(url));
@@ -61,6 +61,29 @@
             if(status!=201) {
                 throw new IOException("mkdir(" + url + ") failed, status code=" + status);
             }
+        }
+    }
+    
+    /** Create the given directory via WebDAV, including parent directories */ 
+    public void mkdirs(String baseUrl,String path) throws IOException {
+        final String [] paths = path.split("/");
+        if(baseUrl.endsWith("/")) {
+            baseUrl = baseUrl.substring(0,baseUrl.length() - 1);
+        }
+        
+        String currentPath = baseUrl;
+        for(String pathElement : paths) {
+            if(pathElement.length() == 0) {
+                continue;
+            }
+            currentPath += "/" + pathElement;
+            mkdir(currentPath);
+        }
+        
+        final String url = baseUrl + path;
+        final int status = httpClient.executeMethod(new GetMethod(url));
+        if(status!=200) {
+            throw new IOException("Expected status 200, got " + status + " for URL=" + url);
         }
     }
     



Mime
View raw message