diff --git a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/DeleteArtifactAction.java b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/DeleteArtifactAction.java index c91dae1f7..83ff863b3 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/DeleteArtifactAction.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/DeleteArtifactAction.java @@ -339,7 +339,7 @@ public class DeleteArtifactAction if ( !VersionUtil.isSnapshot( version ) ) { - if ( metadata.getReleasedVersion().equals( version ) ) + if ( metadata.getReleasedVersion() != null && metadata.getReleasedVersion().equals( version ) ) { metadata.setReleasedVersion( latestVersion ); } @@ -404,4 +404,19 @@ public class DeleteArtifactAction { return listeners; } + + public void setRepositoryFactory( RepositoryContentFactory repositoryFactory ) + { + this.repositoryFactory = repositoryFactory; + } + + public void setConfiguration( ArchivaConfiguration configuration ) + { + this.configuration = configuration; + } + + public void setMetadataRepository( MetadataRepository metadataRepository ) + { + this.metadataRepository = metadataRepository; + } } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/DeleteArtifactActionTest.java b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/DeleteArtifactActionTest.java index 45446707b..cc478358e 100644 --- a/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/DeleteArtifactActionTest.java +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/DeleteArtifactActionTest.java @@ -20,17 +20,137 @@ package org.apache.maven.archiva.web.action; */ import com.opensymphony.xwork2.Action; +import org.apache.archiva.metadata.model.ArtifactMetadata; +import org.apache.archiva.metadata.repository.MetadataRepository; +import org.apache.commons.lang.StringUtils; +import org.apache.maven.archiva.configuration.ArchivaConfiguration; +import org.apache.maven.archiva.configuration.Configuration; +import org.apache.maven.archiva.configuration.ManagedRepositoryConfiguration; +import org.apache.maven.archiva.repository.ManagedRepositoryContent; +import org.apache.maven.archiva.repository.RepositoryContentFactory; +import org.apache.maven.archiva.repository.content.ManagedDefaultRepositoryContent; import org.codehaus.plexus.spring.PlexusInSpringTestCase; +import org.easymock.MockControl; +import org.easymock.classextension.MockClassControl; + +import java.io.File; +import java.util.ArrayList; +import java.util.Collection; public class DeleteArtifactActionTest extends PlexusInSpringTestCase { + private DeleteArtifactAction action; + + private ArchivaConfiguration configuration; + + private MockControl configurationControl; + + private RepositoryContentFactory repositoryFactory; + + private MockControl repositoryFactoryControl; + + private MetadataRepository metadataRepository; + + private MockControl metadataRepositoryControl; + + private static final String REPOSITORY_ID = "test-repo"; + + private static final String GROUP_ID = "org.apache.archiva"; + + private static final String ARTIFACT_ID = "npe-metadata"; + + private static final String VERSION = "1.0"; + + private static final String REPO_LOCATION = getBasedir() + "/target/test-classes/test-repo"; + + @Override + protected void setUp() + throws Exception + { + super.setUp(); + + action = (DeleteArtifactAction) lookup( Action.class.getName(), "deleteArtifactAction" ); + assertNotNull( action ); + + configurationControl = MockControl.createControl( ArchivaConfiguration.class ); + configuration = ( ArchivaConfiguration ) configurationControl.getMock(); + + repositoryFactoryControl = MockClassControl.createControl( RepositoryContentFactory.class ); + repositoryFactory = ( RepositoryContentFactory ) repositoryFactoryControl.getMock(); + + metadataRepositoryControl = MockControl.createControl( MetadataRepository.class ); + metadataRepository = ( MetadataRepository ) metadataRepositoryControl.getMock(); + + action.setConfiguration( configuration ); + action.setRepositoryFactory( repositoryFactory ); + action.setMetadataRepository( metadataRepository ); + } + + @Override + protected void tearDown() + throws Exception + { + action = null; + + super.tearDown(); + } + public void testGetListeners() throws Exception { - DeleteArtifactAction action = (DeleteArtifactAction) lookup( Action.class.getName(), "deleteArtifactAction" ); - assertNotNull( action ); assertNotNull( action.getListeners() ); assertFalse( action.getListeners().isEmpty() ); } + + public void testNPEInDeleteArtifact() + throws Exception + { + action.setGroupId( GROUP_ID ); + action.setArtifactId( ARTIFACT_ID ); + action.setVersion( VERSION ); + action.setRepositoryId( REPOSITORY_ID ); + + Configuration config = createConfiguration(); + + ManagedRepositoryContent repoContent = new ManagedDefaultRepositoryContent(); + repoContent.setRepository( config.findManagedRepositoryById( REPOSITORY_ID ) ); + + configurationControl.expectAndReturn( configuration.getConfiguration(), config ); + repositoryFactoryControl.expectAndReturn( repositoryFactory.getManagedRepositoryContent( REPOSITORY_ID ), repoContent ); + metadataRepositoryControl.expectAndReturn( metadataRepository.getArtifacts( REPOSITORY_ID, GROUP_ID, ARTIFACT_ID, VERSION ), + new ArrayList() ); + + configurationControl.replay(); + repositoryFactoryControl.replay(); + metadataRepositoryControl.replay(); + + action.doDelete(); + + String artifactPath = REPO_LOCATION + "/" + StringUtils.replace( GROUP_ID, ".", "/" ) + "/" + + StringUtils.replace( ARTIFACT_ID, ".", "/" ) + "/" + VERSION + "/" + ARTIFACT_ID + "-" + VERSION; + + assertFalse( new File( artifactPath + ".jar" ).exists() ); + assertFalse( new File( artifactPath + ".jar.sha1" ).exists() ); + assertFalse( new File( artifactPath + ".jar.md5" ).exists() ); + + assertFalse( new File( artifactPath + ".pom" ).exists() ); + assertFalse( new File( artifactPath + ".pom.sha1" ).exists() ); + assertFalse( new File( artifactPath + ".pom.md5" ).exists() ); + } + + private Configuration createConfiguration() + { + ManagedRepositoryConfiguration managedRepo = new ManagedRepositoryConfiguration(); + managedRepo.setId( REPOSITORY_ID ); + managedRepo.setName( "Test Repository" ); + + managedRepo.setLocation( REPO_LOCATION ); + managedRepo.setReleases( true ); + + Configuration config = new Configuration(); + config.addManagedRepository( managedRepo ); + + return config; + } } diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/1.0/npe-metadata-1.0.jar b/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/1.0/npe-metadata-1.0.jar new file mode 100644 index 000000000..0464407c2 Binary files /dev/null and b/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/1.0/npe-metadata-1.0.jar differ diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/1.0/npe-metadata-1.0.jar.md5 b/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/1.0/npe-metadata-1.0.jar.md5 new file mode 100644 index 000000000..29ab7cbb5 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/1.0/npe-metadata-1.0.jar.md5 @@ -0,0 +1 @@ +5b0e72a002c047e2f200855f6d904a7e \ No newline at end of file diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/1.0/npe-metadata-1.0.jar.sha1 b/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/1.0/npe-metadata-1.0.jar.sha1 new file mode 100644 index 000000000..898bb7519 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/1.0/npe-metadata-1.0.jar.sha1 @@ -0,0 +1 @@ +9b3ed9b1a8f1639bcc6a6986930d71a2996ba2fe \ No newline at end of file diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/1.0/npe-metadata-1.0.pom b/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/1.0/npe-metadata-1.0.pom new file mode 100644 index 000000000..143bd719d --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/1.0/npe-metadata-1.0.pom @@ -0,0 +1,8 @@ + + + 4.0.0 + org.apache.archiva + npe-metadata + 1.0 + diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/1.0/npe-metadata-1.0.pom.md5 b/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/1.0/npe-metadata-1.0.pom.md5 new file mode 100644 index 000000000..c835b0b76 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/1.0/npe-metadata-1.0.pom.md5 @@ -0,0 +1 @@ +30124c5194a639f12a2fb01e7aa5a952 \ No newline at end of file diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/1.0/npe-metadata-1.0.pom.sha1 b/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/1.0/npe-metadata-1.0.pom.sha1 new file mode 100644 index 000000000..274871d24 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/1.0/npe-metadata-1.0.pom.sha1 @@ -0,0 +1 @@ +83bee18c83a6f4964026587cc4ccffe653c45d0c \ No newline at end of file diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/maven-metadata.xml b/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/maven-metadata.xml new file mode 100644 index 000000000..c999862ff --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/maven-metadata.xml @@ -0,0 +1,12 @@ + + + org.apache.archiva + npe-metadata + 1.0 + + + 1.0 + + 20101105071933 + + diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/maven-metadata.xml.md5 b/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/maven-metadata.xml.md5 new file mode 100644 index 000000000..c73f5bc10 --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/maven-metadata.xml.md5 @@ -0,0 +1 @@ +6b4a71798c8fcb45ee0411cc9cf68064 \ No newline at end of file diff --git a/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/maven-metadata.xml.sha1 b/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/maven-metadata.xml.sha1 new file mode 100644 index 000000000..76091f5fa --- /dev/null +++ b/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/maven-metadata.xml.sha1 @@ -0,0 +1 @@ +33c6dbdfdb263c394082d56e349d36e893ead06f \ No newline at end of file