]> source.dussan.org Git - archiva.git/commitdiff
- implement deleteArtifact in AdministrationServiceImpl
authorMaria Odea B. Ching <oching@apache.org>
Mon, 13 Oct 2008 06:13:27 +0000 (06:13 +0000)
committerMaria Odea B. Ching <oching@apache.org>
Mon, 13 Oct 2008 06:13:27 +0000 (06:13 +0000)
- updated test cases for artifact delete

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

24 files changed:
MRM-124/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractLegacyRepositoryContent.java
MRM-124/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedDefaultRepositoryContent.java
MRM-124/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedLegacyRepositoryContent.java
MRM-124/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/ArtifactVersionsConstraint.java
MRM-124/archiva-modules/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/ArtifactVersionsConstraintTest.java
MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java
MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java
MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/default-repo/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.jar [new file with mode: 0644]
MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/default-repo/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.jar.md5 [new file with mode: 0644]
MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/default-repo/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.jar.sha1 [new file with mode: 0644]
MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/default-repo/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.pom [new file with mode: 0644]
MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/default-repo/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.pom.md5 [new file with mode: 0644]
MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/default-repo/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.pom.sha1 [new file with mode: 0644]
MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/default-repo/org/apache/archiva/archiva-test/1.0/maven-metadata.xml [new file with mode: 0644]
MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/default-repo/org/apache/archiva/archiva-test/1.0/maven-metadata.xml.md5 [new file with mode: 0644]
MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/default-repo/org/apache/archiva/archiva-test/1.0/maven-metadata.xml.sha1 [new file with mode: 0644]
MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/default-repo/org/apache/archiva/archiva-test/1.1/archiva-test-1.1.jar [new file with mode: 0644]
MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/default-repo/org/apache/archiva/archiva-test/1.1/archiva-test-1.1.pom [new file with mode: 0644]
MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/legacy-repo/org.apache.archiva/jars/archiva-diff-1.0.jar [new file with mode: 0644]
MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/legacy-repo/org.apache.archiva/jars/archiva-test-1.0.jar [new file with mode: 0644]
MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/legacy-repo/org.apache.archiva/jars/archiva-test-1.1.jar [new file with mode: 0644]
MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/legacy-repo/org.apache.archiva/poms/archiva-diff-1.0.pom [new file with mode: 0644]
MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/legacy-repo/org.apache.archiva/poms/archiva-test-1.0.pom [new file with mode: 0644]
MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/legacy-repo/org.apache.archiva/poms/archiva-test-1.1.pom [new file with mode: 0644]

index f135d5aad5985d803d55949d4213810758d9fe5a..5ff3c783bad5cf3d3bae94902cd3dc01d1e996aa 100644 (file)
@@ -117,4 +117,9 @@ public abstract class AbstractLegacyRepositoryContent
         // Default process.
         return type + "s";
     }
+    
+    public void setLegacyPathParser( PathParser parser )
+    {
+        this.legacyPathParser = parser;
+    }
 }
index 53bfc1bcbb401e6fd07d24f64972cf11d6b3d812..93545f3dd082b8eadcf3875945ad76b06cd85645 100644 (file)
@@ -78,6 +78,10 @@ public class ManagedDefaultRepositoryContent
                 // TODO: log this somewhere?
             }
         }
+        else
+        {
+            throw new ContentNotFoundException( "Unable to delete non-existing project directory." );
+        }
     }
 
     public String getId()
index c7eee23a5204cb4ae9c92c6101eef87eb505df89..4307022baf9b6ad5b65561ea42e0d3ead44c7255 100644 (file)
@@ -35,18 +35,20 @@ public class ArtifactVersionsConstraint
     
     private String sortColumn = "repositoryId";
     
