]> source.dussan.org Git - archiva.git/commitdiff
Adding tests for new repo content interface
authorMartin Stockhammer <martin_s@apache.org>
Sun, 8 Mar 2020 15:18:52 +0000 (16:18 +0100)
committerMartin Stockhammer <martin_s@apache.org>
Sun, 8 Mar 2020 15:18:52 +0000 (16:18 +0100)
archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/content/AbstractManagedRepositoryContentTest.java
archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/content/AbstractRepositoryContentTest.java
archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/content/ManagedDefaultRepositoryContentTest.java
archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/repository/maven/content/RemoteDefaultRepositoryContentTest.java

index be3f4bae94ecd87ea2ba6493aef81e76df993ec1..27d6426608924c022b59c051f97ba74328615fcd 100644 (file)
@@ -19,10 +19,15 @@ package org.apache.archiva.repository.maven.content;
  */
 
 import org.apache.archiva.repository.LayoutException;
+import org.apache.archiva.repository.content.ItemSelector;
+import org.apache.archiva.repository.content.base.ArchivaItemSelector;
+import org.junit.Test;
 
 import static org.junit.Assert.fail;
 
 /**
+ * Specific tests for ManagedRepositoryContent
+ *
  * @author Martin Stockhammer <martin_s@apache.org>
  */
 public abstract class AbstractManagedRepositoryContentTest extends AbstractRepositoryContentTest
@@ -36,11 +41,22 @@ public abstract class AbstractManagedRepositoryContentTest extends AbstractRepos
         {
             getManaged().toItem( path );
             fail(
-                "Should have thrown a LayoutException on the invalid path [" + path + "] because of [" + reason + "]" );
+                "toItem(path) should have thrown a LayoutException on the invalid path [" + path + "] because of [" + reason + "]" );
         }
         catch ( LayoutException e )
         {
             /* expected path */
         }
     }
+
+    @Test
+    public void testGetArtifactOnEmptyPath() {
+        ItemSelector selector = ArchivaItemSelector.builder( ).build( );
+        try {
+            getManaged( ).getArtifact( selector );
+            fail( "getArtifact(ItemSelector) with empty selector should throw IllegalArgumentException" );
+        } catch (IllegalArgumentException e) {
+            // Good
+        }
+    }
 }
index 34a8be4785b62a31de52f203a41fd6ad991977c9..75f2e1c9a0f2653bb567386aece8f04564854baa 100644 (file)
@@ -19,6 +19,7 @@ package org.apache.archiva.repository.maven.content;
  */
 
 import org.apache.archiva.model.ArtifactReference;
+import org.apache.archiva.repository.RepositoryContent;
 import org.apache.archiva.repository.maven.AbstractRepositoryLayerTestCase;
 import org.apache.archiva.repository.LayoutException;
 import org.apache.archiva.repository.ManagedRepositoryContent;
@@ -69,18 +70,21 @@ public abstract class AbstractRepositoryContentTest
     public void testBadPathTooShort()
     {
         assertBadPath( "invalid/invalid-1.0.jar", "path is too short" );
+        assertBadPathCi( "invalid/invalid-1.0.jar", "path is too short" );
     }
 
     @Test
     public void testBadPathVersionMismatchA()
     {
         assertBadPath( "invalid/invalid/1.0/invalid-2.0.jar", "version mismatch between path and artifact" );
+        assertBadPathCi( "invalid/invalid/1.0/invalid-2.0.jar", "version mismatch between path and artifact" );
     }
 
     @Test
     public void testBadPathVersionMismatchB()
     {
         assertBadPath( "invalid/invalid/1.0/invalid-1.0b.jar", "version mismatch between path and artifact" );
+        assertBadPathCi( "invalid/invalid/1.0/invalid-1.0b.jar", "version mismatch between path and artifact" );
     }
 
     @Test
