]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1282] fix problem with getArtifactVersions when there are multiple artifacts
authorBrett Porter <brett@apache.org>
Thu, 10 Dec 2009 02:30:01 +0000 (02:30 +0000)
committerBrett Porter <brett@apache.org>
Thu, 10 Dec 2009 02:30:01 +0000 (02:30 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@889062 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/plugins/metadata-repository-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java
archiva-modules/plugins/metadata-repository-file/src/test/java/org/apache/archiva/metadata/repository/file/FileMetadataRepositoryTest.java

index dbef173e766864998548186a47ac99f85f3e165f..a280f3c6c6ee32f217d4a3690976cadfaa5b6dfd 100644 (file)
@@ -30,6 +30,7 @@ import java.util.Collection;
 import java.util.Collections;
 import java.util.Date;
 import java.util.HashMap;
+import java.util.HashSet;
 import java.util.LinkedHashSet;
 import java.util.List;
 import java.util.Map;
@@ -691,7 +692,7 @@ public class FileMetadataRepository
 
         Properties properties = readOrCreateProperties( directory, PROJECT_VERSION_METADATA_KEY );
 
-        List<String> versions = new ArrayList<String>();
+        Set<String> versions = new HashSet<String>();
         for ( Map.Entry entry : properties.entrySet() )
         {
             String name = (String) entry.getKey();
index bf9365587a2819d57bbd490e8148d08b6f1167bb..b004a21b1684ca6e1be8ccaae52e661d95e6d75f 100644 (file)
@@ -25,6 +25,7 @@ import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Date;
+import java.util.HashSet;
 import java.util.List;
 import java.util.Map;
 
@@ -220,7 +221,21 @@ public class FileMetadataRepositoryTest
         repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 );
         repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact2 );
 
-        assertEquals( Arrays.asList( version2, version1 ),
+        assertEquals( new HashSet<String>( Arrays.asList( version2, version1 ) ),
+                      repository.getArtifactVersions( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT,
+                                                      TEST_PROJECT_VERSION ) );
+    }
+
+    public void testGetArtifactVersionsMultipleArtifactsSingleVersion()
+    {
+        ArtifactMetadata artifact1 = createArtifact();
+        artifact1.setId( TEST_PROJECT + "-" + TEST_PROJECT_VERSION + ".jar" );
+        ArtifactMetadata artifact2 = createArtifact();
+        artifact2.setId( TEST_PROJECT + "-" + TEST_PROJECT_VERSION + "-sources.jar" );
+        repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact1 );
+        repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact2 );
+
+        assertEquals( Collections.singleton( TEST_PROJECT_VERSION ),
                       repository.getArtifactVersions( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT,
                                                       TEST_PROJECT_VERSION ) );
     }