]> source.dussan.org Git - archiva.git/commitdiff
MRM-781 - Removal of Archiva-Webdav implementation in favor of Jackrabbit-webdav
authorJames William Dumay <jdumay@apache.org>
Tue, 3 Jun 2008 08:23:06 +0000 (08:23 +0000)
committerJames William Dumay <jdumay@apache.org>
Tue, 3 Jun 2008 08:23:06 +0000 (08:23 +0000)
* Implementing litmus compatible removeMember() (DELETE)
* Unit tests

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@662691 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-webdav/src/main/java/org/apache/maven/archiva/webdav/ArchivaDavResource.java
archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/maven/archiva/webdav/DavResourceTest.java

index 7d0efa9f487542183110d54637a094b2ae0193a8..78c1b0c8f97db2d50cb2580dec07fbf55c761ad7 100644 (file)
@@ -307,37 +307,28 @@ public class ArchivaDavResource
         throws DavException
     {
         File resource = checkDavResourceIsArchivaDavResource( member ).getLocalResource();
-
-        if ( !resource.exists() )
-        {
-            throw new DavException( HttpServletResponse.SC_NOT_FOUND, member.getResourcePath() );
-        }
-
-        boolean suceeded = false;
-
-        if ( resource.isDirectory() )
+        
+        if ( resource.exists() )
         {
             try
             {
-                FileUtils.deleteDirectory( resource );
-                suceeded = true;
+                if ( resource.isDirectory() )
+                {
+                    FileUtils.deleteDirectory(resource);
+                }
+                else
+                {
+                    if (!resource.delete())
+                    {
+                        throw new IOException("Could not remove file");
+                    }
+                }
             }
             catch ( IOException e )
             {
-                throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, e );
+                throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR );
             }
         }
-
-        if ( !suceeded && resource.isFile() )
-        {
-            suceeded = resource.delete();
-        }
-
-        if ( !suceeded )
-        {
-            throw new DavException( HttpServletResponse.SC_INTERNAL_SERVER_ERROR, "Could not delete resource " +
-                member.getResourcePath() );
-        }
     }
 
     public void move( DavResource destination )
index 483aab675523e307ad0ee8479a990a340320a71d..46cd3af722e86f83cdf2a0f8c85b71939934b598 100644 (file)
@@ -23,6 +23,9 @@ import java.io.File;
 import org.apache.commons.io.FileUtils;
 import org.apache.jackrabbit.webdav.DavException;
 import org.apache.jackrabbit.webdav.DavResource;
+import org.apache.jackrabbit.webdav.DavResourceFactory;
+import org.apache.jackrabbit.webdav.DavResourceLocator;
+import org.apache.jackrabbit.webdav.DavServletRequest;
 import org.apache.jackrabbit.webdav.DavServletResponse;
 import org.apache.jackrabbit.webdav.DavSession;
 import org.apache.jackrabbit.webdav.lock.ActiveLock;
@@ -43,6 +46,8 @@ public class DavResourceTest extends PlexusInSpringTestCase
     
     private ArchivaDavResourceLocator resourceLocator;
     
+    private DavResourceFactory resourceFactory;
+    
     private File baseDir;
     
     private final String REPOPATH = "myresource.jar";
@@ -64,6 +69,7 @@ public class DavResourceTest extends PlexusInSpringTestCase
         baseDir.mkdirs();
         myResource = new File(baseDir, "myresource.jar");
         assertTrue("Could not create " + myResource.getAbsolutePath(), myResource.createNewFile());
+        resourceFactory = new RootContextDavResourceFactory();
         resourceLocator = (ArchivaDavResourceLocator)new ArchivaDavLocatorFactory().createResourceLocator("/", REPOPATH);
         resource = getDavResource(resourceLocator.getHref(false), myResource);
         lockManager = new SimpleLockManager();
@@ -81,7 +87,32 @@ public class DavResourceTest extends PlexusInSpringTestCase
     
     private DavResource getDavResource(String logicalPath, File file)
     {
-        return new ArchivaDavResource(file.getAbsolutePath(), logicalPath, mimeTypes, session, resourceLocator, null);
+        return new ArchivaDavResource(file.getAbsolutePath(), logicalPath, mimeTypes, session, resourceLocator, resourceFactory);
+    }
+    
+    public void testDeleteCollection()
+        throws Exception
+    {
+        File dir = new File(baseDir, "testdir");
+        try
+        {
+            assertTrue(dir.mkdir());
+            DavResource directoryResource = getDavResource("/testdir", dir);
+            directoryResource.getCollection().removeMember(directoryResource);
+            assertFalse(dir.exists());
+        }
+        finally
+        {
+            FileUtils.deleteDirectory(dir);
+        }
+    }
+    
+    public void testDeleteResource()
+        throws Exception
+    {
+        assertTrue(myResource.exists());
+        resource.getCollection().removeMember(resource);
+        assertFalse(myResource.exists());
     }
     
     public void testIsLockable()
@@ -232,4 +263,15 @@ public class DavResourceTest extends PlexusInSpringTestCase
         
         assertEquals(0, resource.getLocks().length);      
     }
+    
+    private class RootContextDavResourceFactory implements DavResourceFactory
+    {
+        public DavResource createResource(DavResourceLocator locator, DavServletRequest request, DavServletResponse response) throws DavException {
+            throw new UnsupportedOperationException("Not supported yet.");
+        }
+
+        public DavResource createResource(DavResourceLocator locator, DavSession session) throws DavException {
+            return new ArchivaDavResource(baseDir.getAbsolutePath(), "/", mimeTypes, session, resourceLocator, resourceFactory);
+        }
+    }
 }