From eeed20ed3604a898910b347cecd19a6d8793e210 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Fri, 1 Jun 2012 23:48:01 +0000 Subject: fix an issue with not removing project version when removing an artifact from Metadatarepository git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1345397 13f79535-47bb-0310-9956-ffa450edef68 --- .../repository/AbstractMetadataRepositoryTest.java | 46 ++++++++++++++++++++++ 1 file changed, 46 insertions(+) (limited to 'archiva-modules/metadata/metadata-repository-api/src/test') diff --git a/archiva-modules/metadata/metadata-repository-api/src/test/java/org/apache/archiva/metadata/repository/AbstractMetadataRepositoryTest.java b/archiva-modules/metadata/metadata-repository-api/src/test/java/org/apache/archiva/metadata/repository/AbstractMetadataRepositoryTest.java index afaf1f149..da9099aaa 100644 --- a/archiva-modules/metadata/metadata-repository-api/src/test/java/org/apache/archiva/metadata/repository/AbstractMetadataRepositoryTest.java +++ b/archiva-modules/metadata/metadata-repository-api/src/test/java/org/apache/archiva/metadata/repository/AbstractMetadataRepositoryTest.java @@ -32,8 +32,11 @@ import org.apache.archiva.metadata.model.Organization; import org.apache.archiva.metadata.model.ProjectMetadata; import org.apache.archiva.metadata.model.ProjectVersionMetadata; import org.apache.archiva.metadata.model.Scm; +import org.fest.assertions.Assertions; import org.junit.Test; import org.junit.runner.RunWith; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import org.springframework.test.context.ContextConfiguration; import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @@ -64,6 +67,8 @@ public abstract class AbstractMetadataRepositoryTest private static final String TEST_PROJECT_VERSION = "1.0"; + private static final String TEST_PROJECT_VERSION_2_0 = "2.0"; + private static final String TEST_FACET_ID = "test-facet-id"; private static final String TEST_NAME = "test/name"; @@ -78,6 +83,8 @@ public abstract class AbstractMetadataRepositoryTest private static final String TEST_METADATA_VALUE = "test-metadata"; + protected Logger log = LoggerFactory.getLogger( getClass() ); + protected static Map createTestMetadataFacetFactories() { Map factories = new HashMap(); @@ -603,6 +610,7 @@ public abstract class AbstractMetadataRepositoryTest public void testGetMetadataFacetsWhenEmpty() throws Exception { + List facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID ); assertTrue( facets.isEmpty() ); } @@ -1049,10 +1057,27 @@ public abstract class AbstractMetadataRepositoryTest assertEquals( Collections.singletonList( artifact ), new ArrayList( repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ) ) ); + repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION_2_0, artifact ); + + Collection versions = repository.getProjectVersions( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT ); + + log.info( "versions {}", versions ); + + Assertions.assertThat( versions ).isNotNull().isNotEmpty().hasSize( 2 ).contains( "1.0", "2.0" ); + repository.removeArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact.getId() ); + versions = repository.getProjectVersions( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT ); + + log.info( "versions {}", versions ); + + Assertions.assertThat( versions ).isNotNull().isNotEmpty().hasSize( 1 ).contains( "2.0" ); + assertTrue( repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ).isEmpty() ); + + Assertions.assertThat( repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, + TEST_PROJECT_VERSION_2_0 ) ).isNotEmpty().hasSize( 1 ); } @Test @@ -1093,6 +1118,27 @@ public abstract class AbstractMetadataRepositoryTest assertTrue( repository.getRootNamespaces( TEST_REPO_ID ).isEmpty() ); } + + @Test + public void deleteVersion() + throws Exception + { + ArtifactMetadata artifact = createArtifact(); + artifact.addFacet( new TestMetadataFacet( "value" ) ); + + repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact ); + + repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact ); + + assertEquals( Collections.singletonList( artifact ), new ArrayList( + repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ) ) ); + + repository.removeArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact.getId() ); + + assertTrue( + repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ).isEmpty() ); + } + private static ProjectMetadata createProject() { return createProject( TEST_NAMESPACE ); -- cgit v1.2.3