archiva-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From och...@apache.org
Subject svn commit: r1031518 - in /archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src: main/java/org/apache/maven/archiva/web/action/ test/java/org/apache/maven/archiva/web/action/ test/resources/test-repo/ test/resources/test-repo/org/ test/resource...
Date Fri, 05 Nov 2010 11:22:06 GMT
Author: oching
Date: Fri Nov  5 11:22:06 2010
New Revision: 1031518

URL: http://svn.apache.org/viewvc?rev=1031518&view=rev
Log:
[MRM-1303] fixed npe in delete artifact + unit test

Added:
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/1.0/
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/1.0/npe-metadata-1.0.jar
  (with props)
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/1.0/npe-metadata-1.0.jar.md5
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/1.0/npe-metadata-1.0.jar.sha1
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/1.0/npe-metadata-1.0.pom
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/1.0/npe-metadata-1.0.pom.md5
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/1.0/npe-metadata-1.0.pom.sha1
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/maven-metadata.xml
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/maven-metadata.xml.md5
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/maven-metadata.xml.sha1
Modified:
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/DeleteArtifactAction.java
    archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/DeleteArtifactActionTest.java

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/DeleteArtifactAction.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/DeleteArtifactAction.java?rev=1031518&r1=1031517&r2=1031518&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/DeleteArtifactAction.java
(original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/main/java/org/apache/maven/archiva/web/action/DeleteArtifactAction.java
Fri Nov  5 11:22:06 2010
@@ -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;
+    }
 }

Modified: archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/DeleteArtifactActionTest.java
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/DeleteArtifactActionTest.java?rev=1031518&r1=1031517&r2=1031518&view=diff
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/DeleteArtifactActionTest.java
(original)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/java/org/apache/maven/archiva/web/action/DeleteArtifactActionTest.java
Fri Nov  5 11:22:06 2010
@@ -20,17 +20,137 @@ package org.apache.maven.archiva.web.act
  */
 
 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;
+    }
 }

Added: archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/1.0/npe-metadata-1.0.jar
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/1.0/npe-metadata-1.0.jar?rev=1031518&view=auto
==============================================================================
Binary file - no diff available.

Propchange: archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/1.0/npe-metadata-1.0.jar
------------------------------------------------------------------------------
    svn:mime-type = application/octet-stream

Added: archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/1.0/npe-metadata-1.0.jar.md5
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/1.0/npe-metadata-1.0.jar.md5?rev=1031518&view=auto
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/1.0/npe-metadata-1.0.jar.md5
(added)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/1.0/npe-metadata-1.0.jar.md5
Fri Nov  5 11:22:06 2010
@@ -0,0 +1 @@
+5b0e72a002c047e2f200855f6d904a7e
\ No newline at end of file

Added: archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/1.0/npe-metadata-1.0.jar.sha1
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/1.0/npe-metadata-1.0.jar.sha1?rev=1031518&view=auto
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/1.0/npe-metadata-1.0.jar.sha1
(added)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/1.0/npe-metadata-1.0.jar.sha1
Fri Nov  5 11:22:06 2010
@@ -0,0 +1 @@
+9b3ed9b1a8f1639bcc6a6986930d71a2996ba2fe
\ No newline at end of file

Added: archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/1.0/npe-metadata-1.0.pom
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/1.0/npe-metadata-1.0.pom?rev=1031518&view=auto
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/1.0/npe-metadata-1.0.pom
(added)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/1.0/npe-metadata-1.0.pom
Fri Nov  5 11:22:06 2010
@@ -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>

Added: archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/1.0/npe-metadata-1.0.pom.md5
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/1.0/npe-metadata-1.0.pom.md5?rev=1031518&view=auto
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/1.0/npe-metadata-1.0.pom.md5
(added)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/1.0/npe-metadata-1.0.pom.md5
Fri Nov  5 11:22:06 2010
@@ -0,0 +1 @@
+30124c5194a639f12a2fb01e7aa5a952
\ No newline at end of file

Added: archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/1.0/npe-metadata-1.0.pom.sha1
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/1.0/npe-metadata-1.0.pom.sha1?rev=1031518&view=auto
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/1.0/npe-metadata-1.0.pom.sha1
(added)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/1.0/npe-metadata-1.0.pom.sha1
Fri Nov  5 11:22:06 2010
@@ -0,0 +1 @@
+83bee18c83a6f4964026587cc4ccffe653c45d0c
\ No newline at end of file

Added: archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/maven-metadata.xml
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/maven-metadata.xml?rev=1031518&view=auto
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/maven-metadata.xml
(added)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/maven-metadata.xml
Fri Nov  5 11:22:06 2010
@@ -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>

Added: archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/maven-metadata.xml.md5
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/maven-metadata.xml.md5?rev=1031518&view=auto
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/maven-metadata.xml.md5
(added)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/maven-metadata.xml.md5
Fri Nov  5 11:22:06 2010
@@ -0,0 +1 @@
+6b4a71798c8fcb45ee0411cc9cf68064
\ No newline at end of file

Added: archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/maven-metadata.xml.sha1
URL: http://svn.apache.org/viewvc/archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/maven-metadata.xml.sha1?rev=1031518&view=auto
==============================================================================
--- archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/maven-metadata.xml.sha1
(added)
+++ archiva/trunk/archiva-modules/archiva-web/archiva-webapp/src/test/resources/test-repo/org/apache/archiva/npe-metadata/maven-metadata.xml.sha1
Fri Nov  5 11:22:06 2010
@@ -0,0 +1 @@
+33c6dbdfdb263c394082d56e349d36e893ead06f
\ No newline at end of file



Mime
View raw message