@@ -88,6 +92,8 @@ public abstract class AbstractRepositoryContentTest
     {
         assertBadPath( "org/apache/maven/test/1.0-SNAPSHOT/wrong-artifactId-1.0-20050611.112233-1.jar",
                        "wrong artifact id" );
+        assertBadPathCi( "org/apache/maven/test/1.0-SNAPSHOT/wrong-artifactId-1.0-20050611.112233-1.jar",
+            "wrong artifact id" );
     }
 
     /**
@@ -372,13 +378,14 @@ public abstract class AbstractRepositoryContentTest
         assertLayoutCi( path, groupId, artifactId, version, classifier, type );
     }
 
+
     @Test
-    public void testToArtifactOnEmptyPath()
+    public void testToItemSelectorOnEmptyPath()
     {
         try
         {
-            toArtifactReference( "" );
-            fail( "Should have failed due to empty path." );
+            getContent( ).toItemSelector( "" );
+            fail( "toItemSelector() should have failed due to empty path." );
         }
         catch ( LayoutException e )
         {
@@ -387,12 +394,12 @@ public abstract class AbstractRepositoryContentTest
     }
 
     @Test
-    public void testToArtifactOnNullPath()
+    public void testToArtifactOnEmptyPath()
     {
         try
         {
-            toArtifactReference( null );
-            fail( "Should have failed due to null path." );
+            toArtifactReference( "" );
+            fail( "Should have failed due to empty path." );
         }
         catch ( LayoutException e )
         {
@@ -401,12 +408,12 @@ public abstract class AbstractRepositoryContentTest
     }
 
     @Test
-    public void testToArtifactReferenceOnEmptyPath()
+    public void testToArtifactOnNullPath()
     {
         try
         {
-            toArtifactReference( "" );
-            fail( "Should have failed due to empty path." );
+            toArtifactReference( null );
+            fail( "Should have failed due to null path." );
         }
         catch ( LayoutException e )
         {
@@ -415,12 +422,12 @@ public abstract class AbstractRepositoryContentTest
     }
 
     @Test
-    public void testToArtifactReferenceOnNullPath()
+    public void testToItemSelectorOnNullPath()
     {
         try
         {
-            toArtifactReference( null );
-            fail( "Should have failed due to null path." );
+            getContent().toItemSelector( null );
+            fail( "toItemSelector() should have failed due to null path." );
         }
         catch ( LayoutException e )
         {
@@ -636,4 +643,6 @@ public abstract class AbstractRepositoryContentTest
     protected abstract ItemSelector toItemSelector(String path) throws LayoutException;
 
     protected abstract ManagedRepositoryContent getManaged();
+
+    protected abstract RepositoryContent getContent( );
 }
index c58b159cc4b0ead311653631d2809a83fa70f109..ba66d57aa547a574809d60fd8f2d5a94a654e3d7 100644 (file)
@@ -29,6 +29,7 @@ import org.apache.archiva.model.VersionedReference;
 import org.apache.archiva.repository.EditableManagedRepository;
 import org.apache.archiva.repository.LayoutException;
 import org.apache.archiva.repository.ManagedRepositoryContent;
+import org.apache.archiva.repository.RepositoryContent;
 import org.apache.archiva.repository.content.ItemSelector;
 import org.apache.archiva.repository.maven.MavenManagedRepository;
 import org.apache.archiva.repository.maven.metadata.storage.ArtifactMappingProvider;
@@ -282,6 +283,12 @@ public class ManagedDefaultRepositoryContentTest
         return repoContent;
     }
 
+    @Override
+    protected RepositoryContent getContent( )
+    {
+        return repoContent;
+    }
+
     private Path setupRepoCopy( String source, String target) throws IOException
     {
         Path defaultRepo = getRepositoryPath( source );
index d8d08600f068351f31e788c1232afdac99b733c7..1666395d1461d5592c7d11420b844afa81b0d9ff 100644 (file)
@@ -23,6 +23,7 @@ import org.apache.archiva.repository.LayoutException;
 import org.apache.archiva.repository.ManagedRepositoryContent;
 import org.apache.archiva.repository.RemoteRepository;
 import org.apache.archiva.repository.RemoteRepositoryContent;
+import org.apache.archiva.repository.RepositoryContent;
 import org.apache.archiva.repository.content.ItemSelector;
 import org.apache.archiva.repository.maven.metadata.storage.ArtifactMappingProvider;
 import org.junit.Before;
@@ -73,6 +74,12 @@ public class RemoteDefaultRepositoryContentTest
         return null;
     }
 
+    @Override
+    protected RepositoryContent getContent( )
+    {
+        return repoContent;
+    }
+
     @Override
     protected String toPath( ArtifactReference reference )
     {