-    public ArtifactVersionsConstraint( String repoId, String groupId, String artifactId )
+    public ArtifactVersionsConstraint( String repoId, String groupId, String artifactId, boolean includeWhenGathered )
     {        
         if( repoId != null )
         {   
-            whereClause = "repositoryId.equals(selectedRepoId) && groupId.equals(selectedGroupId) && artifactId.equals(selectedArtifactId) " +
-                       "&& whenGathered != null";
+            whereClause = "repositoryId.equals(selectedRepoId) && groupId.equals(selectedGroupId) && artifactId.equals(selectedArtifactId) " 
+                + ( includeWhenGathered ? "&& whenGathered != null" : "" );                
             declParams = new String[] { "String selectedRepoId", "String selectedGroupId", "String selectedArtifactId" };
             params = new Object[] { repoId, groupId, artifactId };
         }
         else
         {
-            whereClause = "groupId.equals(selectedGroupId) && artifactId.equals(selectedArtifactId) && this.whenGathered != null";            
+            whereClause =
+                "groupId.equals(selectedGroupId) && artifactId.equals(selectedArtifactId) " +                        
+                    ( includeWhenGathered ? "&& whenGathered != null" : "" );            
             declParams = new String[] { "String selectedGroupId", "String selectedArtifactId" };
             params = new Object[] { groupId, artifactId };
         }
@@ -54,7 +56,7 @@ public class ArtifactVersionsConstraint
     
     public ArtifactVersionsConstraint( String repoId, String groupId, String artifactId, String sortColumn )
     {   
-        this( repoId, groupId, artifactId );
+        this( repoId, groupId, artifactId, true );
         this.sortColumn = sortColumn;        
     }
         
index f7fa5b4ff70dc700b169d17d61bef4aaf0c6cb6e..d00c6dcf58c61131e04039036278f4c2e0ff57ae 100644 (file)
@@ -87,14 +87,14 @@ public class ArtifactVersionsConstraintTest
     {        
         populateDb();
         assertConstraint( "Artifacts By Repository", 3, 
-                          new ArtifactVersionsConstraint( null, "org.apache.archiva", "artifact-one" ) );
+                          new ArtifactVersionsConstraint( null, "org.apache.archiva", "artifact-one", true ) );
     }    
     
     public void testQueryAllVersionsOfArtifactInARepo() throws Exception
     {
         populateDb();
         assertConstraint( "Artifacts By Repository", 2, 
-                          new ArtifactVersionsConstraint( TEST_REPO, "org.apache.archiva", "artifact-one" ) );
+                          new ArtifactVersionsConstraint( TEST_REPO, "org.apache.archiva", "artifact-one", true ) );
     }
     
     private void assertConstraint( String msg, int count, ArtifactVersionsConstraint constraint )
index 35ff650a1847dd7b180497d9b2b653cfbd6c74b4..fafc92361dc82e6c4792a655e38a07a06d86b56a 100644 (file)
@@ -32,11 +32,22 @@ import org.apache.maven.archiva.configuration.IndeterminateConfigurationExceptio
 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
 import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
 import org.apache.maven.archiva.configuration.RepositoryScanningConfiguration;
+import org.apache.maven.archiva.consumers.ConsumerException;
 import org.apache.maven.archiva.consumers.DatabaseCleanupConsumer;
 import org.apache.maven.archiva.consumers.DatabaseUnprocessedArtifactConsumer;
 import org.apache.maven.archiva.consumers.InvalidRepositoryContentConsumer;
 import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
+import org.apache.maven.archiva.database.ArchivaDatabaseException;
+import org.apache.maven.archiva.database.ArtifactDAO;
+import org.apache.maven.archiva.database.constraints.ArtifactVersionsConstraint;
 import org.apache.maven.archiva.database.updater.DatabaseConsumers;
+import org.apache.maven.archiva.model.ArchivaArtifact;
+import org.apache.maven.archiva.model.VersionedReference;
+import org.apache.maven.archiva.repository.ContentNotFoundException;
+import org.apache.maven.archiva.repository.ManagedRepositoryContent;
+import org.apache.maven.archiva.repository.RepositoryContentFactory;
+import org.apache.maven.archiva.repository.RepositoryException;
+import org.apache.maven.archiva.repository.RepositoryNotFoundException;
 import org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers;
 import org.apache.maven.archiva.scheduled.ArchivaTaskScheduler;
 import org.apache.maven.archiva.scheduled.DefaultArchivaTaskScheduler;
