From: Martin Stockhammer Date: Sun, 9 Feb 2020 21:01:11 +0000 (+0100) Subject: Adding additional tests X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=af4c1a763b5a73a3f30f0b3dd1cd9de55d2b00ca;p=archiva.git Adding additional tests --- diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/content/maven2/AbstractDefaultRepositoryContent.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/content/maven2/AbstractDefaultRepositoryContent.java index d7d87c8b3..0919fcadb 100644 --- a/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/content/maven2/AbstractDefaultRepositoryContent.java +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/main/java/org/apache/archiva/repository/content/maven2/AbstractDefaultRepositoryContent.java @@ -141,6 +141,7 @@ public abstract class AbstractDefaultRepositoryContent implements RepositoryCont reference.getClassifier(), reference.getType() ); } + @Override public String toPath( ArtifactReference reference ) { if ( reference == null ) diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/ManagedDefaultRepositoryContentTest.java b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/ManagedDefaultRepositoryContentTest.java index 0e1a1cecb..c921adf0f 100644 --- a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/ManagedDefaultRepositoryContentTest.java +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/java/org/apache/archiva/metadata/repository/storage/maven2/ManagedDefaultRepositoryContentTest.java @@ -31,12 +31,15 @@ import org.apache.archiva.repository.EditableManagedRepository; import org.apache.archiva.repository.LayoutException; import org.apache.archiva.repository.content.maven2.ManagedDefaultRepositoryContent; import org.apache.archiva.repository.maven2.MavenManagedRepository; +import org.apache.commons.io.FileUtils; import org.junit.Before; import org.junit.Test; import javax.inject.Inject; import javax.inject.Named; +import java.io.IOException; import java.net.URISyntaxException; +import java.nio.file.Files; import java.nio.file.Path; import java.nio.file.Paths; import java.util.ArrayList; @@ -45,8 +48,7 @@ import java.util.Collections; import java.util.List; import java.util.Set; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; +import static org.junit.Assert.*; /** * ManagedDefaultRepositoryContentTest @@ -256,4 +258,103 @@ public class ManagedDefaultRepositoryContentTest { return repoContent.toPath( reference ); } + + private Path setupRepoCopy( String source, String target) throws IOException + { + Path defaultRepo = getRepositoryPath( source ); + Path newRepo = defaultRepo.getParent( ).resolve( target ); + FileUtils.copyDirectory( defaultRepo.toFile( ), newRepo.toFile( ) ); + + MavenManagedRepository repository = createRepository( "testRepo", "Unit Test Repo", newRepo ); + + FileType fileType = archivaConfiguration.getConfiguration().getRepositoryScanning().getFileTypes().get( 0 ); + fileType.addPattern( "**/*.xml" ); + assertEquals( FileTypes.ARTIFACTS, fileType.getId() ); + + fileTypes.afterConfigurationChange( null, "fileType", null ); + + repoContent = new ManagedDefaultRepositoryContent(repository, artifactMappingProviders, fileTypes, fileLockManager); + return newRepo; + + } + + @Test + public void testDeleteArtifactWithType() throws IOException + { + Path deleteRepo = setupRepoCopy( "delete-repository", "delete-repository-2" ); + assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar" ) ) ); + assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar" ) ) ); + assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.md5" ) ) ); + assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.sha1" ) ) ); + assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.pom" ) ) ); + + ArtifactReference ref = new ArtifactReference( ); + ref.setGroupId( "org.apache.maven" ); + ref.setArtifactId( "samplejar" ); + ref.setVersion( "1.0" ); + ref.setType( "jar" ); + + repoContent.deleteArtifact( ref ); + + assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar" ) ) ); + assertFalse( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar" ) ) ); + assertFalse( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.md5" ) ) ); + assertFalse( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.sha1" ) ) ); + assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.pom" ) ) ); + + + } + + + @Test + public void testDeleteArtifactWithClassifier() throws IOException + { + Path deleteRepo = setupRepoCopy( "default-repository", "default-repository-2" ); + assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar" ) ) ); + assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar.sha1" ) ) ); + assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar" ) ) ); + assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.md5" ) ) ); + assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.sha1" ) ) ); + assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.pom" ) ) ); + + ArtifactReference ref = new ArtifactReference( ); + ref.setGroupId( "org.apache.maven" ); + ref.setArtifactId( "samplejar" ); + ref.setVersion( "1.0" ); + ref.setClassifier( "source" ); + ref.setType( "jar" ); + + repoContent.deleteArtifact( ref ); + + assertFalse( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar" ) ) ); + assertFalse( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar.sha1" ) ) ); + assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar" ) ) ); + assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.md5" ) ) ); + assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.sha1" ) ) ); + assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.pom" ) ) ); + + } + + @Test + public void testDeleteArtifactWithoutType() throws IOException + { + Path deleteRepo = setupRepoCopy( "default-repository", "default-repository-2" ); + assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar" ) ) ); + assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar.sha1" ) ) ); + assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar" ) ) ); + assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.md5" ) ) ); + assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.jar.sha1" ) ) ); + assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0/samplejar-1.0.pom" ) ) ); + + ArtifactReference ref = new ArtifactReference( ); + ref.setGroupId( "org.apache.maven" ); + ref.setArtifactId( "samplejar" ); + ref.setVersion( "1.0" ); + + repoContent.deleteArtifact( ref ); + + assertFalse( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar/1.0" ) ) ); + assertTrue( Files.exists( deleteRepo.resolve( "org/apache/maven/samplejar" ) ) ); + + } } diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/resources/repositories/default-repository/org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/resources/repositories/default-repository/org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar new file mode 100644 index 000000000..54d190b23 --- /dev/null +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/resources/repositories/default-repository/org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar @@ -0,0 +1 @@ +dummy content. sample file only. diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/resources/repositories/default-repository/org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar.sha1 b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/resources/repositories/default-repository/org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar.sha1 new file mode 100644 index 000000000..a5c1a4c4f --- /dev/null +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/resources/repositories/default-repository/org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar.sha1 @@ -0,0 +1 @@ +754133cd9c36adef86d35b96c0e96e11a9c6bfc9 samplejar-1.0.jar diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/resources/repositories/default-repository/org/apache/maven/samplejar/1.0/samplejar-1.0.jar.md5 b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/resources/repositories/default-repository/org/apache/maven/samplejar/1.0/samplejar-1.0.jar.md5 new file mode 100644 index 000000000..a5c2bc901 --- /dev/null +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/resources/repositories/default-repository/org/apache/maven/samplejar/1.0/samplejar-1.0.jar.md5 @@ -0,0 +1 @@ +fd4275a6811332d67075ffd879d13d4a samplejar-1.0.jar diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/resources/repositories/default-repository/org/apache/maven/samplejar/1.0/samplejar-1.0.jar.sha1 b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/resources/repositories/default-repository/org/apache/maven/samplejar/1.0/samplejar-1.0.jar.sha1 new file mode 100644 index 000000000..a5c1a4c4f --- /dev/null +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/resources/repositories/default-repository/org/apache/maven/samplejar/1.0/samplejar-1.0.jar.sha1 @@ -0,0 +1 @@ +754133cd9c36adef86d35b96c0e96e11a9c6bfc9 samplejar-1.0.jar diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/resources/repositories/delete-repository/KEYS b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/resources/repositories/delete-repository/KEYS new file mode 100644 index 000000000..d3b34d5ad --- /dev/null +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/resources/repositories/delete-repository/KEYS @@ -0,0 +1 @@ +test KEYS file \ No newline at end of file diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/resources/repositories/delete-repository/org/apache/maven/A/1.0/A-1.0.pom b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/resources/repositories/delete-repository/org/apache/maven/A/1.0/A-1.0.pom new file mode 100644 index 000000000..202a0a448 --- /dev/null +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/resources/repositories/delete-repository/org/apache/maven/A/1.0/A-1.0.pom @@ -0,0 +1,28 @@ + + + + 4.0.0 + org.apache.maven + A + 1.0 + Maven Test Repository Artifact Discovery + war + diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/resources/repositories/delete-repository/org/apache/maven/A/1.0/A-1.0.war b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/resources/repositories/delete-repository/org/apache/maven/A/1.0/A-1.0.war new file mode 100644 index 000000000..54d190b23 --- /dev/null +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/resources/repositories/delete-repository/org/apache/maven/A/1.0/A-1.0.war @@ -0,0 +1 @@ +dummy content. sample file only. diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/resources/repositories/delete-repository/org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/resources/repositories/delete-repository/org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar new file mode 100644 index 000000000..54d190b23 --- /dev/null +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/resources/repositories/delete-repository/org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar @@ -0,0 +1 @@ +dummy content. sample file only. diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/resources/repositories/delete-repository/org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar.sha1 b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/resources/repositories/delete-repository/org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar.sha1 new file mode 100644 index 000000000..a5c1a4c4f --- /dev/null +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/resources/repositories/delete-repository/org/apache/maven/samplejar/1.0/samplejar-1.0-source.jar.sha1 @@ -0,0 +1 @@ +754133cd9c36adef86d35b96c0e96e11a9c6bfc9 samplejar-1.0.jar diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/resources/repositories/delete-repository/org/apache/maven/samplejar/1.0/samplejar-1.0.jar b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/resources/repositories/delete-repository/org/apache/maven/samplejar/1.0/samplejar-1.0.jar new file mode 100644 index 000000000..54d190b23 --- /dev/null +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/resources/repositories/delete-repository/org/apache/maven/samplejar/1.0/samplejar-1.0.jar @@ -0,0 +1 @@ +dummy content. sample file only. diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/resources/repositories/delete-repository/org/apache/maven/samplejar/1.0/samplejar-1.0.jar.md5 b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/resources/repositories/delete-repository/org/apache/maven/samplejar/1.0/samplejar-1.0.jar.md5 new file mode 100644 index 000000000..a5c2bc901 --- /dev/null +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/resources/repositories/delete-repository/org/apache/maven/samplejar/1.0/samplejar-1.0.jar.md5 @@ -0,0 +1 @@ +fd4275a6811332d67075ffd879d13d4a samplejar-1.0.jar diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/resources/repositories/delete-repository/org/apache/maven/samplejar/1.0/samplejar-1.0.jar.sha1 b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/resources/repositories/delete-repository/org/apache/maven/samplejar/1.0/samplejar-1.0.jar.sha1 new file mode 100644 index 000000000..a5c1a4c4f --- /dev/null +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/resources/repositories/delete-repository/org/apache/maven/samplejar/1.0/samplejar-1.0.jar.sha1 @@ -0,0 +1 @@ +754133cd9c36adef86d35b96c0e96e11a9c6bfc9 samplejar-1.0.jar diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/resources/repositories/delete-repository/org/apache/maven/samplejar/1.0/samplejar-1.0.pom b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/resources/repositories/delete-repository/org/apache/maven/samplejar/1.0/samplejar-1.0.pom new file mode 100644 index 000000000..6ab57d162 --- /dev/null +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/resources/repositories/delete-repository/org/apache/maven/samplejar/1.0/samplejar-1.0.pom @@ -0,0 +1,29 @@ + + + + 4.0.0 + org.apache.maven + C + 1.0 + Maven Test Repository Artifact Discovery + + + diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/resources/repositories/delete-repository/org/apache/maven/samplejar/2.0/samplejar-2.0.jar b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/resources/repositories/delete-repository/org/apache/maven/samplejar/2.0/samplejar-2.0.jar new file mode 100644 index 000000000..54d190b23 --- /dev/null +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/resources/repositories/delete-repository/org/apache/maven/samplejar/2.0/samplejar-2.0.jar @@ -0,0 +1 @@ +dummy content. sample file only. diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/resources/repositories/delete-repository/org/apache/maven/samplejar/2.0/samplejar-2.0.pom b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/resources/repositories/delete-repository/org/apache/maven/samplejar/2.0/samplejar-2.0.pom new file mode 100644 index 000000000..a959980df --- /dev/null +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/resources/repositories/delete-repository/org/apache/maven/samplejar/2.0/samplejar-2.0.pom @@ -0,0 +1,29 @@ + + + + 4.0.0 + org.apache.maven + C + 1.0 + Maven Test Repository Artifact Discovery + + jar + diff --git a/archiva-modules/archiva-maven/archiva-maven-repository/src/test/resources/repositories/delete-repository/org/apache/maven/samplejar/maven-metadata.xml b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/resources/repositories/delete-repository/org/apache/maven/samplejar/maven-metadata.xml new file mode 100644 index 000000000..89de35f4e --- /dev/null +++ b/archiva-modules/archiva-maven/archiva-maven-repository/src/test/resources/repositories/delete-repository/org/apache/maven/samplejar/maven-metadata.xml @@ -0,0 +1,35 @@ + + + + org.apache.maven + samplejar + 6.0-SNAPSHOT + + 2.0 + 6.0-SNAPSHOT + + 26 + + + 6.0-SNAPSHOT + 6.0-20060311.093250-41 + 6.0-20060311.183228-42 + 6.0-20060311.183228-40 + 6.0-20060311.183228-37 + 6.0-20060311.183228-30 + 6.0-20060311.183228-29 + 6.0-20060311.183228-6 + 6.0-20060311.183228-9 + 6.0-20060311.183228-10 + 6.0-20060313.001659-43 + 6.0-20060313.001659-41 + 6.0-20060313.001659-38 + 6.0-20060313.001659-31 + 6.0-20060313.001659-30 + 6.0-20060313.001659-7 + 6.0-20060313.001659-10 + 6.0-20060313.001659-11 + + 20060313010719 + +