From e7bc35db81e879f19a7846098d1f6eed31e1b142 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Thu, 11 Oct 2012 22:43:15 +0000 Subject: [PATCH] add unit test for new method in MetadataRepository and fix compilation for some impls/mocks git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1397345 13f79535-47bb-0310-9956-ffa450edef68 --- .../repository/TestMetadataRepository.java | 6 ++++++ .../mock/MockRepositorySessionFactory.java | 7 +++++++ .../repository/TestMetadataRepository.java | 6 ++++++ .../mock/MockRepositorySessionFactory.java | 7 +++++++ .../mock/MockRepositorySessionFactory.java | 7 +++++++ .../NewArtifactsRssFeedProcessorTest.java | 6 ++++++ .../memory/TestMetadataRepository.java | 6 ++++++ .../repository/TestMetadataRepository.java | 6 ++++++ .../AbstractMetadataRepositoryTest.java | 20 ++++++++++++++++++- .../repository/TestMetadataRepository.java | 6 ++++++ .../file/FileMetadataRepository.java | 19 +++++++++++++++++- 11 files changed, 94 insertions(+), 2 deletions(-) diff --git a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java index b3effd9c9..36ab43c3d 100644 --- a/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java +++ b/archiva-modules/archiva-base/archiva-consumers/archiva-core-consumers/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java @@ -201,4 +201,10 @@ public class TestMetadataRepository { } + + public void removeProjectVersion( String repoId, String namespace, String projectId, String projectVersion ) + throws MetadataRepositoryException + { + + } } diff --git a/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/mock/MockRepositorySessionFactory.java b/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/mock/MockRepositorySessionFactory.java index cdaee822e..2f1d8aa85 100644 --- a/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/mock/MockRepositorySessionFactory.java +++ b/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/mock/MockRepositorySessionFactory.java @@ -260,6 +260,13 @@ public class MockRepositorySessionFactory { } + + public void removeProjectVersion( String repoId, String namespace, String projectId, + String projectVersion ) + throws MetadataRepositoryException + { + + } }; } }; diff --git a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java index cfc5a9732..8e7013db3 100644 --- a/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java +++ b/archiva-modules/archiva-base/archiva-proxy/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java @@ -206,4 +206,10 @@ public class TestMetadataRepository { } + + public void removeProjectVersion( String repoId, String namespace, String projectId, String projectVersion ) + throws MetadataRepositoryException + { + + } } diff --git a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/mock/MockRepositorySessionFactory.java b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/mock/MockRepositorySessionFactory.java index 9be74fa74..ad8928c23 100644 --- a/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/mock/MockRepositorySessionFactory.java +++ b/archiva-modules/archiva-base/archiva-repository-admin/archiva-repository-admin-default/src/test/java/org/apache/archiva/admin/mock/MockRepositorySessionFactory.java @@ -260,6 +260,13 @@ public class MockRepositorySessionFactory { } + + public void removeProjectVersion( String repoId, String namespace, String projectId, + String projectVersion ) + throws MetadataRepositoryException + { + + } }; } }; diff --git a/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/test/java/org/apache/archiva/scheduler/indexing/mock/MockRepositorySessionFactory.java b/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/test/java/org/apache/archiva/scheduler/indexing/mock/MockRepositorySessionFactory.java index 217338775..09297f1ec 100644 --- a/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/test/java/org/apache/archiva/scheduler/indexing/mock/MockRepositorySessionFactory.java +++ b/archiva-modules/archiva-scheduler/archiva-scheduler-indexing/src/test/java/org/apache/archiva/scheduler/indexing/mock/MockRepositorySessionFactory.java @@ -260,6 +260,13 @@ public class MockRepositorySessionFactory { } + + public void removeProjectVersion( String repoId, String namespace, String projectId, + String projectVersion ) + throws MetadataRepositoryException + { + + } }; } }; diff --git a/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessorTest.java b/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessorTest.java index d53314266..5978c7c98 100644 --- a/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessorTest.java +++ b/archiva-modules/archiva-web/archiva-rss/src/test/java/org/apache/archiva/rss/processor/NewArtifactsRssFeedProcessorTest.java @@ -337,5 +337,11 @@ public class NewArtifactsRssFeedProcessorTest { } + + public void removeProjectVersion( String repoId, String namespace, String projectId, String projectVersion ) + throws MetadataRepositoryException + { + + } } } diff --git a/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/webtest/memory/TestMetadataRepository.java b/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/webtest/memory/TestMetadataRepository.java index 8702ee366..d5a4da2ed 100644 --- a/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/webtest/memory/TestMetadataRepository.java +++ b/archiva-modules/archiva-web/archiva-web-common/src/test/java/org/apache/archiva/webtest/memory/TestMetadataRepository.java @@ -241,4 +241,10 @@ public class TestMetadataRepository { } + + public void removeProjectVersion( String repoId, String namespace, String projectId, String projectVersion ) + throws MetadataRepositoryException + { + + } } \ No newline at end of file diff --git a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java index f15ac0e63..089bcc025 100644 --- a/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java +++ b/archiva-modules/archiva-web/archiva-webdav/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java @@ -202,4 +202,10 @@ public class TestMetadataRepository { } + + public void removeProjectVersion( String repoId, String namespace, String projectId, String projectVersion ) + throws MetadataRepositoryException + { + + } } 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 ca400cc9e..55aed9ce7 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 @@ -1132,7 +1132,7 @@ public abstract class AbstractMetadataRepositoryTest } @Test - public void deleteVersion() + public void deleteArtifact() throws Exception { ArtifactMetadata artifact = createArtifact(); @@ -1151,6 +1151,24 @@ public abstract class AbstractMetadataRepositoryTest repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ).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( 1, repository.getProjectVersions( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT ).size() ); + + repository.removeProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ); + + assertEquals( 0, repository.getProjectVersions( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT ).size() ); + } + @Test public void deleteSnapshotVersion() throws Exception diff --git a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java index 3f615c09b..214e6a81e 100644 --- a/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java +++ b/archiva-modules/plugins/maven2-repository/src/test/java/org/apache/archiva/metadata/repository/TestMetadataRepository.java @@ -217,4 +217,10 @@ public class TestMetadataRepository { } + + public void removeProjectVersion( String repoId, String namespace, String projectId, String projectVersion ) + throws MetadataRepositoryException + { + + } } \ No newline at end of file diff --git a/archiva-modules/plugins/metadata-store-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java b/archiva-modules/plugins/metadata-store-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java index 3294ab895..87c3b6711 100644 --- a/archiva-modules/plugins/metadata-store-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java +++ b/archiva-modules/plugins/metadata-store-file/src/main/java/org/apache/archiva/metadata/repository/file/FileMetadataRepository.java @@ -703,7 +703,6 @@ public class FileMetadataRepository * @param namespace * @param project * @param projectVersion - * @param projectId * @param metadataFacet will remove artifacts which have this {@link MetadataFacet} using equals * @throws MetadataRepositoryException */ @@ -1163,6 +1162,24 @@ public class FileMetadataRepository return projectVersions; } + + public void removeProjectVersion( String repoId, String namespace, String projectId, String projectVersion ) + throws MetadataRepositoryException + { + File directory = new File( getDirectory( repoId ), namespace + "/" + projectId + "/" + projectVersion ); + if ( directory.exists() ) + { + try + { + FileUtils.deleteDirectory( directory ); + } + catch ( IOException e ) + { + throw new MetadataRepositoryException( e.getMessage(), e ); + } + } + } + private void writeProperties( Properties properties, File directory, String propertiesKey ) throws IOException {