@@ -73,6 +84,26 @@ public class AdministrationServiceImpl
      */
     private ArchivaTaskScheduler taskScheduler;
     
+    /**
+     * @plexus.requirement
+     */
+    private RepositoryContentFactory repoFactory;
+    
+    /**
+     * @plexus.requirement role-hint="jdo"
+     */
+    private ArtifactDAO artifactDAO;
+    
+    /**
+     * @plexus.requirement role-hint="not-present-remove-db-artifact"
+     */
+    private DatabaseCleanupConsumer cleanupArtifacts;
+    
+    /**
+     * @plexus.requirement role-hint="not-present-remove-db-project"
+     */
+    private DatabaseCleanupConsumer cleanupProjects;
+    
     /**
      * @see AdministrationService#configureDatabaseConsumer(String, boolean)
      */
@@ -190,12 +221,76 @@ public class AdministrationServiceImpl
     /**
      * @see AdministrationService#deleteArtifact(String, String, String, String)
      */
-    public boolean deleteArtifact( String repoId, String groupId, String artifactId, String version ) throws Exception
+    public boolean deleteArtifact( String repoId, String groupId, String artifactId, String version )
+        throws Exception
     {
-        // TODO implement delete artifact in Archiva
+        Configuration config = archivaConfiguration.getConfiguration();
+        ManagedRepositoryConfiguration repoConfig = config.findManagedRepositoryById( repoId );
         
-        // TODO Auto-generated method stub
-        return false;
+        if( repoConfig == null )
+        {
+            throw new Exception( "Repository does not exist." );
+        }
+            
+        try
+        {
+            ManagedRepositoryContent repoContent = repoFactory.getManagedRepositoryContent( repoId );            
+            VersionedReference ref = new VersionedReference();
+            ref.setGroupId( groupId );
+            ref.setArtifactId( artifactId );
+            ref.setVersion( version );
+                   
+            // delete from file system
+            repoContent.deleteVersion( ref );
+            
+            ArtifactVersionsConstraint constraint = new ArtifactVersionsConstraint( repoId, groupId, artifactId, false );
+            List<ArchivaArtifact> artifacts = null;
+            
+            try
+            {
+                artifacts = artifactDAO.queryArtifacts( constraint );
+                if( artifacts == null )
+                {
+                    return true;
+                }
+            }
+            catch ( ArchivaDatabaseException e )
+            {
+                throw new Exception( "Error occurred while cleaning up database." );
+            }            
+               
+            // cleanup db manually? or use the cleanup consumers as what is done now?
+            for( ArchivaArtifact artifact : artifacts )
+            {
+                if( artifact.getVersion().equals( version ) )
+                {
+                    try
+                    {
+                        cleanupArtifacts.processArchivaArtifact( artifact );
+                        cleanupProjects.processArchivaArtifact( artifact );
+                    }
+                    catch ( ConsumerException ce )
+                    {
+                        // log error
+                        continue;
+                    }                   
+                }
+            }
+        }
+        catch ( ContentNotFoundException e )
+        {
+            throw new Exception( "Artifact does not exist." );
+        }
+        catch ( RepositoryNotFoundException e )
+        {
+            throw new Exception( "Repository does not exist." );
+        }
+        catch ( RepositoryException e )
+        {
+            throw new Exception( "Repository exception occurred." );
+        }
+        
+        return true;
     }
 
     /**
@@ -370,5 +465,25 @@ public class AdministrationServiceImpl
     public void setTaskScheduler( ArchivaTaskScheduler taskScheduler )
     {
         this.taskScheduler = taskScheduler;
+    }
+
+    public void setRepoFactory( RepositoryContentFactory repoFactory )
+    {
+        this.repoFactory = repoFactory;
+    }
+
+    public void setArtifactDAO( ArtifactDAO artifactDAO )
+    {
+        this.artifactDAO = artifactDAO;
+    }
+
+    public void setCleanupArtifacts( DatabaseCleanupConsumer cleanupArtifacts )
+    {
+        this.cleanupArtifacts = cleanupArtifacts;
+    }
+
+    public void setCleanupProjects( DatabaseCleanupConsumer cleanupProjects )
+    {
+        this.cleanupProjects = cleanupProjects;
     }   
 }
index 0a9b3085990f96ba68d4ed5d6655e1243459b071..59d24519c42e03dc9e366114f9300ba1f2d6d96d 100644 (file)
@@ -19,6 +19,7 @@ package org.apache.archiva.web.xmlrpc.services;
  * under the License.
  */
 
