diff options
author | Olivier Lamy <olamy@apache.org> | 2014-03-24 01:36:57 +0000 |
---|---|---|
committer | Olivier Lamy <olamy@apache.org> | 2014-03-24 01:36:57 +0000 |
commit | ed0db11f65e5c67c68c8b5246f7c13c55f249502 (patch) | |
tree | 7c61e42660ffe66e8dc3bcd9d7f992daaa31e8c0 /archiva-modules | |
parent | 72ddf2322fd1e95a3b18ef541fdee8a15437a4a3 (diff) | |
download | archiva-ed0db11f65e5c67c68c8b5246f7c13c55f249502.tar.gz archiva-ed0db11f65e5c67c68c8b5246f7c13c55f249502.zip |
prevent ClassCastException as now return a Collection rather than a List
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1580693 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'archiva-modules')
2 files changed, 40 insertions, 17 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 c33c8d676..20f8f9664 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 @@ -270,7 +270,7 @@ public abstract class AbstractMetadataRepositoryTest MailingList mailingList = new MailingList(); mailingList.setName( "Foo List" ); mailingList.setOtherArchives( Arrays.asList( "other archive" ) ); - metadata.setMailingLists( Arrays.asList( mailingList ) ); + metadata.setMailingLists( Arrays.asList( mailingList ) ); Scm scm = new Scm(); scm.setConnection( "connection" ); @@ -321,7 +321,8 @@ public abstract class AbstractMetadataRepositoryTest mailingList = metadata.getMailingLists().get( 0 ); assertEquals( "Foo List", mailingList.getName() ); //assertEquals( Collections.singletonList( "other archive" ), mailingList.getOtherArchives() ); - Assertions.assertThat( mailingList.getOtherArchives() ).isNotNull().isNotEmpty().hasSize( 1 ).contains( "other archive" ); + Assertions.assertThat( mailingList.getOtherArchives() ).isNotNull().isNotEmpty().hasSize( 1 ).contains( + "other archive" ); assertEquals( "connection", metadata.getScm().getConnection() ); assertEquals( "dev conn", metadata.getScm().getDeveloperConnection() ); @@ -1010,13 +1011,13 @@ public abstract class AbstractMetadataRepositoryTest // test it restricts to the appropriate repository assertEquals( Collections.singletonList( artifact ), - repository.getArtifactsByChecksum( TEST_REPO_ID, TEST_SHA1 ) ); - assertEquals( Collections.singletonList( secondArtifact ), - repository.getArtifactsByChecksum( OTHER_REPO_ID, TEST_SHA1 ) ); + new ArrayList<ArtifactMetadata>( repository.getArtifactsByChecksum( TEST_REPO_ID, TEST_SHA1 ) ) ); + assertEquals( Collections.singletonList( secondArtifact ), new ArrayList<ArtifactMetadata>( + repository.getArtifactsByChecksum( OTHER_REPO_ID, TEST_SHA1 ) ) ); assertEquals( Collections.singletonList( artifact ), - repository.getArtifactsByChecksum( TEST_REPO_ID, TEST_MD5 ) ); + new ArrayList<ArtifactMetadata>( repository.getArtifactsByChecksum( TEST_REPO_ID, TEST_MD5 ) ) ); assertEquals( Collections.singletonList( secondArtifact ), - repository.getArtifactsByChecksum( OTHER_REPO_ID, TEST_MD5 ) ); + new ArrayList<ArtifactMetadata>( repository.getArtifactsByChecksum( OTHER_REPO_ID, TEST_MD5 ) ) ); } @Test @@ -1103,7 +1104,7 @@ public abstract class AbstractMetadataRepositoryTest repository.save(); assertEquals( Collections.singletonList( artifact ), - repository.getArtifactsByChecksum( TEST_REPO_ID, TEST_MD5 ) ); + new ArrayList<ArtifactMetadata>( repository.getArtifactsByChecksum( TEST_REPO_ID, TEST_MD5 ) ) ); } @Test @@ -1115,7 +1116,7 @@ public abstract class AbstractMetadataRepositoryTest repository.save(); assertEquals( Collections.singletonList( artifact ), - repository.getArtifactsByChecksum( TEST_REPO_ID, TEST_SHA1 ) ); + new ArrayList<ArtifactMetadata>( repository.getArtifactsByChecksum( TEST_REPO_ID, TEST_SHA1 ) ) ); } @Test @@ -1129,9 +1130,9 @@ public abstract class AbstractMetadataRepositoryTest repository.save(); assertEquals( Collections.singletonList( artifact ), - repository.getArtifactsByChecksum( TEST_REPO_ID, TEST_SHA1 ) ); + new ArrayList<ArtifactMetadata>( repository.getArtifactsByChecksum( TEST_REPO_ID, TEST_SHA1 ) ) ); assertEquals( Collections.singletonList( artifact ), - repository.getArtifactsByChecksum( TEST_REPO_ID, TEST_MD5 ) ); + new ArrayList<ArtifactMetadata>( repository.getArtifactsByChecksum( TEST_REPO_ID, TEST_MD5 ) ) ); } @Test @@ -1164,8 +1165,9 @@ public abstract class AbstractMetadataRepositoryTest ArtifactMetadata artifact = createArtifact(); repository.updateArtifact( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION, artifact ); - Collection<ArtifactMetadata> artifactsByChecksum = repository.getArtifactsByChecksum( TEST_REPO_ID, "not checksum" ); - assertEquals( Collections.<ArtifactMetadata>emptyList(), artifactsByChecksum ); + Collection<ArtifactMetadata> artifactsByChecksum = + repository.getArtifactsByChecksum( TEST_REPO_ID, "not checksum" ); + Assertions.assertThat( artifactsByChecksum ).isNotNull().isEmpty(); } 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 831686269..42b0e80fc 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 @@ -1688,7 +1688,7 @@ public class CassandraMetadataRepository } - protected ArtifactMetadata mapArtifactMetadataLongColumnSlice( ColumnSlice columnSlice ) + protected ArtifactMetadata mapArtifactMetadataLongColumnSlice( ColumnSlice<String,Long> columnSlice ) { ArtifactMetadata artifactMetadata = new ArtifactMetadata(); artifactMetadata.setNamespace( getAsStringValue( columnSlice, "namespaceId" ) ); @@ -1698,7 +1698,7 @@ public class CassandraMetadataRepository artifactMetadata.setMd5( getAsStringValue( columnSlice, "md5" ) ); artifactMetadata.setProject( getAsStringValue( columnSlice, "project" ) ); artifactMetadata.setProjectVersion( getAsStringValue( columnSlice, "projectVersion" ) ); - artifactMetadata.setRepositoryId( getStringValue( columnSlice, "repositoryName" ) ); + artifactMetadata.setRepositoryId( getAsStringValue( columnSlice, "repositoryName" ) ); artifactMetadata.setSha1( getAsStringValue( columnSlice, "sha1" ) ); artifactMetadata.setVersion( getAsStringValue( columnSlice, "version" ) ); Long whenGathered = getLongValue( columnSlice, "whenGathered" ); @@ -1709,6 +1709,27 @@ public class CassandraMetadataRepository return artifactMetadata; } + protected ArtifactMetadata mapArtifactMetadataStringColumnSlice( ColumnSlice<String,String> columnSlice ) + { + ArtifactMetadata artifactMetadata = new ArtifactMetadata(); + artifactMetadata.setNamespace( getStringValue( columnSlice, "namespaceId" ) ); + artifactMetadata.setSize( getAsLongValue( columnSlice, "size" ) ); + artifactMetadata.setId( getStringValue( columnSlice, "id" ) ); + artifactMetadata.setFileLastModified( getAsLongValue( columnSlice, "fileLastModified" ) ); + artifactMetadata.setMd5( getStringValue( columnSlice, "md5" ) ); + artifactMetadata.setProject( getStringValue( columnSlice, "project" ) ); + artifactMetadata.setProjectVersion( getStringValue( columnSlice, "projectVersion" ) ); + artifactMetadata.setRepositoryId( getStringValue( columnSlice, "repositoryName" ) ); + artifactMetadata.setSha1( getStringValue( columnSlice, "sha1" ) ); + artifactMetadata.setVersion( getStringValue( columnSlice, "version" ) ); + Long whenGathered = getAsLongValue( columnSlice, "whenGathered" ); + if ( whenGathered != null ) + { + artifactMetadata.setWhenGathered( new Date( whenGathered ) ); + } + return artifactMetadata; + } + protected void populateFacets( final ArtifactMetadata artifactMetadata ) { /* final List<MetadataFacetModel> metadataFacetModels = new ArrayList<MetadataFacetModel>(); @@ -1792,7 +1813,7 @@ public class CassandraMetadataRepository if ( StringUtils.equals( repositoryName, repositoryId ) ) { - artifactMetadataMap.put( row.getKey(), mapArtifactMetadataLongColumnSlice( columnSlice ) ); + artifactMetadataMap.put( row.getKey(), mapArtifactMetadataStringColumnSlice( columnSlice ) ); } } @@ -1813,7 +1834,7 @@ public class CassandraMetadataRepository if ( StringUtils.equals( repositoryName, repositoryId ) ) { - artifactMetadataMap.put( row.getKey(), mapArtifactMetadataLongColumnSlice( columnSlice ) ); + artifactMetadataMap.put( row.getKey(), mapArtifactMetadataStringColumnSlice( columnSlice ) ); } } |