From 122145013ef5d19d2c8b955c7f9008ed4b2ed879 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Wed, 26 Mar 2014 02:41:06 +0000 Subject: [PATCH] should return null if no facets found git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1581639 13f79535-47bb-0310-9956-ffa450edef68 --- .../repository/AbstractMetadataRepositoryTest.java | 8 ++++---- .../cassandra/CassandraMetadataRepository.java | 13 ++++++++++--- .../cassandra/CassandraMetadataRepositoryTest.java | 2 ++ 3 files changed, 16 insertions(+), 7 deletions(-) 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 4734a2a71..06add9a0f 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 @@ -743,14 +743,14 @@ public abstract class AbstractMetadataRepositoryTest throws Exception { List facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID ); - assertTrue( facets.isEmpty() ); - assertNull( repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) ); + assertThat( facets ).isNotNull().isEmpty(); + assertThat( repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) ).isNull(); repository.removeMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ); facets = repository.getMetadataFacets( TEST_REPO_ID, TEST_FACET_ID ); - assertTrue( facets.isEmpty() ); - assertNull( repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) ); + assertThat( facets ).isNotNull().isEmpty(); + assertThat( repository.getMetadataFacet( TEST_REPO_ID, TEST_FACET_ID, TEST_NAME ) ).isNull(); } @Test diff --git a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepository.java b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepository.java index 6e4794432..08a1a7c4a 100644 --- a/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepository.java +++ b/archiva-modules/plugins/metadata-store-cassandra/src/main/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepository.java @@ -1300,7 +1300,8 @@ public class CassandraMetadataRepository addInsertion( dependencyMutator, keyDependency, cfDependency, "version", dependency.getVersion() ); - } dependencyMutator.execute(); + } + dependencyMutator.execute(); } protected void removeDependencies( String projectVersionMetadataKey ) @@ -1334,7 +1335,8 @@ public class CassandraMetadataRepository for ( Row row : result.get() ) { - ColumnFamilyResult columnFamilyResult = this.dependencyTemplate.queryColumns( row.getKey() ); + ColumnFamilyResult columnFamilyResult = + this.dependencyTemplate.queryColumns( row.getKey() ); Dependency dependency = new Dependency(); dependency.setClassifier( columnFamilyResult.getString( "classifier" ) ); @@ -1595,7 +1597,12 @@ public class CassandraMetadataRepository .execute(); MetadataFacet metadataFacet = metadataFacetFactory.createMetadataFacet( repositoryId, name ); - Map map = new HashMap( result.get().getCount() ); + int size = result.get().getCount(); + if ( size < 1 ) + { + return null; + } + Map map = new HashMap( size ); for ( Row row : result.get() ) { ColumnSlice columnSlice = row.getColumnSlice(); diff --git a/archiva-modules/plugins/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepositoryTest.java b/archiva-modules/plugins/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepositoryTest.java index e43f5afce..89ac59886 100644 --- a/archiva-modules/plugins/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepositoryTest.java +++ b/archiva-modules/plugins/metadata-store-cassandra/src/test/java/org/apache/archiva/metadata/repository/cassandra/CassandraMetadataRepositoryTest.java @@ -80,8 +80,10 @@ public class CassandraMetadataRepositoryTest { cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(), cassandraArchivaManager.getProjectFamilyName() ); + cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(), cassandraArchivaManager.getNamespaceFamilyName() ); + cassandraArchivaManager.getCluster().truncate( cassandraArchivaManager.getKeyspace().getKeyspaceName(), cassandraArchivaManager.getRepositoryFamilyName() );