From a400db0c397421b46e8a30f94fcbe5a7ee3139a1 Mon Sep 17 00:00:00 2001 From: "Maria Odea B. Ching" Date: Mon, 13 Oct 2008 06:13:27 +0000 Subject: [PATCH] - implement deleteArtifact in AdministrationServiceImpl - updated test cases for artifact delete git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-124@703920 13f79535-47bb-0310-9956-ffa450edef68 --- .../AbstractLegacyRepositoryContent.java | 5 + .../ManagedDefaultRepositoryContent.java | 4 + .../ManagedLegacyRepositoryContent.java | 5 + .../ArtifactVersionsConstraint.java | 12 +- .../ArtifactVersionsConstraintTest.java | 4 +- .../services/AdministrationServiceImpl.java | 123 +++++++++- .../AdministrationServiceImplTest.java | 229 ++++++++++++++++-- .../archiva-test/1.0/archiva-test-1.0.jar | 0 .../archiva-test/1.0/archiva-test-1.0.jar.md5 | 0 .../1.0/archiva-test-1.0.jar.sha1 | 0 .../archiva-test/1.0/archiva-test-1.0.pom | 0 .../archiva-test/1.0/archiva-test-1.0.pom.md5 | 0 .../1.0/archiva-test-1.0.pom.sha1 | 0 .../archiva-test/1.0/maven-metadata.xml | 0 .../archiva-test/1.0/maven-metadata.xml.md5 | 0 .../archiva-test/1.0/maven-metadata.xml.sha1 | 0 .../archiva-test/1.1/archiva-test-1.1.jar | 0 .../archiva-test/1.1/archiva-test-1.1.pom | 0 .../jars/archiva-diff-1.0.jar | 0 .../jars/archiva-test-1.0.jar | 0 .../jars/archiva-test-1.1.jar | 0 .../poms/archiva-diff-1.0.pom | 0 .../poms/archiva-test-1.0.pom | 0 .../poms/archiva-test-1.1.pom | 0 24 files changed, 356 insertions(+), 26 deletions(-) create mode 100644 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 create mode 100644 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 create mode 100644 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 create mode 100644 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 create mode 100644 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 create mode 100644 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 create mode 100644 archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/default-repo/org/apache/archiva/archiva-test/1.0/maven-metadata.xml create mode 100644 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 create mode 100644 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 create mode 100644 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 create mode 100644 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 create mode 100644 archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/legacy-repo/org.apache.archiva/jars/archiva-diff-1.0.jar create mode 100644 archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/legacy-repo/org.apache.archiva/jars/archiva-test-1.0.jar create mode 100644 archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/legacy-repo/org.apache.archiva/jars/archiva-test-1.1.jar create mode 100644 archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/legacy-repo/org.apache.archiva/poms/archiva-diff-1.0.pom create mode 100644 archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/legacy-repo/org.apache.archiva/poms/archiva-test-1.0.pom create mode 100644 archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/legacy-repo/org.apache.archiva/poms/archiva-test-1.1.pom diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractLegacyRepositoryContent.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractLegacyRepositoryContent.java index f135d5aad..5ff3c783b 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractLegacyRepositoryContent.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/AbstractLegacyRepositoryContent.java @@ -117,4 +117,9 @@ public abstract class AbstractLegacyRepositoryContent // Default process. return type + "s"; } + + public void setLegacyPathParser( PathParser parser ) + { + this.legacyPathParser = parser; + } } diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedDefaultRepositoryContent.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedDefaultRepositoryContent.java index 53bfc1bcb..93545f3dd 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedDefaultRepositoryContent.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedDefaultRepositoryContent.java @@ -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() diff --git a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedLegacyRepositoryContent.java b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedLegacyRepositoryContent.java index 6b59d86f3..03216fd8a 100644 --- a/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedLegacyRepositoryContent.java +++ b/archiva-modules/archiva-base/archiva-repository-layer/src/main/java/org/apache/maven/archiva/repository/content/ManagedLegacyRepositoryContent.java @@ -454,4 +454,9 @@ public class ManagedLegacyRepositoryContent } } } + + public void setFileTypes( FileTypes fileTypes ) + { + this.filetypes = fileTypes; + } } diff --git a/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/ArtifactVersionsConstraint.java b/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/ArtifactVersionsConstraint.java index c7eee23a5..4307022ba 100644 --- a/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/ArtifactVersionsConstraint.java +++ b/archiva-modules/archiva-database/src/main/java/org/apache/maven/archiva/database/constraints/ArtifactVersionsConstraint.java @@ -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; } diff --git a/archiva-modules/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/ArtifactVersionsConstraintTest.java b/archiva-modules/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/ArtifactVersionsConstraintTest.java index f7fa5b4ff..d00c6dcf5 100644 --- a/archiva-modules/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/ArtifactVersionsConstraintTest.java +++ b/archiva-modules/archiva-database/src/test/java/org/apache/maven/archiva/database/constraints/ArtifactVersionsConstraintTest.java @@ -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 ) diff --git a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java index 35ff650a1..fafc92361 100644 --- a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java +++ b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImpl.java @@ -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 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; } } diff --git a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java index 0a9b30859..59d24519c 100644 --- a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java +++ b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/AdministrationServiceImplTest.java @@ -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 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 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 getArtifacts() + { + List artifacts = new ArrayList(); + + 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/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/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 index 000000000..e69de29bb diff --git a/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/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 index 000000000..e69de29bb diff --git a/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/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 index 000000000..e69de29bb diff --git a/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/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 index 000000000..e69de29bb diff --git a/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/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 index 000000000..e69de29bb diff --git a/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/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 index 000000000..e69de29bb diff --git a/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/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 index 000000000..e69de29bb diff --git a/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/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 index 000000000..e69de29bb diff --git a/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/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 index 000000000..e69de29bb diff --git a/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/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 index 000000000..e69de29bb diff --git a/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/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 index 000000000..e69de29bb diff --git a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/legacy-repo/org.apache.archiva/jars/archiva-diff-1.0.jar b/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 index 000000000..e69de29bb diff --git a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/legacy-repo/org.apache.archiva/jars/archiva-test-1.0.jar b/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 index 000000000..e69de29bb diff --git a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/legacy-repo/org.apache.archiva/jars/archiva-test-1.1.jar b/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 index 000000000..e69de29bb diff --git a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/legacy-repo/org.apache.archiva/poms/archiva-diff-1.0.pom b/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 index 000000000..e69de29bb diff --git a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/legacy-repo/org.apache.archiva/poms/archiva-test-1.0.pom b/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 index 000000000..e69de29bb diff --git a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/resources/legacy-repo/org.apache.archiva/poms/archiva-test-1.1.pom b/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 index 000000000..e69de29bb -- 2.39.5