]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1303] fixed npe in delete artifact + unit test
authorMaria Odea B. Ching <oching@apache.org>
Fri, 5 Nov 2010 11:22:06 +0000 (11:22 +0000)
committerMaria Odea B. Ching <oching@apache.org>
Fri, 5 Nov 2010 11:22:06 +0000 (11:22 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1031518 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/DeleteArtifactAction.java
archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/DeleteArtifactActionTest.java
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 with mode: 0644]
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 with mode: 0644]
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 with mode: 0644]
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 with mode: 0644]
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 with mode: 0644]
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 with mode: 0644]
archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/maven-metadata.xml [new file with mode: 0644]
archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/maven-metadata.xml.md5 [new file with mode: 0644]
archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/maven-metadata.xml.sha1 [new file with mode: 0644]

index c91dae1f721684e28e7795666d3e10534dd97b45..83ff863b3352e309ef4470a7987fe4240229ce52 100644 (file)
@@ -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;
+    }
 }
index 45446707b4b3c3c785a632bc827ad6e08e2993d0..cc478358e562d90b99e8c8684054321bf896556e 100644 (file)
@@ -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
 {
-    public void testGetListeners()
+    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
     {
-        DeleteArtifactAction action = (DeleteArtifactAction) lookup( Action.class.getName(), "deleteArtifactAction" );
+        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
+    {
         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<ArtifactMetadata>() );
+
+        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 (file)
index 0000000..0464407
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 (file)
index 0000000..29ab7cb
--- /dev/null
@@ -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 (file)
index 0000000..898bb75
--- /dev/null
@@ -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 (file)
index 0000000..143bd71
--- /dev/null
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<project xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" xmlns="http://maven.apache.org/POM/4.0.0"
+    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
+  <modelVersion>4.0.0</modelVersion>
+  <groupId>org.apache.archiva</groupId>
+  <artifactId>npe-metadata</artifactId>
+  <version>1.0</version>
+</project>
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 (file)
index 0000000..c835b0b
--- /dev/null
@@ -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 (file)
index 0000000..274871d
--- /dev/null
@@ -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 (file)
index 0000000..c999862
--- /dev/null
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<metadata>
+  <groupId>org.apache.archiva</groupId>
+  <artifactId>npe-metadata</artifactId>
+  <version>1.0</version>
+  <versioning>
+    <versions>
+      <version>1.0</version>
+    </versions>
+    <lastUpdated>20101105071933</lastUpdated>
+  </versioning>
+</metadata>
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 (file)
index 0000000..c73f5bc
--- /dev/null
@@ -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 (file)
index 0000000..76091f5
--- /dev/null
@@ -0,0 +1 @@
+33c6dbdfdb263c394082d56e349d36e893ead06f
\ No newline at end of file