+import java.io.File;
 import java.util.ArrayList;
 import java.util.List;
 
@@ -27,6 +28,7 @@ import org.apache.archiva.web.xmlrpc.api.beans.RemoteRepository;
 import org.apache.maven.archiva.configuration.ArchivaConfiguration;
 import org.apache.maven.archiva.configuration.Configuration;
 import org.apache.maven.archiva.configuration.DatabaseScanningConfiguration;
+import org.apache.maven.archiva.configuration.FileTypes;
 import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration;
 import org.apache.maven.archiva.configuration.RemoteRepositoryConfiguration;
 import org.apache.maven.archiva.configuration.RepositoryScanningConfiguration;
@@ -34,7 +36,16 @@ import org.apache.maven.archiva.consumers.DatabaseCleanupConsumer;
 import org.apache.maven.archiva.consumers.DatabaseUnprocessedArtifactConsumer;
 import org.apache.maven.archiva.consumers.InvalidRepositoryContentConsumer;
 import org.apache.maven.archiva.consumers.KnownRepositoryContentConsumer;
+import org.apache.maven.archiva.database.ArtifactDAO;
 import org.apache.maven.archiva.database.updater.DatabaseConsumers;
+import org.apache.maven.archiva.model.ArchivaArtifact;
+import org.apache.maven.archiva.model.ArchivaArtifactModel;
+import org.apache.maven.archiva.model.ArtifactReference;
+import org.apache.maven.archiva.repository.RepositoryContentFactory;
+import org.apache.maven.archiva.repository.content.ManagedDefaultRepositoryContent;
+import org.apache.maven.archiva.repository.content.ManagedLegacyRepositoryContent;
+import org.apache.maven.archiva.repository.content.PathParser;
+import org.apache.maven.archiva.repository.layout.LayoutException;
 import org.apache.maven.archiva.repository.scanner.RepositoryContentConsumers;
 import org.apache.maven.archiva.scheduled.ArchivaTaskScheduler;
 import org.apache.maven.archiva.scheduled.tasks.DatabaseTask;
@@ -98,6 +109,19 @@ public class AdministrationServiceImplTest
     private DatabaseCleanupConsumer cleanupIndexConsumer;
     
     private DatabaseCleanupConsumer cleanupDbConsumer;
+    
+    // delete artifact    
+    private MockControl repoFactoryControl;
+    
+    private RepositoryContentFactory repositoryFactory;
+    
+    private MockControl artifactDaoControl;
+    
+    private ArtifactDAO artifactDao;
+    
+    private MockControl cleanupControl;
+    
+    private DatabaseCleanupConsumer cleanupConsumer;
         
     protected void setUp()
         throws Exception
@@ -137,11 +161,25 @@ public class AdministrationServiceImplTest
         processArtifactConsumer = ( DatabaseUnprocessedArtifactConsumer ) unprocessedConsumersControl.getMock();
         processPomConsumer = ( DatabaseUnprocessedArtifactConsumer ) unprocessedConsumersControl.getMock();
         
