mirror of https://github.com/apache/archiva.git
[MRM-1288] migrate getDependees() to new API
git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@885319 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
0caebfc6b6
commit
d6c5ea064e
|
@ -45,6 +45,55 @@ public class Artifact
|
|||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals( Object o )
|
||||
{
|
||||
if ( this == o )
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if ( o == null || getClass() != o.getClass() )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
Artifact artifact = (Artifact) o;
|
||||
|
||||
if ( !artifactId.equals( artifact.artifactId ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ( !groupId.equals( artifact.groupId ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ( !repositoryId.equals( artifact.repositoryId ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ( type != null ? !type.equals( artifact.type ) : artifact.type != null )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if ( !version.equals( artifact.version ) )
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
int result = repositoryId.hashCode();
|
||||
result = 31 * result + groupId.hashCode();
|
||||
result = 31 * result + artifactId.hashCode();
|
||||
result = 31 * result + version.hashCode();
|
||||
result = 31 * result + ( type != null ? type.hashCode() : 0 );
|
||||
return result;
|
||||
}
|
||||
|
||||
public Artifact( String repositoryId, String groupId, String artifactId, String version, String type )
|
||||
// String type, Date whenGathered )
|
||||
{
|
||||
|
|
|
@ -66,6 +66,10 @@
|
|||
<groupId>org.apache.archiva</groupId>
|
||||
<artifactId>archiva-security</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.apache.archiva</groupId>
|
||||
<artifactId>metadata-repository-api</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.codehaus.plexus</groupId>
|
||||
<artifactId>plexus-spring</artifactId>
|
||||
|
|
|
@ -20,6 +20,7 @@ package org.apache.archiva.web.xmlrpc.services;
|
|||
*/
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
|
@ -27,6 +28,8 @@ import org.apache.archiva.indexer.search.RepositorySearch;
|
|||
import org.apache.archiva.indexer.search.SearchResultHit;
|
||||
import org.apache.archiva.indexer.search.SearchResultLimits;
|
||||
import org.apache.archiva.indexer.search.SearchResults;
|
||||
import org.apache.archiva.metadata.model.ProjectVersionReference;
|
||||
import org.apache.archiva.metadata.repository.MetadataResolver;
|
||||
import org.apache.archiva.web.xmlrpc.api.SearchService;
|
||||
import org.apache.archiva.web.xmlrpc.api.beans.Artifact;
|
||||
import org.apache.archiva.web.xmlrpc.api.beans.Dependency;
|
||||
|
@ -71,13 +74,17 @@ public class SearchServiceImpl
|
|||
|
||||
private RepositoryBrowsing repoBrowsing;
|
||||
|
||||
private MetadataResolver metadataResolver;
|
||||
|
||||
public SearchServiceImpl( XmlRpcUserRepositories xmlRpcUserRepositories, ArchivaDAO archivaDAO,
|
||||
RepositoryBrowsing repoBrowsing, RepositorySearch search )
|
||||
RepositoryBrowsing repoBrowsing, MetadataResolver metadataResolver,
|
||||
RepositorySearch search )
|
||||
{
|
||||
this.xmlRpcUserRepositories = xmlRpcUserRepositories;
|
||||
this.archivaDAO = archivaDAO;
|
||||
this.repoBrowsing = repoBrowsing;
|
||||
this.search = search;
|
||||
this.metadataResolver = metadataResolver;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
|
@ -263,13 +270,15 @@ public class SearchServiceImpl
|
|||
List<Artifact> artifacts = new ArrayList<Artifact>();
|
||||
List<String> observableRepos = xmlRpcUserRepositories.getObservableRepositories();
|
||||
|
||||
List<ArchivaProjectModel> dependees =
|
||||
repoBrowsing.getUsedBy( "", observableRepos, groupId, artifactId, version );
|
||||
for ( ArchivaProjectModel model : dependees )
|
||||
for ( String repoId : observableRepos )
|
||||
{
|
||||
Artifact artifact = new Artifact( "", model.getGroupId(), model.getArtifactId(), model.getVersion(), "" );
|
||||
//model.getWhenIndexed() );
|
||||
artifacts.add( artifact );
|
||||
Collection<ProjectVersionReference> refs =
|
||||
metadataResolver.getProjectReferences( repoId, groupId, artifactId, version );
|
||||
for ( ProjectVersionReference ref : refs )
|
||||
{
|
||||
artifacts.add(
|
||||
new Artifact( repoId, ref.getNamespace(), ref.getProjectId(), ref.getProjectVersion(), "" ) );
|
||||
}
|
||||
}
|
||||
|
||||
return artifacts;
|
||||
|
|
|
@ -29,6 +29,8 @@ import org.apache.archiva.indexer.search.SearchResultHit;
|
|||
import org.apache.archiva.indexer.search.SearchResultLimits;
|
||||
import org.apache.archiva.indexer.search.SearchResults;
|
||||
import org.apache.archiva.indexer.util.SearchUtil;
|
||||
import org.apache.archiva.metadata.model.ProjectVersionReference;
|
||||
import org.apache.archiva.metadata.repository.MetadataResolver;
|
||||
import org.apache.archiva.web.xmlrpc.api.SearchService;
|
||||
import org.apache.archiva.web.xmlrpc.api.beans.Artifact;
|
||||
import org.apache.archiva.web.xmlrpc.api.beans.Dependency;
|
||||
|
@ -80,6 +82,10 @@ public class SearchServiceImplTest
|
|||
|
||||
private static final String ARCHIVA_TEST_GROUP_ID = "org.apache.archiva";
|
||||
|
||||
private MockControl metadataResolverControl;
|
||||
|
||||
private MetadataResolver metadataResolver;
|
||||
|
||||
@Override
|
||||
public void setUp()
|
||||
throws Exception
|
||||
|
@ -98,7 +104,10 @@ public class SearchServiceImplTest
|
|||
searchControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
|
||||
search = (RepositorySearch) searchControl.getMock();
|
||||
|
||||
searchService = new SearchServiceImpl( userRepos, archivaDAO, repoBrowsing, search );
|
||||
metadataResolverControl = MockControl.createControl( MetadataResolver.class );
|
||||
metadataResolver = (MetadataResolver) metadataResolverControl.getMock();
|
||||
|
||||
searchService = new SearchServiceImpl( userRepos, archivaDAO, repoBrowsing, metadataResolver, search );
|
||||
|
||||
artifactDAOControl = MockControl.createControl( ArtifactDAO.class );
|
||||
artifactDAO = (ArtifactDAO) artifactDAOControl.getMock();
|
||||
|
@ -624,41 +633,42 @@ public class SearchServiceImplTest
|
|||
public void testGetDependees()
|
||||
throws Exception
|
||||
{
|
||||
Date date = new Date();
|
||||
List<String> observableRepoIds = new ArrayList<String>();
|
||||
observableRepoIds.add( "repo1.mirror" );
|
||||
observableRepoIds.add( "public.releases" );
|
||||
String repoId = "repo1.mirror";
|
||||
observableRepoIds.add( repoId );
|
||||
|
||||
List<ArchivaProjectModel> dependeeModels = new ArrayList<ArchivaProjectModel>();
|
||||
ArchivaProjectModel dependeeModel = new ArchivaProjectModel();
|
||||
dependeeModel.setGroupId( ARCHIVA_TEST_GROUP_ID );
|
||||
dependeeModel.setArtifactId( "archiva-dependee-one" );
|
||||
dependeeModel.setVersion( "1.0" );
|
||||
dependeeModel.setWhenIndexed( date );
|
||||
List<ProjectVersionReference> dependeeModels = new ArrayList<ProjectVersionReference>();
|
||||
ProjectVersionReference dependeeModel = new ProjectVersionReference();
|
||||
dependeeModel.setNamespace( ARCHIVA_TEST_GROUP_ID );
|
||||
dependeeModel.setProjectId( "archiva-dependee-one" );
|
||||
dependeeModel.setProjectVersion( "1.0" );
|
||||
dependeeModels.add( dependeeModel );
|
||||
|
||||
dependeeModel = new ArchivaProjectModel();
|
||||
dependeeModel.setGroupId( ARCHIVA_TEST_GROUP_ID );
|
||||
dependeeModel.setArtifactId( "archiva-dependee-two" );
|
||||
dependeeModel.setVersion( "1.0" );
|
||||
dependeeModel.setWhenIndexed( date );
|
||||
dependeeModel = new ProjectVersionReference();
|
||||
dependeeModel.setNamespace( ARCHIVA_TEST_GROUP_ID );
|
||||
dependeeModel.setProjectId( "archiva-dependee-two" );
|
||||
dependeeModel.setProjectVersion( "1.0" );
|
||||
dependeeModels.add( dependeeModel );
|
||||
|
||||
userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds );
|
||||
repoBrowsingControl.expectAndReturn(
|
||||
repoBrowsing.getUsedBy( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ),
|
||||
metadataResolverControl.expectAndReturn(
|
||||
metadataResolver.getProjectReferences( repoId, ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ),
|
||||
dependeeModels );
|
||||
|
||||
repoBrowsingControl.replay();
|
||||
metadataResolverControl.replay();
|
||||
userReposControl.replay();
|
||||
|
||||
List<Artifact> dependees = searchService.getDependees( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" );
|
||||
|
||||
repoBrowsingControl.verify();
|
||||
metadataResolverControl.verify();
|
||||
userReposControl.verify();
|
||||
|
||||
assertNotNull( dependees );
|
||||
assertEquals( 2, dependees.size() );
|
||||
assertEquals( new Artifact( repoId, ARCHIVA_TEST_GROUP_ID, "archiva-dependee-one", "1.0", "" ),
|
||||
dependees.get( 0 ) );
|
||||
assertEquals( new Artifact( repoId, ARCHIVA_TEST_GROUP_ID, "archiva-dependee-two", "1.0", "" ),
|
||||
dependees.get( 1 ) );
|
||||
}
|
||||
|
||||
public void testGetDependeesArtifactDoesNotExist()
|
||||
|
@ -669,32 +679,19 @@ public class SearchServiceImplTest
|
|||
observableRepoIds.add( "repo1.mirror" );
|
||||
observableRepoIds.add( "public.releases" );
|
||||
|
||||
List dependeeModels = new ArrayList();
|
||||
ArchivaProjectModel dependeeModel = new ArchivaProjectModel();
|
||||
dependeeModel.setGroupId( ARCHIVA_TEST_GROUP_ID );
|
||||
dependeeModel.setArtifactId( "archiva-dependee-one" );
|
||||
dependeeModel.setVersion( "1.0" );
|
||||
dependeeModel.setWhenIndexed( date );
|
||||
dependeeModels.add( dependeeModel );
|
||||
|
||||
dependeeModel = new ArchivaProjectModel();
|
||||
dependeeModel.setGroupId( ARCHIVA_TEST_GROUP_ID );
|
||||
dependeeModel.setArtifactId( "archiva-dependee-two" );
|
||||
dependeeModel.setVersion( "1.0" );
|
||||
dependeeModel.setWhenIndexed( date );
|
||||
dependeeModels.add( dependeeModel );
|
||||
|
||||
userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds );
|
||||
repoBrowsingControl.expectAndReturn(
|
||||
repoBrowsing.getUsedBy( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ),
|
||||
null );
|
||||
metadataResolverControl.expectAndReturn(
|
||||
metadataResolver.getProjectReferences( "repo1.mirror", ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID,
|
||||
"1.0" ), null );
|
||||
metadataResolverControl.expectAndReturn(
|
||||
metadataResolver.getProjectReferences( "public.releases", ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID,
|
||||
"1.0" ), null );
|
||||
|
||||
repoBrowsingControl.replay();
|
||||
userReposControl.replay();
|
||||
|
||||
try
|
||||
{
|
||||
List<Artifact> dependees =
|
||||
searchService.getDependees( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" );
|
||||
fail( "An exception should have been thrown." );
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue