fix unit test when searching project version

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1581640 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Olivier Lamy 2014-03-26 02:41:20 +00:00
parent 122145013e
commit 3ff5c718fb
2 changed files with 35 additions and 19 deletions

View File

@ -203,8 +203,9 @@ public abstract class AbstractMetadataRepositoryTest
public void testGetArtifactOnly() public void testGetArtifactOnly()
throws Exception throws Exception
{ {
assertEquals( Collections.<ArtifactMetadata>emptyList(), new ArrayList<ArtifactMetadata>( assertThat( new ArrayList<ArtifactMetadata>(
repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ) ) ); repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT,
TEST_PROJECT_VERSION ) ) ).isNotNull().isEmpty();
assertThat( assertThat(
repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ) ).isNull(); repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ) ).isNull();
assertThat( repository.getProject( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT ) ).isNull(); assertThat( repository.getProject( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT ) ).isNull();
@ -217,8 +218,8 @@ public abstract class AbstractMetadataRepositoryTest
Collection<ArtifactMetadata> artifacts = Collection<ArtifactMetadata> artifacts =
repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION ); repository.getArtifacts( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
assertEquals( Collections.singletonList( metadata ), new ArrayList<ArtifactMetadata>( artifacts ) ); //assertEquals( Collections.singletonList( metadata ), new ArrayList<ArtifactMetadata>( artifacts ) );
assertThat( artifacts ).containsExactly( metadata );
// test that namespace, project and project version is also constructed // test that namespace, project and project version is also constructed
assertThat( repository.getRootNamespaces( TEST_REPO_ID ) ).isNotNull().isNotEmpty().contains( assertThat( repository.getRootNamespaces( TEST_REPO_ID ) ).isNotNull().isNotEmpty().contains(

View File

@ -1005,11 +1005,29 @@ public class CassandraMetadataRepository
final String projectId, final String projectVersion ) final String projectId, final String projectVersion )
throws MetadataResolutionException throws MetadataResolutionException
{ {
String key = new ProjectVersionMetadataModel.KeyBuilder().withRepository( repoId ).withNamespace(
namespace ).withProjectId( projectId ).withId( projectVersion ).build(); Keyspace keyspace = cassandraArchivaManager.getKeyspace();
StringSerializer ss = StringSerializer.get();
QueryResult<OrderedRows<String, String, String>> result = HFactory //
.createRangeSlicesQuery( keyspace, ss, ss, ss ) //
.setColumnFamily( cassandraArchivaManager.getProjectVersionMetadataFamilyName() ) //
.setColumnNames( "projectVersion" ) //
.addEqualsExpression( "repositoryName", repoId ) //
.addEqualsExpression( "namespaceId", namespace ) //
.addEqualsExpression( "projectId", projectId ) //
.addEqualsExpression( "projectVersion", projectVersion ) //
.execute();
if ( result.get().getCount() < 1 )
{
return null;
}
String key = result.get().iterator().next().getKey();
ColumnFamilyResult<String, String> columnFamilyResult = ColumnFamilyResult<String, String> columnFamilyResult =
this.projectVersionMetadataModelTemplate.queryColumns( key ); this.projectVersionMetadataModelTemplate.queryColumns( key );
if ( !columnFamilyResult.hasResults() ) if ( !columnFamilyResult.hasResults() )
{ {
return null; return null;
@ -1062,10 +1080,7 @@ public class CassandraMetadataRepository
projectVersionMetadata.setDependencies( getDependencies( key ) ); projectVersionMetadata.setDependencies( getDependencies( key ) );
// facets // facets
StringSerializer ss = StringSerializer.get(); result = HFactory //
Keyspace keyspace = cassandraArchivaManager.getKeyspace();
QueryResult<OrderedRows<String, String, String>> result = HFactory //
.createRangeSlicesQuery( keyspace, ss, ss, ss ) // .createRangeSlicesQuery( keyspace, ss, ss, ss ) //
.setColumnFamily( cassandraArchivaManager.getMetadataFacetFamilyName() ) // .setColumnFamily( cassandraArchivaManager.getMetadataFacetFamilyName() ) //
.setColumnNames( "facetId", "key", "value", "name" ) // .setColumnNames( "facetId", "key", "value", "name" ) //
@ -1416,18 +1431,17 @@ public class CassandraMetadataRepository
.execute(); .execute();
} }
key = new ProjectVersionMetadataModel.KeyBuilder().withRepository( repositoryId ).withNamespace( key = new ProjectVersionMetadataModel.KeyBuilder() //
namespace ).withProjectId( projectId ).withId( projectVersion ).build(); .withRepository( repositoryId ) //
.withNamespace( namespace ) //
.withProjectId( projectId ) //
.withId( artifactMeta.getId() ) //
.build();
exists = this.projectVersionMetadataModelTemplate.isColumnsExist( key ); exists = this.projectVersionMetadataModelTemplate.isColumnsExist( key );
if ( !exists ) if ( !exists )
{ {
ProjectVersionMetadataModel projectVersionMetadataModel = new ProjectVersionMetadataModel();
projectVersionMetadataModel.setProjectId( projectId );
projectVersionMetadataModel.setId( projectVersion );
projectVersionMetadataModel.setNamespace( namespace );
String cf = this.cassandraArchivaManager.getProjectVersionMetadataFamilyName(); String cf = this.cassandraArchivaManager.getProjectVersionMetadataFamilyName();
projectVersionMetadataModelTemplate.createMutator() // projectVersionMetadataModelTemplate.createMutator() //
@ -1435,6 +1449,7 @@ public class CassandraMetadataRepository
.addInsertion( key, cf, column( "repositoryName", repositoryId ) ) // .addInsertion( key, cf, column( "repositoryName", repositoryId ) ) //
.addInsertion( key, cf, column( "projectVersion", projectVersion ) ) // .addInsertion( key, cf, column( "projectVersion", projectVersion ) ) //
.addInsertion( key, cf, column( "projectId", projectId ) ) // .addInsertion( key, cf, column( "projectId", projectId ) ) //
.addInsertion( key, cf, column( "version", artifactMeta.getVersion() ) ) //
.execute(); .execute();
} }
@ -1465,7 +1480,7 @@ public class CassandraMetadataRepository
QueryResult<OrderedRows<String, String, String>> result = HFactory // QueryResult<OrderedRows<String, String, String>> result = HFactory //
.createRangeSlicesQuery( keyspace, ss, ss, ss ) // .createRangeSlicesQuery( keyspace, ss, ss, ss ) //
.setColumnFamily( cassandraArchivaManager.getProjectVersionMetadataFamilyName() ) // .setColumnFamily( cassandraArchivaManager.getProjectVersionMetadataFamilyName() ) //
.setColumnNames( "projectVersion" ) // .setColumnNames( "version" ) //
.addEqualsExpression( "repositoryName", repoId ) // .addEqualsExpression( "repositoryName", repoId ) //
.addEqualsExpression( "namespaceId", namespace ) // .addEqualsExpression( "namespaceId", namespace ) //
.addEqualsExpression( "projectId", projectId ) // .addEqualsExpression( "projectId", projectId ) //
@ -1476,7 +1491,7 @@ public class CassandraMetadataRepository
for ( Row<String, String, String> row : result.get() ) for ( Row<String, String, String> row : result.get() )
{ {
versions.add( getStringValue( row.getColumnSlice(), "projectVersion" ) ); versions.add( getStringValue( row.getColumnSlice(), "version" ) );
} }
return versions; return versions;