+        // delete artifact
+        repoFactoryControl = MockClassControl.createControl( RepositoryContentFactory.class );
+        repositoryFactory = ( RepositoryContentFactory ) repoFactoryControl.getMock();
+        
+        artifactDaoControl = MockControl.createControl( ArtifactDAO.class );
+        artifactDao = ( ArtifactDAO ) artifactDaoControl.getMock();
+                
+        cleanupControl = MockClassControl.createControl( DatabaseCleanupConsumer.class );
+        cleanupConsumer = ( DatabaseCleanupConsumer ) cleanupControl.getMock();
+                
         service = new AdministrationServiceImpl();
         service.setArchivaConfiguration( archivaConfig );
         service.setRepoConsumersUtil( repoConsumersUtil );     
         service.setDbConsumersUtil( dbConsumersUtil );
         service.setTaskScheduler( taskScheduler );
+        service.setRepoFactory( repositoryFactory );
+        service.setArtifactDAO( artifactDao );
+        service.setCleanupArtifacts( cleanupConsumer );
+        service.setCleanupProjects( cleanupConsumer );
     }
   
 /* Tests for database consumers  */
@@ -420,19 +458,37 @@ public class AdministrationServiceImplTest
 
 /* Tests for delete artifact  */
     
-    /*   public void testDeleteArtifactArtifactExists()
+    public void testDeleteM2ArtifactArtifactExists()
         throws Exception
     {
+        File file = new File( getBasedir(), "/target/test-classes/default-repo/" ); 
+        assertTrue( file.exists() );
+        
+        ManagedRepositoryConfiguration managedRepo = createManagedRepo( "internal", "default", "Internal Repository", true, false );
+        managedRepo.setLocation( file.getAbsolutePath() );
+        
         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
-        configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ),
-                                       createManagedRepo( "internal", "default", "Internal Repository", true, false ) );
+        configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ), managedRepo );
         
-        // TODO 
-        // - mock checking of artifact existence in the repo
-        // - mock artifact delete
+        ManagedDefaultRepositoryContent repoContent = new ManagedDefaultRepositoryContent();
+        repoContent.setRepository( managedRepo );
+        
+        repoFactoryControl.expectAndReturn( repositoryFactory.getManagedRepositoryContent( "internal" ), repoContent );
+                
+        List<ArchivaArtifact> artifacts = getArtifacts();
         
+        artifactDao.queryArtifacts( null );
+        artifactDaoControl.setMatcher( MockControl.ALWAYS_MATCHER );
+        artifactDaoControl.setReturnValue( artifacts );
+        
+        cleanupConsumer.processArchivaArtifact( artifacts.get( 0 ) );
+        cleanupControl.setVoidCallable( 2 );
+                  
         archivaConfigControl.replay();
         configControl.replay();
+        repoFactoryControl.replay();    
+        artifactDaoControl.replay();
+        cleanupControl.replay();
        
         try
         {
@@ -440,29 +496,115 @@ public class AdministrationServiceImplTest
             assertTrue( success ); 
         }
         catch ( Exception e )
-        {
+        {            
             fail( "An exception should not have been thrown." );
         }
         
         archivaConfigControl.verify();
         configControl.verify();
+        repoFactoryControl.verify();
+        artifactDaoControl.verify();
+        cleanupControl.verify();
+        
+        assertFalse( new File( getBasedir(), "/target/test-classes/default-repo/org/apache/archiva/archiva-test/1.0" ).exists() );
+        assertTrue( new File( getBasedir(), "/target/test-classes/default-repo/org/apache/archiva/archiva-test/1.1" ).exists() );
     }
     
+    public void testDeleteM1ArtifactArtifactExists()
+        throws Exception
+    {
+        MockControl fileTypesControl = MockClassControl.createControl( FileTypes.class );
+        FileTypes fileTypes = ( FileTypes ) fileTypesControl.getMock();
+        
+        MockControl pathParserControl = MockClassControl.createControl( PathParser.class );
+        PathParser parser = ( PathParser ) pathParserControl.getMock();
+        
+        File file = new File( getBasedir(), "/target/test-classes/legacy-repo/" ); 
+        assertTrue( file.exists() );
+        
+        ManagedRepositoryConfiguration managedRepo = createManagedRepo( "internal", "legacy", "Internal Repository", true, false );
+        managedRepo.setLocation( file.getAbsolutePath() );
+        
+        archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
+        configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ), managedRepo );
+                
+        ManagedLegacyRepositoryContent repoContent = new ManagedLegacyRepositoryContent();
+        repoContent.setRepository( managedRepo );
+        repoContent.setFileTypes( fileTypes );
+        repoContent.setLegacyPathParser( parser );
+                
+        repoFactoryControl.expectAndReturn( repositoryFactory.getManagedRepositoryContent( "internal" ), repoContent );
+        
+        recordInManagedLegacyRepoContent( fileTypesControl, fileTypes, pathParserControl, parser );
+        
+        List<ArchivaArtifact> artifacts = getArtifacts();
+        
+        artifactDao.queryArtifacts( null );
+        artifactDaoControl.setMatcher( MockControl.ALWAYS_MATCHER );
+        artifactDaoControl.setReturnValue( artifacts );
+                
+        cleanupConsumer.processArchivaArtifact( artifacts.get( 0 ) );
+        cleanupControl.setVoidCallable( 2 );
+        
+        archivaConfigControl.replay();
+        configControl.replay();
+        repoFactoryControl.replay();
+        artifactDaoControl.replay();
+        cleanupControl.replay();
+        fileTypesControl.replay();
+        pathParserControl.replay();
+       
+        try
+        {
+            boolean success = service.deleteArtifact( "internal", "org.apache.archiva", "archiva-test", "1.0" );
+            assertTrue( success ); 
+        }
+        catch ( Exception e )
+        {
+            fail( "An exception should not have been thrown." );
+        }
+        
+        archivaConfigControl.verify();
+        configControl.verify();
+        repoFactoryControl.verify();
+        artifactDaoControl.verify();
+        cleanupControl.verify();
+        fileTypesControl.verify();
+        pathParserControl.verify();
+        
+        assertFalse( new File( getBasedir(), "/target/test-classes/legacy-repo/org.apache.archiva/jars/archiva-test-1.0.jar" ).exists() );
+        assertFalse( new File( getBasedir(), "/target/test-classes/legacy-repo/org.apache.archiva/poms/archiva-test-1.0.pom" ).exists() );
+        
+        assertTrue( new File( getBasedir(), "/target/test-classes/legacy-repo/org.apache.archiva/jars/archiva-test-1.1.jar" ).exists() );
+        assertTrue( new File( getBasedir(), "/target/test-classes/legacy-repo/org.apache.archiva/jars/archiva-diff-1.0.jar" ).exists() );
+        assertTrue( new File( getBasedir(), "/target/test-classes/legacy-repo/org.apache.archiva/poms/archiva-test-1.1.pom" ).exists() );
+        assertTrue( new File( getBasedir(), "/target/test-classes/legacy-repo/org.apache.archiva/poms/archiva-diff-1.0.pom" ).exists() );
+    }
+
     public void testDeleteArtifactArtifactDoesNotExist()
         throws Exception
     {
+        File file = new File( getBasedir(), "/target/test-classes/default-repo/" ); 
+        assertTrue( file.exists() );
+        
+        ManagedRepositoryConfiguration managedRepo = createManagedRepo( "internal", "default", "Internal Repository", true, false );
+        managedRepo.setLocation( file.getAbsolutePath() );
+        
         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
-        configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ),
-                                       createManagedRepo( "internal", "default", "Internal Repository", true, false ) );
+        configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ), managedRepo );
         
-        // TODO mock checking of artifact existence in the repo
+        ManagedDefaultRepositoryContent repoContent = new ManagedDefaultRepositoryContent();
+        repoContent.setRepository( managedRepo );
+        
+        repoFactoryControl.expectAndReturn( repositoryFactory.getManagedRepositoryContent( "internal" ), repoContent );
         
         archivaConfigControl.replay();
         configControl.replay();
+        repoFactoryControl.replay();
        
         try
         {
-            service.deleteArtifact( "internal", "org.apache.archiva", "archiva-test", "1.0" );
+            service.deleteArtifact( "internal", "org.apache.archiva", "archiva-non-existing", "1.0" );
             fail( "An exception should have been thrown." );
         }
         catch ( Exception e )
@@ -472,20 +614,21 @@ public class AdministrationServiceImplTest
         
         archivaConfigControl.verify();
         configControl.verify();
+        repoFactoryControl.verify();
     }
     
     public void testDeleteArtifacRepositoryDoesNotExist()
         throws Exception
-    {
+    {   
         archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
-        configControl.expectAndReturn( config.findManagedRepositoryById( "internal" ), null );
+        configControl.expectAndReturn( config.findManagedRepositoryById( "non-existing-repo" ), null );
         
         archivaConfigControl.replay();
         configControl.replay();
        
         try
         {
-            service.deleteArtifact( "internal", "org.apache.archiva", "archiva-test", "1.0" );
+            service.deleteArtifact( "non-existing-repo", "org.apache.archiva", "archiva-test", "1.0" );
             fail( "An exception should have been thrown." );
         }
         catch ( Exception e )
@@ -496,7 +639,6 @@ public class AdministrationServiceImplTest
         archivaConfigControl.verify();
         configControl.verify();
     }
-    */
     
 /* Tests for repository scanning  */
     
