mirror of https://github.com/apache/archiva.git
add unit test for method getProjectReferences
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1581807 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
24a6d8419c
commit
acc7242804
|
@ -29,6 +29,20 @@ public class ProjectVersionReference
|
||||||
|
|
||||||
private String projectVersion;
|
private String projectVersion;
|
||||||
|
|
||||||
|
public ProjectVersionReference()
|
||||||
|
{
|
||||||
|
// no op
|
||||||
|
}
|
||||||
|
|
||||||
|
public ProjectVersionReference( ReferenceType referenceType, String projectId, String namespace,
|
||||||
|
String projectVersion )
|
||||||
|
{
|
||||||
|
this.referenceType = referenceType;
|
||||||
|
this.projectId = projectId;
|
||||||
|
this.namespace = namespace;
|
||||||
|
this.projectVersion = projectVersion;
|
||||||
|
}
|
||||||
|
|
||||||
public void setReferenceType( ReferenceType referenceType )
|
public void setReferenceType( ReferenceType referenceType )
|
||||||
{
|
{
|
||||||
this.referenceType = referenceType;
|
this.referenceType = referenceType;
|
||||||
|
@ -74,4 +88,48 @@ public class ProjectVersionReference
|
||||||
DEPENDENCY,
|
DEPENDENCY,
|
||||||
PARENT
|
PARENT
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public boolean equals( Object o )
|
||||||
|
{
|
||||||
|
if ( this == o )
|
||||||
|
{
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if ( o == null || getClass() != o.getClass() )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
ProjectVersionReference that = (ProjectVersionReference) o;
|
||||||
|
|
||||||
|
if ( !namespace.equals( that.namespace ) )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ( !projectId.equals( that.projectId ) )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ( !projectVersion.equals( that.projectVersion ) )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if ( referenceType != that.referenceType )
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public int hashCode()
|
||||||
|
{
|
||||||
|
int result = referenceType.hashCode();
|
||||||
|
result = 31 * result + projectId.hashCode();
|
||||||
|
result = 31 * result + namespace.hashCode();
|
||||||
|
result = 31 * result + projectVersion.hashCode();
|
||||||
|
return result;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,6 +31,7 @@ import org.apache.archiva.metadata.model.MetadataFacetFactory;
|
||||||
import org.apache.archiva.metadata.model.Organization;
|
import org.apache.archiva.metadata.model.Organization;
|
||||||
import org.apache.archiva.metadata.model.ProjectMetadata;
|
import org.apache.archiva.metadata.model.ProjectMetadata;
|
||||||
import org.apache.archiva.metadata.model.ProjectVersionMetadata;
|
import org.apache.archiva.metadata.model.ProjectVersionMetadata;
|
||||||
|
import org.apache.archiva.metadata.model.ProjectVersionReference;
|
||||||
import org.apache.archiva.metadata.model.Scm;
|
import org.apache.archiva.metadata.model.Scm;
|
||||||
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
|
import org.apache.archiva.test.utils.ArchivaSpringJUnit4ClassRunner;
|
||||||
import org.assertj.core.util.Sets;
|
import org.assertj.core.util.Sets;
|
||||||
|
@ -1368,6 +1369,57 @@ public abstract class AbstractMetadataRepositoryTest
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testgetProjectReferences()
|
||||||
|
throws Exception
|
||||||
|
{
|
||||||
|
ProjectVersionMetadata metadata = new ProjectVersionMetadata();
|
||||||
|
metadata.setId( TEST_PROJECT_VERSION );
|
||||||
|
|
||||||
|
metadata.setName( "project name" );
|
||||||
|
metadata.setDescription( "project description" );
|
||||||
|
metadata.setUrl( "the url" );
|
||||||
|
|
||||||
|
Dependency d = new Dependency();
|
||||||
|
d.setArtifactId( "artifactId" );
|
||||||
|
d.setClassifier( "classifier" );
|
||||||
|
d.setGroupId( "groupId" );
|
||||||
|
d.setScope( "scope" );
|
||||||
|
d.setSystemPath( "system path" );
|
||||||
|
d.setType( "type" );
|
||||||
|
d.setVersion( "version" );
|
||||||
|
d.setOptional( true );
|
||||||
|
metadata.addDependency( d );
|
||||||
|
|
||||||
|
d = new Dependency();
|
||||||
|
d.setArtifactId( "artifactId1" );
|
||||||
|
d.setClassifier( "classifier" );
|
||||||
|
d.setGroupId( "groupId" );
|
||||||
|
d.setScope( "scope" );
|
||||||
|
d.setSystemPath( "system path" );
|
||||||
|
d.setType( "type" );
|
||||||
|
d.setVersion( "version1" );
|
||||||
|
d.setOptional( true );
|
||||||
|
metadata.addDependency( d );
|
||||||
|
|
||||||
|
repository.updateProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, metadata );
|
||||||
|
|
||||||
|
repository.save();
|
||||||
|
|
||||||
|
metadata = repository.getProjectVersion( TEST_REPO_ID, TEST_NAMESPACE, TEST_PROJECT, TEST_PROJECT_VERSION );
|
||||||
|
|
||||||
|
Collection<ProjectVersionReference> references =
|
||||||
|
repository.getProjectReferences( TEST_REPO_ID, d.getGroupId(), d.getArtifactId(), d.getVersion() );
|
||||||
|
|
||||||
|
log.info( "references: {}", references );
|
||||||
|
|
||||||
|
assertThat( references ).isNotNull().hasSize( 1 ).contains(
|
||||||
|
new ProjectVersionReference( ProjectVersionReference.ReferenceType.DEPENDENCY, TEST_PROJECT, TEST_NAMESPACE,
|
||||||
|
TEST_PROJECT_VERSION ) );
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
private static ProjectMetadata createProject()
|
private static ProjectMetadata createProject()
|
||||||
{
|
{
|
||||||
return createProject( TEST_NAMESPACE );
|
return createProject( TEST_NAMESPACE );
|
||||||
|
|
|
@ -875,7 +875,7 @@ public class CassandraMetadataRepository
|
||||||
|
|
||||||
recordLicenses( key, versionMetadata.getLicenses() );
|
recordLicenses( key, versionMetadata.getLicenses() );
|
||||||
|
|
||||||
recordDependencies( key, versionMetadata.getDependencies() );
|
recordDependencies( key, versionMetadata.getDependencies(), repositoryId );
|
||||||
|
|
||||||
MutationResult mutationResult = mutator.execute();
|
MutationResult mutationResult = mutator.execute();
|
||||||
}
|
}
|
||||||
|
@ -942,7 +942,7 @@ public class CassandraMetadataRepository
|
||||||
recordLicenses( key, versionMetadata.getLicenses() );
|
recordLicenses( key, versionMetadata.getLicenses() );
|
||||||
|
|
||||||
removeDependencies( key );
|
removeDependencies( key );
|
||||||
recordDependencies( key, versionMetadata.getDependencies() );
|
recordDependencies( key, versionMetadata.getDependencies(), repositoryId );
|
||||||
|
|
||||||
projectVersionMetadataTemplate.update( updater );
|
projectVersionMetadataTemplate.update( updater );
|
||||||
|
|
||||||
|
@ -1234,7 +1234,8 @@ public class CassandraMetadataRepository
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
protected void recordDependencies( String projectVersionMetadataKey, List<Dependency> dependencies )
|
protected void recordDependencies( String projectVersionMetadataKey, List<Dependency> dependencies,
|
||||||
|
String repositoryId )
|
||||||
{
|
{
|
||||||
|
|
||||||
if ( dependencies == null || dependencies.isEmpty() )
|
if ( dependencies == null || dependencies.isEmpty() )
|
||||||
|
@ -1252,6 +1253,8 @@ public class CassandraMetadataRepository
|
||||||
addInsertion( dependencyMutator, keyDependency, cfDependency, "projectVersionMetadataModel.key",
|
addInsertion( dependencyMutator, keyDependency, cfDependency, "projectVersionMetadataModel.key",
|
||||||
projectVersionMetadataKey );
|
projectVersionMetadataKey );
|
||||||
|
|
||||||
|
addInsertion( dependencyMutator, keyDependency, cfDependency, "repositoryName", repositoryId );
|
||||||
|
|
||||||
addInsertion( dependencyMutator, keyDependency, cfDependency, "classifier", dependency.getClassifier() );
|
addInsertion( dependencyMutator, keyDependency, cfDependency, "classifier", dependency.getClassifier() );
|
||||||
|
|
||||||
addInsertion( dependencyMutator, keyDependency, cfDependency, "optional",
|
addInsertion( dependencyMutator, keyDependency, cfDependency, "optional",
|
||||||
|
@ -1918,8 +1921,36 @@ public class CassandraMetadataRepository
|
||||||
String projectVersion )
|
String projectVersion )
|
||||||
throws MetadataResolutionException
|
throws MetadataResolutionException
|
||||||
{
|
{
|
||||||
// FIXME implement this
|
QueryResult<OrderedRows<String, String, String>> result = HFactory //
|
||||||
return Collections.emptyList();
|
.createRangeSlicesQuery( keyspace, ss, ss, ss ) //
|
||||||
|
.setColumnFamily( cassandraArchivaManager.getDependencyFamilyName() ) //
|
||||||
|
.setColumnNames( "projectVersionMetadataModel.key" ) //
|
||||||
|
.addEqualsExpression( "repositoryName", repoId ) //
|
||||||
|
.addEqualsExpression( "groupId", namespace ) //
|
||||||
|
.addEqualsExpression( "artifactId", projectId ) //
|
||||||
|
.addEqualsExpression( "version", projectVersion ) //
|
||||||
|
.execute();
|
||||||
|
|
||||||
|
List<String> dependenciesIds = new ArrayList<String>( result.get().getCount() );
|
||||||
|
|
||||||
|
for ( Row<String, String, String> row : result.get().getList() )
|
||||||
|
{
|
||||||
|
dependenciesIds.add( getStringValue( row.getColumnSlice(), "projectVersionMetadataModel.key" ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
List<ProjectVersionReference> references = new ArrayList<ProjectVersionReference>( result.get().getCount() );
|
||||||
|
|
||||||
|
for ( String key : dependenciesIds )
|
||||||
|
{
|
||||||
|
ColumnFamilyResult<String, String> columnFamilyResult =
|
||||||
|
this.projectVersionMetadataTemplate.queryColumns( key );
|
||||||
|
references.add( new ProjectVersionReference( ProjectVersionReference.ReferenceType.DEPENDENCY, //
|
||||||
|
columnFamilyResult.getString( "projectId" ), //
|
||||||
|
columnFamilyResult.getString( "namespaceId" ), //
|
||||||
|
columnFamilyResult.getString( "projectVersion" ) ) );
|
||||||
|
}
|
||||||
|
|
||||||
|
return references;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -375,13 +375,6 @@ public class DefaultCassandraArchivaManager
|
||||||
|
|
||||||
// creating indexes for cql query
|
// creating indexes for cql query
|
||||||
|
|
||||||
BasicColumnDefinition projectVersionMetadataIdColumn = new BasicColumnDefinition();
|
|
||||||
projectVersionMetadataIdColumn.setName( StringSerializer.get().toByteBuffer( "projectVersionMetadataId" ) );
|
|
||||||
projectVersionMetadataIdColumn.setIndexName( "projectVersionMetadataId" );
|
|
||||||
projectVersionMetadataIdColumn.setIndexType( ColumnIndexType.KEYS );
|
|
||||||
projectVersionMetadataIdColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
|
|
||||||
mailingListCf.addColumnDefinition( projectVersionMetadataIdColumn );
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// license table
|
// license table
|
||||||
|
@ -394,13 +387,6 @@ public class DefaultCassandraArchivaManager
|
||||||
|
|
||||||
// creating indexes for cql query
|
// creating indexes for cql query
|
||||||
|
|
||||||
BasicColumnDefinition projectVersionMetadataIdColumn = new BasicColumnDefinition();
|
|
||||||
projectVersionMetadataIdColumn.setName( StringSerializer.get().toByteBuffer( "projectVersionMetadataId" ) );
|
|
||||||
projectVersionMetadataIdColumn.setIndexName( "projectVersionMetadataId" );
|
|
||||||
projectVersionMetadataIdColumn.setIndexType( ColumnIndexType.KEYS );
|
|
||||||
projectVersionMetadataIdColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
|
|
||||||
licenseCf.addColumnDefinition( projectVersionMetadataIdColumn );
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// dependency table
|
// dependency table
|
||||||
|
@ -413,12 +399,12 @@ public class DefaultCassandraArchivaManager
|
||||||
|
|
||||||
// creating indexes for cql query
|
// creating indexes for cql query
|
||||||
|
|
||||||
BasicColumnDefinition projectVersionMetadataIdColumn = new BasicColumnDefinition();
|
BasicColumnDefinition groupIdColumn = new BasicColumnDefinition();
|
||||||
projectVersionMetadataIdColumn.setName( StringSerializer.get().toByteBuffer( "projectVersionMetadataId" ) );
|
groupIdColumn.setName( StringSerializer.get().toByteBuffer( "groupId" ) );
|
||||||
projectVersionMetadataIdColumn.setIndexName( "projectVersionMetadataId" );
|
groupIdColumn.setIndexName( "groupIdIdx" );
|
||||||
projectVersionMetadataIdColumn.setIndexType( ColumnIndexType.KEYS );
|
groupIdColumn.setIndexType( ColumnIndexType.KEYS );
|
||||||
projectVersionMetadataIdColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
|
groupIdColumn.setValidationClass( ComparatorType.UTF8TYPE.getClassName() );
|
||||||
dependencyCf.addColumnDefinition( projectVersionMetadataIdColumn );
|
dependencyCf.addColumnDefinition( groupIdColumn );
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -987,6 +987,7 @@ public class JcrMetadataRepository
|
||||||
String projectId, String projectVersion )
|
String projectId, String projectVersion )
|
||||||
throws MetadataResolutionException
|
throws MetadataResolutionException
|
||||||
{
|
{
|
||||||
|
|
||||||
List<ProjectVersionReference> references = new ArrayList<ProjectVersionReference>();
|
List<ProjectVersionReference> references = new ArrayList<ProjectVersionReference>();
|
||||||
|
|
||||||
// TODO: bind variables instead
|
// TODO: bind variables instead
|
||||||
|
|
Loading…
Reference in New Issue