formatting changes only

git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@885316 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Brett Porter 2009-11-30 02:43:00 +00:00
parent 9f389a48a0
commit 0caebfc6b6
2 changed files with 351 additions and 302 deletions

View File

@ -47,189 +47,196 @@ import org.slf4j.LoggerFactory;
/** /**
* SearchServiceImpl * SearchServiceImpl
* *
* quick/general text search which returns a list of artifacts * quick/general text search which returns a list of artifacts
* query for an artifact based on a checksum * query for an artifact based on a checksum
* query for all available versions of an artifact, sorted in version significance order * query for all available versions of an artifact, sorted in version significance order
* query for all available versions of an artifact since a given date * query for all available versions of an artifact since a given date
* query for an artifact's direct dependencies * query for an artifact's direct dependencies
* query for an artifact's dependency tree (as with mvn dependency:tree - no duplicates should be included) * query for an artifact's dependency tree (as with mvn dependency:tree - no duplicates should be included)
* query for all artifacts that depend on a given artifact * query for all artifacts that depend on a given artifact
* *
* @version $Id: SearchServiceImpl.java * @version $Id: SearchServiceImpl.java
*/ */
public class SearchServiceImpl public class SearchServiceImpl
implements SearchService implements SearchService
{ {
private Logger log = LoggerFactory.getLogger( SearchServiceImpl.class ); private Logger log = LoggerFactory.getLogger( SearchServiceImpl.class );
private RepositorySearch search; private RepositorySearch search;
private XmlRpcUserRepositories xmlRpcUserRepositories; private XmlRpcUserRepositories xmlRpcUserRepositories;
private ArchivaDAO archivaDAO; private ArchivaDAO archivaDAO;
private RepositoryBrowsing repoBrowsing; private RepositoryBrowsing repoBrowsing;
public SearchServiceImpl( XmlRpcUserRepositories xmlRpcUserRepositories, ArchivaDAO archivaDAO, public SearchServiceImpl( XmlRpcUserRepositories xmlRpcUserRepositories, ArchivaDAO archivaDAO,
RepositoryBrowsing repoBrowsing, RepositorySearch search ) RepositoryBrowsing repoBrowsing, RepositorySearch search )
{ {
this.xmlRpcUserRepositories = xmlRpcUserRepositories; this.xmlRpcUserRepositories = xmlRpcUserRepositories;
this.archivaDAO = archivaDAO; this.archivaDAO = archivaDAO;
this.repoBrowsing = repoBrowsing; this.repoBrowsing = repoBrowsing;
this.search = search; this.search = search;
} }
@SuppressWarnings( "unchecked" ) @SuppressWarnings("unchecked")
public List<Artifact> quickSearch( String queryString ) public List<Artifact> quickSearch( String queryString )
throws Exception throws Exception
{ {
List<Artifact> artifacts = new ArrayList<Artifact>(); List<Artifact> artifacts = new ArrayList<Artifact>();
List<String> observableRepos = xmlRpcUserRepositories.getObservableRepositories(); List<String> observableRepos = xmlRpcUserRepositories.getObservableRepositories();
SearchResultLimits limits = new SearchResultLimits( SearchResultLimits.ALL_PAGES ); SearchResultLimits limits = new SearchResultLimits( SearchResultLimits.ALL_PAGES );
SearchResults results = null; SearchResults results = null;
results = search.search( "", observableRepos, queryString, limits, null ); results = search.search( "", observableRepos, queryString, limits, null );
for ( SearchResultHit resultHit : results.getHits() ) for ( SearchResultHit resultHit : results.getHits() )
{ {
// double-check all versions as done in SearchAction // double-check all versions as done in SearchAction
final List<String> versions = final List<String> versions = (List<String>) archivaDAO.query(
(List<String>) archivaDAO.query( new UniqueVersionConstraint( observableRepos, resultHit.getGroupId(), new UniqueVersionConstraint( observableRepos, resultHit.getGroupId(), resultHit.getArtifactId() ) );
resultHit.getArtifactId() ) );
if ( versions != null && !versions.isEmpty() ) if ( versions != null && !versions.isEmpty() )
{ {
resultHit.setVersion( null ); resultHit.setVersion( null );
resultHit.setVersions( filterTimestampedSnapshots( versions ) ); resultHit.setVersions( filterTimestampedSnapshots( versions ) );
} }
List<String> resultHitVersions = resultHit.getVersions(); List<String> resultHitVersions = resultHit.getVersions();
if( resultHitVersions != null ) if ( resultHitVersions != null )
{ {
for( String version : resultHitVersions ) for ( String version : resultHitVersions )
{ {
try try
{ {
ArchivaProjectModel model = repoBrowsing.selectVersion( "", observableRepos, resultHit.getGroupId(), resultHit.getArtifactId(), version ); ArchivaProjectModel model =
repoBrowsing.selectVersion( "", observableRepos, resultHit.getGroupId(),
String repoId = repoBrowsing.getRepositoryId( "", observableRepos, resultHit.getGroupId(), resultHit.getArtifactId(), version ); resultHit.getArtifactId(), version );
String repoId = repoBrowsing.getRepositoryId( "", observableRepos, resultHit.getGroupId(),
resultHit.getArtifactId(), version );
Artifact artifact = null; Artifact artifact = null;
if( model == null ) if ( model == null )
{ {
artifact = new Artifact( repoId, resultHit.getGroupId(), resultHit.getArtifactId(), version, "jar" ); artifact = new Artifact( repoId, resultHit.getGroupId(), resultHit.getArtifactId(), version,
"jar" );
} }
else else
{ {
artifact = new Artifact( repoId, model.getGroupId(), model.getArtifactId(), version, model.getPackaging() ); artifact = new Artifact( repoId, model.getGroupId(), model.getArtifactId(), version,
model.getPackaging() );
} }
artifacts.add( artifact ); artifacts.add( artifact );
} }
catch( ObjectNotFoundException e ) catch ( ObjectNotFoundException e )
{ {
log.debug( "Unable to find pom artifact : " + e.getMessage() ); log.debug( "Unable to find pom artifact : " + e.getMessage() );
} }
catch( ArchivaDatabaseException e ) catch ( ArchivaDatabaseException e )
{ {
log.debug( "Error occurred while getting pom artifact from database : " + e.getMessage() ); log.debug( "Error occurred while getting pom artifact from database : " + e.getMessage() );
} }
} }
} }
} }
return artifacts; return artifacts;
} }
/** /**
* Remove timestamped snapshots from versions * Remove timestamped snapshots from versions
*/ */
private static List<String> filterTimestampedSnapshots(List<String> versions) private static List<String> filterTimestampedSnapshots( List<String> versions )
{ {
final List<String> filtered = new ArrayList<String>(); final List<String> filtered = new ArrayList<String>();
for (final String version : versions) for ( final String version : versions )
{ {
final String baseVersion = VersionUtil.getBaseVersion(version); final String baseVersion = VersionUtil.getBaseVersion( version );
if (!filtered.contains(baseVersion)) if ( !filtered.contains( baseVersion ) )
{ {
filtered.add(baseVersion); filtered.add( baseVersion );
} }
} }
return filtered; return filtered;
} }
public List<Artifact> getArtifactByChecksum( String checksum ) public List<Artifact> getArtifactByChecksum( String checksum )
throws Exception throws Exception
{ {
// 1. get ArtifactDAO from ArchivaDAO // 1. get ArtifactDAO from ArchivaDAO
// 2. create ArtifactsByChecksumConstraint( "queryTerm" ) // 2. create ArtifactsByChecksumConstraint( "queryTerm" )
// 3. query artifacts using constraint // 3. query artifacts using constraint
// 4. convert results to list of Artifact objects // 4. convert results to list of Artifact objects
List<Artifact> results = new ArrayList<Artifact>(); List<Artifact> results = new ArrayList<Artifact>();
ArtifactDAO artifactDAO = archivaDAO.getArtifactDAO(); ArtifactDAO artifactDAO = archivaDAO.getArtifactDAO();
ArtifactsByChecksumConstraint constraint = new ArtifactsByChecksumConstraint( checksum ); ArtifactsByChecksumConstraint constraint = new ArtifactsByChecksumConstraint( checksum );
List<ArchivaArtifact> artifacts = artifactDAO.queryArtifacts( constraint ); List<ArchivaArtifact> artifacts = artifactDAO.queryArtifacts( constraint );
for( ArchivaArtifact archivaArtifact : artifacts ) for ( ArchivaArtifact archivaArtifact : artifacts )
{ {
Artifact artifact = new Artifact( archivaArtifact.getModel().getRepositoryId(), archivaArtifact.getModel().getGroupId(), Artifact artifact =
archivaArtifact.getModel().getArtifactId(), archivaArtifact.getModel().getVersion(), archivaArtifact.getType() ); new Artifact( archivaArtifact.getModel().getRepositoryId(), archivaArtifact.getModel().getGroupId(),
//archivaArtifact.getModel().getWhenGathered() ); archivaArtifact.getModel().getArtifactId(), archivaArtifact.getModel().getVersion(),
archivaArtifact.getType() );
//archivaArtifact.getModel().getWhenGathered() );
results.add( artifact ); results.add( artifact );
} }
return results; return results;
} }
public List<Artifact> getArtifactVersions( String groupId, String artifactId ) public List<Artifact> getArtifactVersions( String groupId, String artifactId )
throws Exception throws Exception
{ {
final List<Artifact> artifacts = new ArrayList<Artifact>(); final List<Artifact> artifacts = new ArrayList<Artifact>();
final List<String> observableRepos = xmlRpcUserRepositories.getObservableRepositories(); final List<String> observableRepos = xmlRpcUserRepositories.getObservableRepositories();
final BrowsingResults results = repoBrowsing.selectArtifactId( "", observableRepos, groupId, artifactId ); final BrowsingResults results = repoBrowsing.selectArtifactId( "", observableRepos, groupId, artifactId );
for( final String version : results.getVersions() ) for ( final String version : results.getVersions() )
{ {
final Artifact artifact = new Artifact( "", groupId, artifactId, version, "pom" ); final Artifact artifact = new Artifact( "", groupId, artifactId, version, "pom" );
//ArchivaArtifact pomArtifact = artifactDAO.getArtifact( groupId, artifactId, version, "", "pom", ); //ArchivaArtifact pomArtifact = artifactDAO.getArtifact( groupId, artifactId, version, "", "pom", );
//Artifact artifact = new Artifact( "", groupId, artifactId, version, pomArtifact.getType() ); //Artifact artifact = new Artifact( "", groupId, artifactId, version, pomArtifact.getType() );
//pomArtifact.getModel().getWhenGathered() ); //pomArtifact.getModel().getWhenGathered() );
artifacts.add( artifact ); artifacts.add( artifact );
} }
// 1. get observable repositories // 1. get observable repositories
// 2. use RepositoryBrowsing method to query uniqueVersions? // 2. use RepositoryBrowsing method to query uniqueVersions?
return artifacts; return artifacts;
} }
public List<Artifact> getArtifactVersionsByDate( String groupId, String artifactId, String version, Date since ) public List<Artifact> getArtifactVersionsByDate( String groupId, String artifactId, String version, Date since )
throws Exception throws Exception
{ {
List<Artifact> artifacts = new ArrayList<Artifact>(); List<Artifact> artifacts = new ArrayList<Artifact>();
// 1. get observable repositories // 1. get observable repositories
// 2. use RepositoryBrowsing method to query uniqueVersions? (but with date) // 2. use RepositoryBrowsing method to query uniqueVersions? (but with date)
return artifacts; return artifacts;
} }
public List<Dependency> getDependencies( String groupId, String artifactId, String version ) public List<Dependency> getDependencies( String groupId, String artifactId, String version )
throws Exception throws Exception
{ {
List<Dependency> dependencies = new ArrayList<Dependency>(); List<Dependency> dependencies = new ArrayList<Dependency>();
List<String> observableRepos = xmlRpcUserRepositories.getObservableRepositories(); List<String> observableRepos = xmlRpcUserRepositories.getObservableRepositories();
try try
{ {
ArchivaProjectModel model = repoBrowsing.selectVersion( "", observableRepos, groupId, artifactId, version ); ArchivaProjectModel model = repoBrowsing.selectVersion( "", observableRepos, groupId, artifactId, version );
List<org.apache.maven.archiva.model.Dependency> modelDeps = model.getDependencies(); List<org.apache.maven.archiva.model.Dependency> modelDeps = model.getDependencies();
for( org.apache.maven.archiva.model.Dependency dep : modelDeps ) for ( org.apache.maven.archiva.model.Dependency dep : modelDeps )
{ {
Dependency dependency = new Dependency( Dependency dependency =
dep.getGroupId(), dep.getArtifactId(), dep.getVersion(), dep.getClassifier(), dep.getType(), dep.getScope() ); new Dependency( dep.getGroupId(), dep.getArtifactId(), dep.getVersion(), dep.getClassifier(),
dep.getType(), dep.getScope() );
dependencies.add( dependency ); dependencies.add( dependency );
} }
} }
@ -237,34 +244,34 @@ public class SearchServiceImpl
{ {
throw new Exception( "Artifact does not exist." ); throw new Exception( "Artifact does not exist." );
} }
return dependencies; return dependencies;
} }
public List<Artifact> getDependencyTree( String groupId, String artifactId, String version ) public List<Artifact> getDependencyTree( String groupId, String artifactId, String version )
throws Exception throws Exception
{ {
List<Artifact> a = new ArrayList<Artifact>(); List<Artifact> a = new ArrayList<Artifact>();
return a; return a;
} }
//get artifacts that depend on a given artifact //get artifacts that depend on a given artifact
public List<Artifact> getDependees( String groupId, String artifactId, String version ) public List<Artifact> getDependees( String groupId, String artifactId, String version )
throws Exception throws Exception
{ {
List<Artifact> artifacts = new ArrayList<Artifact>(); List<Artifact> artifacts = new ArrayList<Artifact>();
List<String> observableRepos = xmlRpcUserRepositories.getObservableRepositories(); List<String> observableRepos = xmlRpcUserRepositories.getObservableRepositories();
List<ArchivaProjectModel> dependees = repoBrowsing.getUsedBy( "", observableRepos, groupId, artifactId, version ); List<ArchivaProjectModel> dependees =
for( ArchivaProjectModel model : dependees ) repoBrowsing.getUsedBy( "", observableRepos, groupId, artifactId, version );
for ( ArchivaProjectModel model : dependees )
{ {
Artifact artifact = Artifact artifact = new Artifact( "", model.getGroupId(), model.getArtifactId(), model.getVersion(), "" );
new Artifact( "", model.getGroupId(), model.getArtifactId(), model.getVersion(), "" ); //model.getWhenIndexed() );
//model.getWhenIndexed() );
artifacts.add( artifact ); artifacts.add( artifact );
} }
return artifacts; return artifacts;
} }
} }

View File

@ -18,7 +18,7 @@ package org.apache.archiva.web.xmlrpc.services;
* specific language governing permissions and limitations * specific language governing permissions and limitations
* under the License. * under the License.
*/ */
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Date; import java.util.Date;
@ -48,32 +48,32 @@ import org.easymock.classextension.MockClassControl;
/** /**
* SearchServiceImplTest * SearchServiceImplTest
* *
* @version $Id: SearchServiceImplTest.java * @version $Id: SearchServiceImplTest.java
*/ */
public class SearchServiceImplTest public class SearchServiceImplTest
extends PlexusInSpringTestCase extends PlexusInSpringTestCase
{ {
private SearchService searchService; private SearchService searchService;
private MockControl userReposControl; private MockControl userReposControl;
private XmlRpcUserRepositories userRepos; private XmlRpcUserRepositories userRepos;
private MockControl searchControl; private MockControl searchControl;
private RepositorySearch search; private RepositorySearch search;
private MockControl archivaDAOControl; private MockControl archivaDAOControl;
private ArchivaDAO archivaDAO; private ArchivaDAO archivaDAO;
private MockControl artifactDAOControl; private MockControl artifactDAOControl;
private ArtifactDAO artifactDAO; private ArtifactDAO artifactDAO;
private MockControl repoBrowsingControl; private MockControl repoBrowsingControl;
private RepositoryBrowsing repoBrowsing; private RepositoryBrowsing repoBrowsing;
private static final String ARCHIVA_TEST_ARTIFACT_ID = "archiva-xmlrpc-test"; private static final String ARCHIVA_TEST_ARTIFACT_ID = "archiva-xmlrpc-test";
@ -85,79 +85,85 @@ public class SearchServiceImplTest
throws Exception throws Exception
{ {
userReposControl = MockClassControl.createControl( XmlRpcUserRepositories.class ); userReposControl = MockClassControl.createControl( XmlRpcUserRepositories.class );
userRepos = ( XmlRpcUserRepositories ) userReposControl.getMock(); userRepos = (XmlRpcUserRepositories) userReposControl.getMock();
archivaDAOControl = MockControl.createControl( ArchivaDAO.class ); archivaDAOControl = MockControl.createControl( ArchivaDAO.class );
archivaDAOControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER ); archivaDAOControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
archivaDAO = ( ArchivaDAO ) archivaDAOControl.getMock(); archivaDAO = (ArchivaDAO) archivaDAOControl.getMock();
repoBrowsingControl = MockControl.createControl( RepositoryBrowsing.class ); repoBrowsingControl = MockControl.createControl( RepositoryBrowsing.class );
repoBrowsing = ( RepositoryBrowsing ) repoBrowsingControl.getMock(); repoBrowsing = (RepositoryBrowsing) repoBrowsingControl.getMock();
searchControl = MockControl.createControl( RepositorySearch.class ); searchControl = MockControl.createControl( RepositorySearch.class );
searchControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER ); searchControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
search = ( RepositorySearch ) searchControl.getMock(); search = (RepositorySearch) searchControl.getMock();
searchService = new SearchServiceImpl( userRepos, archivaDAO, repoBrowsing, search ); searchService = new SearchServiceImpl( userRepos, archivaDAO, repoBrowsing, search );
artifactDAOControl = MockControl.createControl( ArtifactDAO.class ); artifactDAOControl = MockControl.createControl( ArtifactDAO.class );
artifactDAO = ( ArtifactDAO ) artifactDAOControl.getMock(); artifactDAO = (ArtifactDAO) artifactDAOControl.getMock();
} }
// MRM-1230 // MRM-1230
public void testQuickSearchModelPackagingIsUsed() public void testQuickSearchModelPackagingIsUsed()
throws Exception throws Exception
{ {
List<String> observableRepoIds = new ArrayList<String>(); List<String> observableRepoIds = new ArrayList<String>();
observableRepoIds.add( "repo1.mirror" ); observableRepoIds.add( "repo1.mirror" );
observableRepoIds.add( "public.releases" ); observableRepoIds.add( "public.releases" );
userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds ); userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds );
SearchResults results = new SearchResults(); SearchResults results = new SearchResults();
List<String> versions = new ArrayList<String>(); List<String> versions = new ArrayList<String>();
versions.add( "1.0" ); versions.add( "1.0" );
SearchResultHit resultHit = new SearchResultHit(); SearchResultHit resultHit = new SearchResultHit();
resultHit.setGroupId( ARCHIVA_TEST_GROUP_ID ); resultHit.setGroupId( ARCHIVA_TEST_GROUP_ID );
resultHit.setArtifactId( "archiva-webapp" ); resultHit.setArtifactId( "archiva-webapp" );
resultHit.setVersions( versions ); resultHit.setVersions( versions );
resultHit.setRepositoryId( null ); resultHit.setRepositoryId( null );
results.addHit( SearchUtil.getHitId( ARCHIVA_TEST_GROUP_ID, "archiva-webapp" ), resultHit ); results.addHit( SearchUtil.getHitId( ARCHIVA_TEST_GROUP_ID, "archiva-webapp" ), resultHit );
SearchResultLimits limits = new SearchResultLimits( SearchResultLimits.ALL_PAGES ); SearchResultLimits limits = new SearchResultLimits( SearchResultLimits.ALL_PAGES );
searchControl.expectAndDefaultReturn( search.search( "", observableRepoIds, "archiva", limits, null ), results ); searchControl.expectAndDefaultReturn( search.search( "", observableRepoIds, "archiva", limits, null ),
results );
archivaDAOControl.expectAndReturn( archivaDAO.query( new UniqueVersionConstraint( observableRepoIds, resultHit.getGroupId(),
resultHit.getArtifactId() ) ), null ); archivaDAOControl.expectAndReturn( archivaDAO.query(
new UniqueVersionConstraint( observableRepoIds, resultHit.getGroupId(), resultHit.getArtifactId() ) ),
null );
ArchivaProjectModel model = new ArchivaProjectModel(); ArchivaProjectModel model = new ArchivaProjectModel();
model.setGroupId( ARCHIVA_TEST_GROUP_ID ); model.setGroupId( ARCHIVA_TEST_GROUP_ID );
model.setArtifactId( "archiva-webapp" ); model.setArtifactId( "archiva-webapp" );
model.setVersion( "1.0" ); model.setVersion( "1.0" );
model.setPackaging( "war" ); model.setPackaging( "war" );
repoBrowsingControl.expectAndReturn( repoBrowsing.selectVersion( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, "archiva-webapp", "1.0" ), model ); repoBrowsingControl.expectAndReturn(
repoBrowsing.selectVersion( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, "archiva-webapp", "1.0" ),
repoBrowsingControl.expectAndReturn( repoBrowsing.getRepositoryId( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, "archiva-webapp", "1.0" ), "repo1.mirror" ); model );
repoBrowsingControl.expectAndReturn(
repoBrowsing.getRepositoryId( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, "archiva-webapp", "1.0" ),
"repo1.mirror" );
userReposControl.replay(); userReposControl.replay();
searchControl.replay(); searchControl.replay();
repoBrowsingControl.replay(); repoBrowsingControl.replay();
archivaDAOControl.replay(); archivaDAOControl.replay();
List<Artifact> artifacts = searchService.quickSearch( "archiva" ); List<Artifact> artifacts = searchService.quickSearch( "archiva" );
userReposControl.verify(); userReposControl.verify();
searchControl.verify(); searchControl.verify();
repoBrowsingControl.verify(); repoBrowsingControl.verify();
archivaDAOControl.verify(); archivaDAOControl.verify();
assertNotNull( artifacts ); assertNotNull( artifacts );
assertEquals( 1, artifacts.size() ); assertEquals( 1, artifacts.size() );
Artifact artifact = artifacts.get( 0 ); Artifact artifact = artifacts.get( 0 );
assertEquals( ARCHIVA_TEST_GROUP_ID, artifact.getGroupId() ); assertEquals( ARCHIVA_TEST_GROUP_ID, artifact.getGroupId() );
assertEquals( "archiva-webapp", artifact.getArtifactId() ); assertEquals( "archiva-webapp", artifact.getArtifactId() );
@ -166,7 +172,7 @@ public class SearchServiceImplTest
assertNotNull( "Repository should not be null!", artifact.getRepositoryId() ); assertNotNull( "Repository should not be null!", artifact.getRepositoryId() );
assertEquals( "repo1.mirror", artifact.getRepositoryId() ); assertEquals( "repo1.mirror", artifact.getRepositoryId() );
} }
// returned model is null! // returned model is null!
public void testQuickSearchDefaultPackagingIsUsed() public void testQuickSearchDefaultPackagingIsUsed()
throws Exception throws Exception
@ -174,69 +180,74 @@ public class SearchServiceImplTest
List<String> observableRepoIds = new ArrayList<String>(); List<String> observableRepoIds = new ArrayList<String>();
observableRepoIds.add( "repo1.mirror" ); observableRepoIds.add( "repo1.mirror" );
observableRepoIds.add( "public.releases" ); observableRepoIds.add( "public.releases" );
userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds ); userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds );
SearchResults results = new SearchResults(); SearchResults results = new SearchResults();
List<String> versions = new ArrayList<String>(); List<String> versions = new ArrayList<String>();
versions.add( "1.0" ); versions.add( "1.0" );
SearchResultHit resultHit = new SearchResultHit(); SearchResultHit resultHit = new SearchResultHit();
resultHit.setRepositoryId( null ); resultHit.setRepositoryId( null );
resultHit.setGroupId( ARCHIVA_TEST_GROUP_ID ); resultHit.setGroupId( ARCHIVA_TEST_GROUP_ID );
resultHit.setArtifactId( ARCHIVA_TEST_ARTIFACT_ID ); resultHit.setArtifactId( ARCHIVA_TEST_ARTIFACT_ID );
resultHit.setVersions( versions ); resultHit.setVersions( versions );
results.addHit( SearchUtil.getHitId( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID ), resultHit ); results.addHit( SearchUtil.getHitId( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID ), resultHit );
SearchResultLimits limits = new SearchResultLimits( SearchResultLimits.ALL_PAGES ); SearchResultLimits limits = new SearchResultLimits( SearchResultLimits.ALL_PAGES );
searchControl.expectAndDefaultReturn( search.search( "", observableRepoIds, "archiva", limits, null ), results ); searchControl.expectAndDefaultReturn( search.search( "", observableRepoIds, "archiva", limits, null ),
results );
archivaDAOControl.expectAndReturn( archivaDAO.query( new UniqueVersionConstraint( observableRepoIds, resultHit.getGroupId(),
resultHit.getArtifactId() ) ), null ); archivaDAOControl.expectAndReturn( archivaDAO.query(
new UniqueVersionConstraint( observableRepoIds, resultHit.getGroupId(), resultHit.getArtifactId() ) ),
repoBrowsingControl.expectAndReturn( repoBrowsing.selectVersion( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, null );
ARCHIVA_TEST_ARTIFACT_ID, "1.0" ), null );
repoBrowsingControl.expectAndReturn(
repoBrowsingControl.expectAndReturn( repoBrowsing.getRepositoryId( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, repoBrowsing.selectVersion( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ),
ARCHIVA_TEST_ARTIFACT_ID, "1.0" ), null ); null );
repoBrowsingControl.expectAndReturn(
repoBrowsing.getRepositoryId( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID,
"1.0" ), null );
userReposControl.replay(); userReposControl.replay();
searchControl.replay(); searchControl.replay();
repoBrowsingControl.replay(); repoBrowsingControl.replay();
archivaDAOControl.replay(); archivaDAOControl.replay();
List<Artifact> artifacts = searchService.quickSearch( "archiva" ); List<Artifact> artifacts = searchService.quickSearch( "archiva" );
userReposControl.verify(); userReposControl.verify();
searchControl.verify(); searchControl.verify();
repoBrowsingControl.verify(); repoBrowsingControl.verify();
archivaDAOControl.verify(); archivaDAOControl.verify();
assertNotNull( artifacts ); assertNotNull( artifacts );
assertEquals( 1, artifacts.size() ); assertEquals( 1, artifacts.size() );
Artifact artifact = artifacts.get( 0 ); Artifact artifact = artifacts.get( 0 );
assertEquals( ARCHIVA_TEST_GROUP_ID, artifact.getGroupId() ); assertEquals( ARCHIVA_TEST_GROUP_ID, artifact.getGroupId() );
assertEquals( ARCHIVA_TEST_ARTIFACT_ID, artifact.getArtifactId() ); assertEquals( ARCHIVA_TEST_ARTIFACT_ID, artifact.getArtifactId() );
assertEquals( "1.0", artifact.getVersion() ); assertEquals( "1.0", artifact.getVersion() );
assertEquals( "jar", artifact.getType() ); assertEquals( "jar", artifact.getType() );
assertNull( "Repository should be null since the model was not found in the database!", artifact.getRepositoryId() ); assertNull( "Repository should be null since the model was not found in the database!",
artifact.getRepositoryId() );
} }
/* /*
* quick/general text search which returns a list of artifacts * quick/general text search which returns a list of artifacts
* query for an artifact based on a checksum * query for an artifact based on a checksum
* query for all available versions of an artifact, sorted in version significance order * query for all available versions of an artifact, sorted in version significance order
* query for all available versions of an artifact since a given date * query for all available versions of an artifact since a given date
* query for an artifact's direct dependencies * query for an artifact's direct dependencies
* query for an artifact's dependency tree (as with mvn dependency:tree - no duplicates should be included) * query for an artifact's dependency tree (as with mvn dependency:tree - no duplicates should be included)
* query for all artifacts that depend on a given artifact * query for all artifacts that depend on a given artifact
*/ */
/* quick search */ /* quick search */
// public void testQuickSearchArtifactBytecodeSearch() // public void testQuickSearchArtifactBytecodeSearch()
// throws Exception // throws Exception
// { // {
@ -283,62 +294,66 @@ public class SearchServiceImplTest
// assertNotNull( artifacts ); // assertNotNull( artifacts );
// assertEquals( 1, artifacts.size() ); // assertEquals( 1, artifacts.size() );
// } // }
public void testQuickSearchArtifactRegularSearch() public void testQuickSearchArtifactRegularSearch()
throws Exception throws Exception
{ {
List<String> observableRepoIds = new ArrayList<String>(); List<String> observableRepoIds = new ArrayList<String>();
observableRepoIds.add( "repo1.mirror" ); observableRepoIds.add( "repo1.mirror" );
observableRepoIds.add( "public.releases" ); observableRepoIds.add( "public.releases" );
userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds ); userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds );
SearchResults results = new SearchResults(); SearchResults results = new SearchResults();
List<String> versions = new ArrayList<String>(); List<String> versions = new ArrayList<String>();
versions.add( "1.0" ); versions.add( "1.0" );
SearchResultHit resultHit = new SearchResultHit(); SearchResultHit resultHit = new SearchResultHit();
resultHit.setGroupId( ARCHIVA_TEST_GROUP_ID ); resultHit.setGroupId( ARCHIVA_TEST_GROUP_ID );
resultHit.setArtifactId( ARCHIVA_TEST_ARTIFACT_ID ); resultHit.setArtifactId( ARCHIVA_TEST_ARTIFACT_ID );
resultHit.setVersions( versions ); resultHit.setVersions( versions );
resultHit.setRepositoryId( null ); resultHit.setRepositoryId( null );
results.addHit( SearchUtil.getHitId( resultHit.getGroupId(), resultHit.getArtifactId() ), resultHit ); results.addHit( SearchUtil.getHitId( resultHit.getGroupId(), resultHit.getArtifactId() ), resultHit );
archivaDAOControl.expectAndReturn( archivaDAO.query( new UniqueVersionConstraint( observableRepoIds, resultHit.getGroupId(), archivaDAOControl.expectAndReturn( archivaDAO.query(
resultHit.getArtifactId() ) ), null ); new UniqueVersionConstraint( observableRepoIds, resultHit.getGroupId(), resultHit.getArtifactId() ) ),
null );
SearchResultLimits limits = new SearchResultLimits( SearchResultLimits.ALL_PAGES ); SearchResultLimits limits = new SearchResultLimits( SearchResultLimits.ALL_PAGES );
searchControl.expectAndDefaultReturn( search.search( "", observableRepoIds, "archiva", limits, null ), results ); searchControl.expectAndDefaultReturn( search.search( "", observableRepoIds, "archiva", limits, null ),
results );
ArchivaProjectModel model = new ArchivaProjectModel(); ArchivaProjectModel model = new ArchivaProjectModel();
model.setGroupId( ARCHIVA_TEST_GROUP_ID ); model.setGroupId( ARCHIVA_TEST_GROUP_ID );
model.setArtifactId( ARCHIVA_TEST_ARTIFACT_ID ); model.setArtifactId( ARCHIVA_TEST_ARTIFACT_ID );
model.setVersion( "1.0" ); model.setVersion( "1.0" );
model.setPackaging( "jar" ); model.setPackaging( "jar" );
repoBrowsingControl.expectAndReturn( repoBrowsing.selectVersion( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, repoBrowsingControl.expectAndReturn(
ARCHIVA_TEST_ARTIFACT_ID, "1.0" ), model ); repoBrowsing.selectVersion( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ),
model );
repoBrowsingControl.expectAndReturn( repoBrowsing.getRepositoryId( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID,
ARCHIVA_TEST_ARTIFACT_ID, "1.0" ), "repo1.mirror" ); repoBrowsingControl.expectAndReturn(
repoBrowsing.getRepositoryId( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID,
"1.0" ), "repo1.mirror" );
userReposControl.replay(); userReposControl.replay();
searchControl.replay(); searchControl.replay();
archivaDAOControl.replay(); archivaDAOControl.replay();
repoBrowsingControl.replay(); repoBrowsingControl.replay();
List<Artifact> artifacts = searchService.quickSearch( "archiva" ); List<Artifact> artifacts = searchService.quickSearch( "archiva" );
userReposControl.verify(); userReposControl.verify();
searchControl.verify(); searchControl.verify();
archivaDAOControl.verify(); archivaDAOControl.verify();
repoBrowsingControl.verify(); repoBrowsingControl.verify();
assertNotNull( artifacts ); assertNotNull( artifacts );
assertEquals( 1, artifacts.size() ); assertEquals( 1, artifacts.size() );
Artifact artifact = artifacts.get( 0 ); Artifact artifact = artifacts.get( 0 );
assertEquals( ARCHIVA_TEST_GROUP_ID, artifact.getGroupId() ); assertEquals( ARCHIVA_TEST_GROUP_ID, artifact.getGroupId() );
assertEquals( ARCHIVA_TEST_ARTIFACT_ID, artifact.getArtifactId() ); assertEquals( ARCHIVA_TEST_ARTIFACT_ID, artifact.getArtifactId() );
@ -347,73 +362,75 @@ public class SearchServiceImplTest
assertNotNull( "Repository should not be null!", artifact.getRepositoryId() ); assertNotNull( "Repository should not be null!", artifact.getRepositoryId() );
assertEquals( "repo1.mirror", artifact.getRepositoryId() ); assertEquals( "repo1.mirror", artifact.getRepositoryId() );
} }
public void testQuickSearchNoResults( ) public void testQuickSearchNoResults()
throws Exception throws Exception
{ {
List<String> observableRepoIds = new ArrayList<String>(); List<String> observableRepoIds = new ArrayList<String>();
observableRepoIds.add( "repo1.mirror" ); observableRepoIds.add( "repo1.mirror" );
observableRepoIds.add( "public.releases" ); observableRepoIds.add( "public.releases" );
userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds ); userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds );
SearchResults results = new SearchResults(); SearchResults results = new SearchResults();
SearchResultLimits limits = new SearchResultLimits( SearchResultLimits.ALL_PAGES ); SearchResultLimits limits = new SearchResultLimits( SearchResultLimits.ALL_PAGES );
searchControl.expectAndDefaultReturn( search.search( "", observableRepoIds, "non-existent", limits, null ), results ); searchControl.expectAndDefaultReturn( search.search( "", observableRepoIds, "non-existent", limits, null ),
results );
userReposControl.replay(); userReposControl.replay();
searchControl.replay(); searchControl.replay();
List<Artifact> artifacts = searchService.quickSearch( "test" ); List<Artifact> artifacts = searchService.quickSearch( "test" );
userReposControl.verify(); userReposControl.verify();
searchControl.verify(); searchControl.verify();
assertNotNull( artifacts ); assertNotNull( artifacts );
assertEquals( 0, artifacts.size() ); assertEquals( 0, artifacts.size() );
} }
/* query artifact by checksum */ /* query artifact by checksum */
public void testGetArtifactByChecksum() public void testGetArtifactByChecksum()
throws Exception throws Exception
{ {
Date whenGathered = new Date(); Date whenGathered = new Date();
ArtifactsByChecksumConstraint constraint = new ArtifactsByChecksumConstraint( "a1b2c3aksjhdasfkdasasd" ); ArtifactsByChecksumConstraint constraint = new ArtifactsByChecksumConstraint( "a1b2c3aksjhdasfkdasasd" );
List<ArchivaArtifact> artifacts = new ArrayList<ArchivaArtifact>(); List<ArchivaArtifact> artifacts = new ArrayList<ArchivaArtifact>();
ArchivaArtifact artifact = new ArchivaArtifact( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0", "", "jar", "test-repo" ); ArchivaArtifact artifact =
new ArchivaArtifact( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0", "", "jar", "test-repo" );
artifact.getModel().setWhenGathered( whenGathered ); artifact.getModel().setWhenGathered( whenGathered );
artifacts.add( artifact ); artifacts.add( artifact );
archivaDAOControl.expectAndReturn( archivaDAO.getArtifactDAO(), artifactDAO ); archivaDAOControl.expectAndReturn( archivaDAO.getArtifactDAO(), artifactDAO );
artifactDAO.queryArtifacts( constraint ); artifactDAO.queryArtifacts( constraint );
artifactDAOControl.setMatcher( MockControl.ALWAYS_MATCHER ); artifactDAOControl.setMatcher( MockControl.ALWAYS_MATCHER );
artifactDAOControl.setReturnValue( artifacts ); artifactDAOControl.setReturnValue( artifacts );
archivaDAOControl.replay(); archivaDAOControl.replay();
artifactDAOControl.replay(); artifactDAOControl.replay();
List<Artifact> results = searchService.getArtifactByChecksum( "a1b2c3aksjhdasfkdasasd" ); List<Artifact> results = searchService.getArtifactByChecksum( "a1b2c3aksjhdasfkdasasd" );
archivaDAOControl.verify(); archivaDAOControl.verify();
artifactDAOControl.verify(); artifactDAOControl.verify();
assertNotNull( results ); assertNotNull( results );
assertEquals( 1, results.size() ); assertEquals( 1, results.size() );
} }
/* query artifact versions */ /* query artifact versions */
public void testGetArtifactVersionsArtifactExists() public void testGetArtifactVersionsArtifactExists()
throws Exception throws Exception
{ {
Date whenGathered = new Date(); Date whenGathered = new Date();
List<String> observableRepoIds = new ArrayList<String>(); List<String> observableRepoIds = new ArrayList<String>();
observableRepoIds.add( "repo1.mirror" ); observableRepoIds.add( "repo1.mirror" );
observableRepoIds.add( "public.releases" ); observableRepoIds.add( "public.releases" );
List<String> versions = new ArrayList<String>(); List<String> versions = new ArrayList<String>();
versions.add( "1.0" ); versions.add( "1.0" );
versions.add( "1.1-beta-1" ); versions.add( "1.1-beta-1" );
@ -421,141 +438,163 @@ public class SearchServiceImplTest
versions.add( "1.1" ); versions.add( "1.1" );
versions.add( "1.2" ); versions.add( "1.2" );
versions.add( "1.2.1-SNAPSHOT" ); versions.add( "1.2.1-SNAPSHOT" );
BrowsingResults results = new BrowsingResults( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID ); BrowsingResults results = new BrowsingResults( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID );
results.setSelectedRepositoryIds( observableRepoIds ); results.setSelectedRepositoryIds( observableRepoIds );
results.setVersions( versions ); results.setVersions( versions );
List<ArchivaArtifact> archivaArtifacts = new ArrayList<ArchivaArtifact>(); List<ArchivaArtifact> archivaArtifacts = new ArrayList<ArchivaArtifact>();
ArchivaArtifact archivaArtifact = new ArchivaArtifact( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, versions.get( 0 ), "", "pom", "repo1.mirror" ); ArchivaArtifact archivaArtifact =
new ArchivaArtifact( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, versions.get( 0 ), "", "pom",
"repo1.mirror" );
archivaArtifact.getModel().setWhenGathered( whenGathered ); archivaArtifact.getModel().setWhenGathered( whenGathered );
archivaArtifacts.add( archivaArtifact ); archivaArtifacts.add( archivaArtifact );
archivaArtifact = new ArchivaArtifact( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, versions.get( 1 ), "", "pom", "public.releases" ); archivaArtifact =
new ArchivaArtifact( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, versions.get( 1 ), "", "pom",
"public.releases" );
archivaArtifact.getModel().setWhenGathered( whenGathered ); archivaArtifact.getModel().setWhenGathered( whenGathered );
archivaArtifacts.add( archivaArtifact ); archivaArtifacts.add( archivaArtifact );
archivaArtifact = new ArchivaArtifact( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, versions.get( 2 ), "", "pom", "repo1.mirror" ); archivaArtifact =
new ArchivaArtifact( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, versions.get( 2 ), "", "pom",
"repo1.mirror" );
archivaArtifact.getModel().setWhenGathered( whenGathered ); archivaArtifact.getModel().setWhenGathered( whenGathered );
archivaArtifacts.add( archivaArtifact ); archivaArtifacts.add( archivaArtifact );
archivaArtifact = new ArchivaArtifact( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, versions.get( 3 ), "", "pom", "public.releases" ); archivaArtifact =
new ArchivaArtifact( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, versions.get( 3 ), "", "pom",
"public.releases" );
archivaArtifact.getModel().setWhenGathered( whenGathered ); archivaArtifact.getModel().setWhenGathered( whenGathered );
archivaArtifacts.add( archivaArtifact ); archivaArtifacts.add( archivaArtifact );
archivaArtifact = new ArchivaArtifact( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, versions.get( 4 ), "", "pom", "repo1.mirror" ); archivaArtifact =
new ArchivaArtifact( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, versions.get( 4 ), "", "pom",
"repo1.mirror" );
archivaArtifact.getModel().setWhenGathered( whenGathered ); archivaArtifact.getModel().setWhenGathered( whenGathered );
archivaArtifacts.add( archivaArtifact ); archivaArtifacts.add( archivaArtifact );
archivaArtifact = new ArchivaArtifact( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, versions.get( 5 ), "", "pom", "public.releases" ); archivaArtifact =
new ArchivaArtifact( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, versions.get( 5 ), "", "pom",
"public.releases" );
archivaArtifact.getModel().setWhenGathered( whenGathered ); archivaArtifact.getModel().setWhenGathered( whenGathered );
archivaArtifacts.add( archivaArtifact ); archivaArtifacts.add( archivaArtifact );
userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds ); userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds );
repoBrowsingControl.expectAndReturn( repoBrowsing.selectArtifactId( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, repoBrowsingControl.expectAndReturn(
ARCHIVA_TEST_ARTIFACT_ID ), results ); repoBrowsing.selectArtifactId( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID ),
results );
archivaDAOControl.expectAndReturn( archivaDAO.getArtifactDAO(), artifactDAO ); archivaDAOControl.expectAndReturn( archivaDAO.getArtifactDAO(), artifactDAO );
artifactDAOControl.expectAndDefaultReturn( artifactDAO.getArtifact( ARCHIVA_TEST_GROUP_ID, artifactDAOControl.expectAndDefaultReturn(
ARCHIVA_TEST_ARTIFACT_ID, versions.get( 0 ), "", "pom", "repo1.mirror" ), archivaArtifacts.get( 0 ) ); artifactDAO.getArtifact( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, versions.get( 0 ), "", "pom",
artifactDAOControl.expectAndDefaultReturn( artifactDAO.getArtifact( ARCHIVA_TEST_GROUP_ID, "repo1.mirror" ), archivaArtifacts.get( 0 ) );
ARCHIVA_TEST_ARTIFACT_ID, versions.get( 1 ), "", "pom", "public.releases" ), archivaArtifacts.get( 1 ) ); artifactDAOControl.expectAndDefaultReturn(
artifactDAOControl.expectAndDefaultReturn( artifactDAO.getArtifact( ARCHIVA_TEST_GROUP_ID, artifactDAO.getArtifact( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, versions.get( 1 ), "", "pom",
ARCHIVA_TEST_ARTIFACT_ID, versions.get( 2 ), "", "pom", "repo1.mirror" ), archivaArtifacts.get( 2 ) ); "public.releases" ), archivaArtifacts.get( 1 ) );
artifactDAOControl.expectAndDefaultReturn( artifactDAO.getArtifact( ARCHIVA_TEST_GROUP_ID, artifactDAOControl.expectAndDefaultReturn(
ARCHIVA_TEST_ARTIFACT_ID, versions.get( 3 ), "", "pom", "public.releases" ), archivaArtifacts.get( 3 ) ); artifactDAO.getArtifact( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, versions.get( 2 ), "", "pom",
artifactDAOControl.expectAndDefaultReturn( artifactDAO.getArtifact( ARCHIVA_TEST_GROUP_ID, "repo1.mirror" ), archivaArtifacts.get( 2 ) );
ARCHIVA_TEST_ARTIFACT_ID, versions.get( 4 ), "", "pom", "repo1.mirror" ), archivaArtifacts.get( 4 ) ); artifactDAOControl.expectAndDefaultReturn(
artifactDAOControl.expectAndDefaultReturn( artifactDAO.getArtifact( ARCHIVA_TEST_GROUP_ID, artifactDAO.getArtifact( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, versions.get( 3 ), "", "pom",
ARCHIVA_TEST_ARTIFACT_ID, versions.get( 5 ), "", "pom", "public.releases" ), archivaArtifacts.get( 5 ) ); "public.releases" ), archivaArtifacts.get( 3 ) );
artifactDAOControl.expectAndDefaultReturn(
artifactDAO.getArtifact( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, versions.get( 4 ), "", "pom",
"repo1.mirror" ), archivaArtifacts.get( 4 ) );
artifactDAOControl.expectAndDefaultReturn(
artifactDAO.getArtifact( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, versions.get( 5 ), "", "pom",
"public.releases" ), archivaArtifacts.get( 5 ) );
userReposControl.replay(); userReposControl.replay();
repoBrowsingControl.replay(); repoBrowsingControl.replay();
artifactDAOControl.replay(); artifactDAOControl.replay();
List<Artifact> artifacts = searchService.getArtifactVersions( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID ); List<Artifact> artifacts = searchService.getArtifactVersions( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID );
userReposControl.verify(); userReposControl.verify();
repoBrowsingControl.verify(); repoBrowsingControl.verify();
artifactDAOControl.verify(); artifactDAOControl.verify();
assertNotNull( artifacts ); assertNotNull( artifacts );
assertEquals( 6, artifacts.size() ); assertEquals( 6, artifacts.size() );
} }
/* query artifact versions since a given date */ /* query artifact versions since a given date */
public void testGetArtifactVersionsByDateArtifactExists() public void testGetArtifactVersionsByDateArtifactExists()
throws Exception throws Exception
{ {
} }
public void testGetArtifactVersionsByDateArtifactDoesNotExist() public void testGetArtifactVersionsByDateArtifactDoesNotExist()
throws Exception throws Exception
{ {
} }
/* query artifact dependencies */ /* query artifact dependencies */
public void testGetDependenciesArtifactExists() public void testGetDependenciesArtifactExists()
throws Exception throws Exception
{ {
List<String> observableRepoIds = new ArrayList<String>(); List<String> observableRepoIds = new ArrayList<String>();
observableRepoIds.add( "repo1.mirror" ); observableRepoIds.add( "repo1.mirror" );
observableRepoIds.add( "public.releases" ); observableRepoIds.add( "public.releases" );
ArchivaProjectModel model = new ArchivaProjectModel(); ArchivaProjectModel model = new ArchivaProjectModel();
model.setGroupId( ARCHIVA_TEST_GROUP_ID ); model.setGroupId( ARCHIVA_TEST_GROUP_ID );
model.setArtifactId( ARCHIVA_TEST_ARTIFACT_ID ); model.setArtifactId( ARCHIVA_TEST_ARTIFACT_ID );
model.setVersion( "1.0" ); model.setVersion( "1.0" );
org.apache.maven.archiva.model.Dependency dependency = new org.apache.maven.archiva.model.Dependency(); org.apache.maven.archiva.model.Dependency dependency = new org.apache.maven.archiva.model.Dependency();
dependency.setGroupId( "commons-logging" ); dependency.setGroupId( "commons-logging" );
dependency.setArtifactId( "commons-logging" ); dependency.setArtifactId( "commons-logging" );
dependency.setVersion( "2.0" ); dependency.setVersion( "2.0" );
model.addDependency( dependency ); model.addDependency( dependency );
dependency = new org.apache.maven.archiva.model.Dependency(); dependency = new org.apache.maven.archiva.model.Dependency();
dependency.setGroupId( "junit" ); dependency.setGroupId( "junit" );
dependency.setArtifactId( "junit" ); dependency.setArtifactId( "junit" );
dependency.setVersion( "2.4" ); dependency.setVersion( "2.4" );
dependency.setScope( "test" ); dependency.setScope( "test" );
model.addDependency( dependency ); model.addDependency( dependency );
userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds ); userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds );
repoBrowsingControl.expectAndReturn( repoBrowsingControl.expectAndReturn(
repoBrowsing.selectVersion( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ), model ); repoBrowsing.selectVersion( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ),
model );
repoBrowsingControl.replay();
repoBrowsingControl.replay();
userReposControl.replay(); userReposControl.replay();
List<Dependency> dependencies = searchService.getDependencies( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ); List<Dependency> dependencies =
searchService.getDependencies( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" );
repoBrowsingControl.verify(); repoBrowsingControl.verify();
userReposControl.verify(); userReposControl.verify();
assertNotNull( dependencies ); assertNotNull( dependencies );
assertEquals( 2, dependencies.size() ); assertEquals( 2, dependencies.size() );
} }
public void testGetDependenciesArtifactDoesNotExist() public void testGetDependenciesArtifactDoesNotExist()
throws Exception throws Exception
{ {
List<String> observableRepoIds = new ArrayList<String>(); List<String> observableRepoIds = new ArrayList<String>();
observableRepoIds.add( "repo1.mirror" ); observableRepoIds.add( "repo1.mirror" );
observableRepoIds.add( "public.releases" ); observableRepoIds.add( "public.releases" );
userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds ); userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds );
repoBrowsingControl.expectAndThrow( repoBrowsingControl.expectAndThrow(
repoBrowsing.selectVersion( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ), new ObjectNotFoundException( "Artifact does not exist." ) ); repoBrowsing.selectVersion( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ),
new ObjectNotFoundException( "Artifact does not exist." ) );
userReposControl.replay(); userReposControl.replay();
repoBrowsingControl.replay(); repoBrowsingControl.replay();
try try
{ {
searchService.getDependencies( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ); searchService.getDependencies( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" );
@ -565,23 +604,23 @@ public class SearchServiceImplTest
{ {
assertEquals( "Artifact does not exist.", e.getMessage() ); assertEquals( "Artifact does not exist.", e.getMessage() );
} }
userReposControl.verify(); userReposControl.verify();
repoBrowsingControl.verify(); repoBrowsingControl.verify();
} }
public void testGetDependencyTreeArtifactExists() public void testGetDependencyTreeArtifactExists()
throws Exception throws Exception
{ {
// TODO // TODO
} }
public void testGetDependencyTreeArtifactDoesNotExist() public void testGetDependencyTreeArtifactDoesNotExist()
throws Exception throws Exception
{ {
// TODO // TODO
} }
public void testGetDependees() public void testGetDependees()
throws Exception throws Exception
{ {
@ -589,7 +628,7 @@ public class SearchServiceImplTest
List<String> observableRepoIds = new ArrayList<String>(); List<String> observableRepoIds = new ArrayList<String>();
observableRepoIds.add( "repo1.mirror" ); observableRepoIds.add( "repo1.mirror" );
observableRepoIds.add( "public.releases" ); observableRepoIds.add( "public.releases" );
List<ArchivaProjectModel> dependeeModels = new ArrayList<ArchivaProjectModel>(); List<ArchivaProjectModel> dependeeModels = new ArrayList<ArchivaProjectModel>();
ArchivaProjectModel dependeeModel = new ArchivaProjectModel(); ArchivaProjectModel dependeeModel = new ArchivaProjectModel();
dependeeModel.setGroupId( ARCHIVA_TEST_GROUP_ID ); dependeeModel.setGroupId( ARCHIVA_TEST_GROUP_ID );
@ -597,30 +636,31 @@ public class SearchServiceImplTest
dependeeModel.setVersion( "1.0" ); dependeeModel.setVersion( "1.0" );
dependeeModel.setWhenIndexed( date ); dependeeModel.setWhenIndexed( date );
dependeeModels.add( dependeeModel ); dependeeModels.add( dependeeModel );
dependeeModel = new ArchivaProjectModel(); dependeeModel = new ArchivaProjectModel();
dependeeModel.setGroupId( ARCHIVA_TEST_GROUP_ID ); dependeeModel.setGroupId( ARCHIVA_TEST_GROUP_ID );
dependeeModel.setArtifactId( "archiva-dependee-two" ); dependeeModel.setArtifactId( "archiva-dependee-two" );
dependeeModel.setVersion( "1.0" ); dependeeModel.setVersion( "1.0" );
dependeeModel.setWhenIndexed( date ); dependeeModel.setWhenIndexed( date );
dependeeModels.add( dependeeModel ); dependeeModels.add( dependeeModel );
userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds ); userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds );
repoBrowsingControl.expectAndReturn( repoBrowsing.getUsedBy( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, repoBrowsingControl.expectAndReturn(
ARCHIVA_TEST_ARTIFACT_ID, "1.0" ), dependeeModels ); repoBrowsing.getUsedBy( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ),
dependeeModels );
repoBrowsingControl.replay();
repoBrowsingControl.replay();
userReposControl.replay(); userReposControl.replay();
List<Artifact> dependees = searchService.getDependees( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ); List<Artifact> dependees = searchService.getDependees( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" );
repoBrowsingControl.verify(); repoBrowsingControl.verify();
userReposControl.verify(); userReposControl.verify();
assertNotNull( dependees ); assertNotNull( dependees );
assertEquals( 2, dependees.size() ); assertEquals( 2, dependees.size() );
} }
public void testGetDependeesArtifactDoesNotExist() public void testGetDependeesArtifactDoesNotExist()
throws Exception throws Exception
{ {
@ -628,7 +668,7 @@ public class SearchServiceImplTest
List<String> observableRepoIds = new ArrayList<String>(); List<String> observableRepoIds = new ArrayList<String>();
observableRepoIds.add( "repo1.mirror" ); observableRepoIds.add( "repo1.mirror" );
observableRepoIds.add( "public.releases" ); observableRepoIds.add( "public.releases" );
List dependeeModels = new ArrayList(); List dependeeModels = new ArrayList();
ArchivaProjectModel dependeeModel = new ArchivaProjectModel(); ArchivaProjectModel dependeeModel = new ArchivaProjectModel();
dependeeModel.setGroupId( ARCHIVA_TEST_GROUP_ID ); dependeeModel.setGroupId( ARCHIVA_TEST_GROUP_ID );
@ -636,24 +676,26 @@ public class SearchServiceImplTest
dependeeModel.setVersion( "1.0" ); dependeeModel.setVersion( "1.0" );
dependeeModel.setWhenIndexed( date ); dependeeModel.setWhenIndexed( date );
dependeeModels.add( dependeeModel ); dependeeModels.add( dependeeModel );
dependeeModel = new ArchivaProjectModel(); dependeeModel = new ArchivaProjectModel();
dependeeModel.setGroupId( ARCHIVA_TEST_GROUP_ID ); dependeeModel.setGroupId( ARCHIVA_TEST_GROUP_ID );
dependeeModel.setArtifactId( "archiva-dependee-two" ); dependeeModel.setArtifactId( "archiva-dependee-two" );
dependeeModel.setVersion( "1.0" ); dependeeModel.setVersion( "1.0" );
dependeeModel.setWhenIndexed( date ); dependeeModel.setWhenIndexed( date );
dependeeModels.add( dependeeModel ); dependeeModels.add( dependeeModel );
userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds ); userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds );
repoBrowsingControl.expectAndReturn( repoBrowsing.getUsedBy( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, repoBrowsingControl.expectAndReturn(
ARCHIVA_TEST_ARTIFACT_ID, "1.0" ), null ); repoBrowsing.getUsedBy( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ),
null );
repoBrowsingControl.replay();
repoBrowsingControl.replay();
userReposControl.replay(); userReposControl.replay();
try try
{ {
List<Artifact> dependees = searchService.getDependees( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ); List<Artifact> dependees =
searchService.getDependees( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" );
fail( "An exception should have been thrown." ); fail( "An exception should have been thrown." );
} }
catch ( Exception e ) catch ( Exception e )