@@ -757,4 +899,61 @@ public class AdministrationServiceImplTest
         unprocessedConsumersControl.expectAndReturn( processArtifactConsumer.getId(), "process-artifact" );
         unprocessedConsumersControl.expectAndReturn( processPomConsumer.getId(), "process-pom" );
     }    
+    
+    private List<ArchivaArtifact> getArtifacts()
+    {
+        List<ArchivaArtifact> artifacts = new ArrayList<ArchivaArtifact>();
+        
+        ArchivaArtifactModel model = new ArchivaArtifactModel();
+        model.setRepositoryId( "internal" );
+        model.setGroupId( "org.apache.archiva" );
+        model.setArtifactId( "archiva-test" );
+        model.setVersion( "1.0" );
+        model.setType( "jar" );
+        
+        ArchivaArtifact artifact = new ArchivaArtifact( model );
+        artifacts.add( artifact );
+        return artifacts;
+    }    
+    
+    private void recordInManagedLegacyRepoContent( MockControl fileTypesControl, FileTypes fileTypes,
+                                                   MockControl pathParserControl, PathParser parser )
+        throws LayoutException
+    {
+        fileTypesControl.expectAndReturn( fileTypes.matchesArtifactPattern( "org.apache.archiva/poms/archiva-test-1.0.pom" ), true );
+        fileTypesControl.expectAndReturn( fileTypes.matchesArtifactPattern( "org.apache.archiva/poms/archiva-test-1.1.pom" ), true );
+        fileTypesControl.expectAndReturn( fileTypes.matchesArtifactPattern( "org.apache.archiva/poms/archiva-diff-1.0.pom" ), true );
+        fileTypesControl.expectAndReturn( fileTypes.matchesArtifactPattern( "org.apache.archiva/jars/archiva-diff-1.0.jar" ), true );
+        fileTypesControl.expectAndReturn( fileTypes.matchesArtifactPattern( "org.apache.archiva/jars/archiva-test-1.0.jar" ), true );
+        fileTypesControl.expectAndReturn( fileTypes.matchesArtifactPattern( "org.apache.archiva/jars/archiva-test-1.1.jar" ), true );
+        
+        ArtifactReference aRef = createArtifactReference("archiva-test", "org.apache.archiva", "1.1", "pom");
+        pathParserControl.expectAndReturn( parser.toArtifactReference( "org.apache.archiva/poms/archiva-test-1.1.pom" ), aRef );
+        
+        aRef = createArtifactReference("archiva-test", "org.apache.archiva", "1.0", "pom");                
+        pathParserControl.expectAndReturn( parser.toArtifactReference( "org.apache.archiva/poms/archiva-test-1.0.pom" ), aRef );
+        
+        aRef = createArtifactReference("archiva-diff", "org.apache.archiva", "1.0", "pom");
+        pathParserControl.expectAndReturn( parser.toArtifactReference( "org.apache.archiva/poms/archiva-diff-1.0.pom" ), aRef );
+        
+        aRef = createArtifactReference("archiva-diff", "org.apache.archiva", "1.0", "jar");                
+        pathParserControl.expectAndReturn( parser.toArtifactReference( "org.apache.archiva/jars/archiva-diff-1.0.jar" ), aRef );
+        
+        aRef = createArtifactReference("archiva-test", "org.apache.archiva", "1.0", "jar");
+        pathParserControl.expectAndReturn( parser.toArtifactReference( "org.apache.archiva/jars/archiva-test-1.0.jar" ), aRef );
+        
+        aRef = createArtifactReference("archiva-test", "org.apache.archiva", "1.1", "jar");
+        pathParserControl.expectAndReturn( parser.toArtifactReference( "org.apache.archiva/jars/archiva-test-1.1.jar" ), aRef );
+    }
+
+    private ArtifactReference createArtifactReference( String artifactId, String groupId, String version, String type )
+    {
+        ArtifactReference aRef = new ArtifactReference();
+        aRef.setArtifactId( artifactId );
+        aRef.setGroupId( groupId );
+        aRef.setType( type );
+        aRef.setVersion( version );
+        
+        return aRef;
+    }
 }
\ No newline at end of file
diff --git a/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/default-repo/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.jar b/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/default-repo/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.jar
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/default-repo/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.jar.md5 b/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/default-repo/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.jar.md5
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/default-repo/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.jar.sha1 b/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/default-repo/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.jar.sha1
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/default-repo/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.pom b/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/default-repo/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.pom
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/default-repo/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.pom.md5 b/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/default-repo/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.pom.md5
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/default-repo/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.pom.sha1 b/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/default-repo/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.pom.sha1
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/default-repo/org/apache/archiva/archiva-test/1.0/maven-metadata.xml b/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/default-repo/org/apache/archiva/archiva-test/1.0/maven-metadata.xml
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/default-repo/org/apache/archiva/archiva-test/1.0/maven-metadata.xml.md5 b/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/default-repo/org/apache/archiva/archiva-test/1.0/maven-metadata.xml.md5
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/default-repo/org/apache/archiva/archiva-test/1.0/maven-metadata.xml.sha1 b/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/default-repo/org/apache/archiva/archiva-test/1.0/maven-metadata.xml.sha1
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/default-repo/org/apache/archiva/archiva-test/1.1/archiva-test-1.1.jar b/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/default-repo/org/apache/archiva/archiva-test/1.1/archiva-test-1.1.jar
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/default-repo/org/apache/archiva/archiva-test/1.1/archiva-test-1.1.pom b/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/default-repo/org/apache/archiva/archiva-test/1.1/archiva-test-1.1.pom
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/legacy-repo/org.apache.archiva/jars/archiva-diff-1.0.jar b/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/legacy-repo/org.apache.archiva/jars/archiva-diff-1.0.jar
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/legacy-repo/org.apache.archiva/jars/archiva-test-1.0.jar b/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/legacy-repo/org.apache.archiva/jars/archiva-test-1.0.jar
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/legacy-repo/org.apache.archiva/jars/archiva-test-1.1.jar b/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/legacy-repo/org.apache.archiva/jars/archiva-test-1.1.jar
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/legacy-repo/org.apache.archiva/poms/archiva-diff-1.0.pom b/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/legacy-repo/org.apache.archiva/poms/archiva-diff-1.0.pom
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/legacy-repo/org.apache.archiva/poms/archiva-test-1.0.pom b/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/legacy-repo/org.apache.archiva/poms/archiva-test-1.0.pom
new file mode 100644 (file)
index 0000000..e69de29
diff --git a/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/legacy-repo/org.apache.archiva/poms/archiva-test-1.1.pom b/MRM-124/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/legacy-repo/org.apache.archiva/poms/archiva-test-1.1.pom
new file mode 100644 (file)
index 0000000..e69de29