/**
* SearchServiceImpl
- *
+ *
* quick/general text search which returns a list of artifacts
* 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 since a given date
* 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 all artifacts that depend on a given artifact
- *
+ * query for all artifacts that depend on a given artifact
+ *
* @version $Id: SearchServiceImpl.java
*/
public class SearchServiceImpl
implements SearchService
-{
+{
private Logger log = LoggerFactory.getLogger( SearchServiceImpl.class );
-
+
private RepositorySearch search;
-
+
private XmlRpcUserRepositories xmlRpcUserRepositories;
-
+
private ArchivaDAO archivaDAO;
-
+
private RepositoryBrowsing repoBrowsing;
-
+
public SearchServiceImpl( XmlRpcUserRepositories xmlRpcUserRepositories, ArchivaDAO archivaDAO,
RepositoryBrowsing repoBrowsing, RepositorySearch search )
{
this.xmlRpcUserRepositories = xmlRpcUserRepositories;
- this.archivaDAO = archivaDAO;
+ this.archivaDAO = archivaDAO;
this.repoBrowsing = repoBrowsing;
this.search = search;
}
-
- @SuppressWarnings( "unchecked" )
+
+ @SuppressWarnings("unchecked")
public List<Artifact> quickSearch( String queryString )
throws Exception
- {
+ {
List<Artifact> artifacts = new ArrayList<Artifact>();
List<String> observableRepos = xmlRpcUserRepositories.getObservableRepositories();
SearchResultLimits limits = new SearchResultLimits( SearchResultLimits.ALL_PAGES );
SearchResults results = null;
-
+
results = search.search( "", observableRepos, queryString, limits, null );
-
+
for ( SearchResultHit resultHit : results.getHits() )
{
// double-check all versions as done in SearchAction
- final List<String> versions =
- (List<String>) archivaDAO.query( new UniqueVersionConstraint( observableRepos, resultHit.getGroupId(),
- resultHit.getArtifactId() ) );
+ final List<String> versions = (List<String>) archivaDAO.query(
+ new UniqueVersionConstraint( observableRepos, resultHit.getGroupId(), resultHit.getArtifactId() ) );
if ( versions != null && !versions.isEmpty() )
{
resultHit.setVersion( null );
resultHit.setVersions( filterTimestampedSnapshots( versions ) );
}
-
+
List<String> resultHitVersions = resultHit.getVersions();
- if( resultHitVersions != null )
+ if ( resultHitVersions != null )
{
- for( String version : resultHitVersions )
- {
+ for ( String version : resultHitVersions )
+ {
try
{
- ArchivaProjectModel model = repoBrowsing.selectVersion( "", observableRepos, resultHit.getGroupId(), resultHit.getArtifactId(), version );
-
- String repoId = repoBrowsing.getRepositoryId( "", observableRepos, resultHit.getGroupId(), resultHit.getArtifactId(), version );
-
+ ArchivaProjectModel model =
+ repoBrowsing.selectVersion( "", observableRepos, resultHit.getGroupId(),
+ resultHit.getArtifactId(), version );
+
+ String repoId = repoBrowsing.getRepositoryId( "", observableRepos, resultHit.getGroupId(),
+ resultHit.getArtifactId(), version );
+
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
- {
- 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 );
}
- catch( ObjectNotFoundException e )
- {
- log.debug( "Unable to find pom artifact : " + e.getMessage() );
+ catch ( ObjectNotFoundException e )
+ {
+ 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() );
}
}
}
- }
-
+ }
+
return artifacts;
}
-
+
/**
* 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>();
- for (final String version : versions)
+ for ( final String version : versions )
{
- final String baseVersion = VersionUtil.getBaseVersion(version);
- if (!filtered.contains(baseVersion))
+ final String baseVersion = VersionUtil.getBaseVersion( version );
+ if ( !filtered.contains( baseVersion ) )
{
- filtered.add(baseVersion);
+ filtered.add( baseVersion );
}
}
return filtered;
}
-
- public List<Artifact> getArtifactByChecksum( String checksum )
+
+ public List<Artifact> getArtifactByChecksum( String checksum )
throws Exception
{
// 1. get ArtifactDAO from ArchivaDAO
// 2. create ArtifactsByChecksumConstraint( "queryTerm" )
// 3. query artifacts using constraint
// 4. convert results to list of Artifact objects
-
+
List<Artifact> results = new ArrayList<Artifact>();
ArtifactDAO artifactDAO = archivaDAO.getArtifactDAO();
-
+
ArtifactsByChecksumConstraint constraint = new ArtifactsByChecksumConstraint( checksum );
List<ArchivaArtifact> artifacts = artifactDAO.queryArtifacts( constraint );
-
- for( ArchivaArtifact archivaArtifact : artifacts )
+
+ for ( ArchivaArtifact archivaArtifact : artifacts )
{
- Artifact artifact = new Artifact( archivaArtifact.getModel().getRepositoryId(), archivaArtifact.getModel().getGroupId(),
- archivaArtifact.getModel().getArtifactId(), archivaArtifact.getModel().getVersion(), archivaArtifact.getType() );
- //archivaArtifact.getModel().getWhenGathered() );
+ Artifact artifact =
+ new Artifact( archivaArtifact.getModel().getRepositoryId(), archivaArtifact.getModel().getGroupId(),
+ archivaArtifact.getModel().getArtifactId(), archivaArtifact.getModel().getVersion(),
+ archivaArtifact.getType() );
+ //archivaArtifact.getModel().getWhenGathered() );
results.add( artifact );
}
-
+
return results;
}
-
- public List<Artifact> getArtifactVersions( String groupId, String artifactId )
+
+ public List<Artifact> getArtifactVersions( String groupId, String artifactId )
throws Exception
{
- final List<Artifact> artifacts = new ArrayList<Artifact>();
+ final List<Artifact> artifacts = new ArrayList<Artifact>();
final List<String> observableRepos = xmlRpcUserRepositories.getObservableRepositories();
-
+
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", );
//Artifact artifact = new Artifact( "", groupId, artifactId, version, pomArtifact.getType() );
- //pomArtifact.getModel().getWhenGathered() );
-
+ //pomArtifact.getModel().getWhenGathered() );
+
artifacts.add( artifact );
}
-
+
// 1. get observable repositories
// 2. use RepositoryBrowsing method to query uniqueVersions?
return artifacts;
}
-
+
public List<Artifact> getArtifactVersionsByDate( String groupId, String artifactId, String version, Date since )
throws Exception
{
List<Artifact> artifacts = new ArrayList<Artifact>();
-
+
// 1. get observable repositories
// 2. use RepositoryBrowsing method to query uniqueVersions? (but with date)
-
+
return artifacts;
}
-
- public List<Dependency> getDependencies( String groupId, String artifactId, String version )
+
+ public List<Dependency> getDependencies( String groupId, String artifactId, String version )
throws Exception
- {
- List<Dependency> dependencies = new ArrayList<Dependency>();
+ {
+ List<Dependency> dependencies = new ArrayList<Dependency>();
List<String> observableRepos = xmlRpcUserRepositories.getObservableRepositories();
-
+
try
{
ArchivaProjectModel model = repoBrowsing.selectVersion( "", observableRepos, groupId, artifactId, version );
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(
- dep.getGroupId(), dep.getArtifactId(), dep.getVersion(), dep.getClassifier(), dep.getType(), dep.getScope() );
+ Dependency dependency =
+ new Dependency( dep.getGroupId(), dep.getArtifactId(), dep.getVersion(), dep.getClassifier(),
+ dep.getType(), dep.getScope() );
dependencies.add( dependency );
}
}
{
throw new Exception( "Artifact does not exist." );
}
-
+
return dependencies;
}
-
- public List<Artifact> getDependencyTree( String groupId, String artifactId, String version )
+
+ public List<Artifact> getDependencyTree( String groupId, String artifactId, String version )
throws Exception
{
List<Artifact> a = new ArrayList<Artifact>();
-
+
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 )
throws Exception
{
List<Artifact> artifacts = new ArrayList<Artifact>();
List<String> observableRepos = xmlRpcUserRepositories.getObservableRepositories();
-
- List<ArchivaProjectModel> dependees = repoBrowsing.getUsedBy( "", observableRepos, groupId, artifactId, version );
- for( ArchivaProjectModel model : dependees )
+
+ List<ArchivaProjectModel> dependees =
+ repoBrowsing.getUsedBy( "", observableRepos, groupId, artifactId, version );
+ for ( ArchivaProjectModel model : dependees )
{
- Artifact artifact =
- new Artifact( "", model.getGroupId(), model.getArtifactId(), model.getVersion(), "" );
- //model.getWhenIndexed() );
+ Artifact artifact = new Artifact( "", model.getGroupId(), model.getArtifactId(), model.getVersion(), "" );
+ //model.getWhenIndexed() );
artifacts.add( artifact );
}
-
+
return artifacts;
}
}
* specific language governing permissions and limitations
* under the License.
*/
-
+
import java.util.ArrayList;
import java.util.Date;
/**
* SearchServiceImplTest
- *
+ *
* @version $Id: SearchServiceImplTest.java
*/
public class SearchServiceImplTest
extends PlexusInSpringTestCase
{
private SearchService searchService;
-
+
private MockControl userReposControl;
-
+
private XmlRpcUserRepositories userRepos;
-
+
private MockControl searchControl;
-
+
private RepositorySearch search;
-
+
private MockControl archivaDAOControl;
-
+
private ArchivaDAO archivaDAO;
-
+
private MockControl artifactDAOControl;
-
+
private ArtifactDAO artifactDAO;
-
+
private MockControl repoBrowsingControl;
-
+
private RepositoryBrowsing repoBrowsing;
private static final String ARCHIVA_TEST_ARTIFACT_ID = "archiva-xmlrpc-test";
throws Exception
{
userReposControl = MockClassControl.createControl( XmlRpcUserRepositories.class );
- userRepos = ( XmlRpcUserRepositories ) userReposControl.getMock();
-
+ userRepos = (XmlRpcUserRepositories) userReposControl.getMock();
+
archivaDAOControl = MockControl.createControl( ArchivaDAO.class );
archivaDAOControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
- archivaDAO = ( ArchivaDAO ) archivaDAOControl.getMock();
-
+ archivaDAO = (ArchivaDAO) archivaDAOControl.getMock();
+
repoBrowsingControl = MockControl.createControl( RepositoryBrowsing.class );
- repoBrowsing = ( RepositoryBrowsing ) repoBrowsingControl.getMock();
-
+ repoBrowsing = (RepositoryBrowsing) repoBrowsingControl.getMock();
+
searchControl = MockControl.createControl( RepositorySearch.class );
searchControl.setDefaultMatcher( MockControl.ALWAYS_MATCHER );
- search = ( RepositorySearch ) searchControl.getMock();
-
+ search = (RepositorySearch) searchControl.getMock();
+
searchService = new SearchServiceImpl( userRepos, archivaDAO, repoBrowsing, search );
-
- artifactDAOControl = MockControl.createControl( ArtifactDAO.class );
- artifactDAO = ( ArtifactDAO ) artifactDAOControl.getMock();
+
+ artifactDAOControl = MockControl.createControl( ArtifactDAO.class );
+ artifactDAO = (ArtifactDAO) artifactDAOControl.getMock();
}
-
+
// MRM-1230
public void testQuickSearchModelPackagingIsUsed()
throws Exception
- {
+ {
List<String> observableRepoIds = new ArrayList<String>();
observableRepoIds.add( "repo1.mirror" );
observableRepoIds.add( "public.releases" );
-
+
userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds );
-
- SearchResults results = new SearchResults();
+
+ SearchResults results = new SearchResults();
List<String> versions = new ArrayList<String>();
versions.add( "1.0" );
-
+
SearchResultHit resultHit = new SearchResultHit();
resultHit.setGroupId( ARCHIVA_TEST_GROUP_ID );
- resultHit.setArtifactId( "archiva-webapp" );
+ resultHit.setArtifactId( "archiva-webapp" );
resultHit.setVersions( versions );
resultHit.setRepositoryId( null );
-
+
results.addHit( SearchUtil.getHitId( ARCHIVA_TEST_GROUP_ID, "archiva-webapp" ), resultHit );
-
+
SearchResultLimits limits = new SearchResultLimits( SearchResultLimits.ALL_PAGES );
-
- searchControl.expectAndDefaultReturn( search.search( "", observableRepoIds, "archiva", limits, null ), results );
-
- archivaDAOControl.expectAndReturn( archivaDAO.query( new UniqueVersionConstraint( observableRepoIds, resultHit.getGroupId(),
- resultHit.getArtifactId() ) ), null );
-
+
+ searchControl.expectAndDefaultReturn( search.search( "", observableRepoIds, "archiva", limits, null ),
+ results );
+
+ archivaDAOControl.expectAndReturn( archivaDAO.query(
+ new UniqueVersionConstraint( observableRepoIds, resultHit.getGroupId(), resultHit.getArtifactId() ) ),
+ null );
+
ArchivaProjectModel model = new ArchivaProjectModel();
model.setGroupId( ARCHIVA_TEST_GROUP_ID );
model.setArtifactId( "archiva-webapp" );
model.setVersion( "1.0" );
model.setPackaging( "war" );
-
- repoBrowsingControl.expectAndReturn( repoBrowsing.selectVersion( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, "archiva-webapp", "1.0" ), model );
-
- repoBrowsingControl.expectAndReturn( repoBrowsing.getRepositoryId( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, "archiva-webapp", "1.0" ), "repo1.mirror" );
-
+
+ repoBrowsingControl.expectAndReturn(
+ repoBrowsing.selectVersion( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, "archiva-webapp", "1.0" ),
+ model );
+
+ repoBrowsingControl.expectAndReturn(
+ repoBrowsing.getRepositoryId( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, "archiva-webapp", "1.0" ),
+ "repo1.mirror" );
+
userReposControl.replay();
searchControl.replay();
repoBrowsingControl.replay();
archivaDAOControl.replay();
-
+
List<Artifact> artifacts = searchService.quickSearch( "archiva" );
-
+
userReposControl.verify();
searchControl.verify();
repoBrowsingControl.verify();
archivaDAOControl.verify();
-
+
assertNotNull( artifacts );
assertEquals( 1, artifacts.size() );
-
+
Artifact artifact = artifacts.get( 0 );
assertEquals( ARCHIVA_TEST_GROUP_ID, artifact.getGroupId() );
assertEquals( "archiva-webapp", artifact.getArtifactId() );
assertNotNull( "Repository should not be null!", artifact.getRepositoryId() );
assertEquals( "repo1.mirror", artifact.getRepositoryId() );
}
-
+
// returned model is null!
public void testQuickSearchDefaultPackagingIsUsed()
throws Exception
List<String> observableRepoIds = new ArrayList<String>();
observableRepoIds.add( "repo1.mirror" );
observableRepoIds.add( "public.releases" );
-
+
userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds );
-
- SearchResults results = new SearchResults();
+
+ SearchResults results = new SearchResults();
List<String> versions = new ArrayList<String>();
versions.add( "1.0" );
-
+
SearchResultHit resultHit = new SearchResultHit();
resultHit.setRepositoryId( null );
resultHit.setGroupId( ARCHIVA_TEST_GROUP_ID );
resultHit.setArtifactId( ARCHIVA_TEST_ARTIFACT_ID );
resultHit.setVersions( versions );
-
+
results.addHit( SearchUtil.getHitId( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID ), resultHit );
-
+
SearchResultLimits limits = new SearchResultLimits( SearchResultLimits.ALL_PAGES );
-
- searchControl.expectAndDefaultReturn( search.search( "", observableRepoIds, "archiva", limits, null ), results );
-
- archivaDAOControl.expectAndReturn( archivaDAO.query( new UniqueVersionConstraint( observableRepoIds, resultHit.getGroupId(),
- resultHit.getArtifactId() ) ), null );
-
- repoBrowsingControl.expectAndReturn( repoBrowsing.selectVersion( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID,
- ARCHIVA_TEST_ARTIFACT_ID, "1.0" ), null );
-
- repoBrowsingControl.expectAndReturn( repoBrowsing.getRepositoryId( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID,
- ARCHIVA_TEST_ARTIFACT_ID, "1.0" ), null );
-
+
+ searchControl.expectAndDefaultReturn( search.search( "", observableRepoIds, "archiva", limits, null ),
+ results );
+
+ archivaDAOControl.expectAndReturn( archivaDAO.query(
+ new UniqueVersionConstraint( observableRepoIds, resultHit.getGroupId(), resultHit.getArtifactId() ) ),
+ null );
+
+ repoBrowsingControl.expectAndReturn(
+ repoBrowsing.selectVersion( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ),
+ null );
+
+ repoBrowsingControl.expectAndReturn(
+ repoBrowsing.getRepositoryId( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID,
+ "1.0" ), null );
+
userReposControl.replay();
searchControl.replay();
repoBrowsingControl.replay();
- archivaDAOControl.replay();
-
+ archivaDAOControl.replay();
+
List<Artifact> artifacts = searchService.quickSearch( "archiva" );
-
+
userReposControl.verify();
searchControl.verify();
repoBrowsingControl.verify();
archivaDAOControl.verify();
-
+
assertNotNull( artifacts );
assertEquals( 1, artifacts.size() );
-
+
Artifact artifact = artifacts.get( 0 );
assertEquals( ARCHIVA_TEST_GROUP_ID, artifact.getGroupId() );
assertEquals( ARCHIVA_TEST_ARTIFACT_ID, artifact.getArtifactId() );
assertEquals( "1.0", artifact.getVersion() );
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
- * 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 since a given date
- * 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 all artifacts that depend on a given artifact
- */
-
- /* quick search */
-
+ * quick/general text search which returns a list of artifacts
+ * 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 since a given date
+ * 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 all artifacts that depend on a given artifact
+ */
+
+ /* quick search */
+
// public void testQuickSearchArtifactBytecodeSearch()
// throws Exception
// {
// assertNotNull( artifacts );
// assertEquals( 1, artifacts.size() );
// }
-
+
public void testQuickSearchArtifactRegularSearch()
throws Exception
{
List<String> observableRepoIds = new ArrayList<String>();
observableRepoIds.add( "repo1.mirror" );
observableRepoIds.add( "public.releases" );
-
+
userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds );
-
- SearchResults results = new SearchResults();
+
+ SearchResults results = new SearchResults();
List<String> versions = new ArrayList<String>();
versions.add( "1.0" );
-
+
SearchResultHit resultHit = new SearchResultHit();
resultHit.setGroupId( ARCHIVA_TEST_GROUP_ID );
resultHit.setArtifactId( ARCHIVA_TEST_ARTIFACT_ID );
resultHit.setVersions( versions );
resultHit.setRepositoryId( null );
-
+
results.addHit( SearchUtil.getHitId( resultHit.getGroupId(), resultHit.getArtifactId() ), resultHit );
-
- archivaDAOControl.expectAndReturn( archivaDAO.query( new UniqueVersionConstraint( observableRepoIds, resultHit.getGroupId(),
- resultHit.getArtifactId() ) ), null );
-
+
+ archivaDAOControl.expectAndReturn( archivaDAO.query(
+ new UniqueVersionConstraint( observableRepoIds, resultHit.getGroupId(), resultHit.getArtifactId() ) ),
+ null );
+
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();
model.setGroupId( ARCHIVA_TEST_GROUP_ID );
model.setArtifactId( ARCHIVA_TEST_ARTIFACT_ID );
model.setVersion( "1.0" );
model.setPackaging( "jar" );
-
- repoBrowsingControl.expectAndReturn( 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.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" );
+
userReposControl.replay();
searchControl.replay();
archivaDAOControl.replay();
repoBrowsingControl.replay();
-
+
List<Artifact> artifacts = searchService.quickSearch( "archiva" );
-
+
userReposControl.verify();
searchControl.verify();
archivaDAOControl.verify();
repoBrowsingControl.verify();
-
+
assertNotNull( artifacts );
assertEquals( 1, artifacts.size() );
-
+
Artifact artifact = artifacts.get( 0 );
assertEquals( ARCHIVA_TEST_GROUP_ID, artifact.getGroupId() );
assertEquals( ARCHIVA_TEST_ARTIFACT_ID, artifact.getArtifactId() );
assertNotNull( "Repository should not be null!", artifact.getRepositoryId() );
assertEquals( "repo1.mirror", artifact.getRepositoryId() );
}
-
- public void testQuickSearchNoResults( )
+
+ public void testQuickSearchNoResults()
throws Exception
{
List<String> observableRepoIds = new ArrayList<String>();
observableRepoIds.add( "repo1.mirror" );
observableRepoIds.add( "public.releases" );
-
+
userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds );
-
+
SearchResults results = new SearchResults();
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();
searchControl.replay();
-
+
List<Artifact> artifacts = searchService.quickSearch( "test" );
-
+
userReposControl.verify();
searchControl.verify();
-
+
assertNotNull( artifacts );
assertEquals( 0, artifacts.size() );
- }
-
+ }
+
/* query artifact by checksum */
-
+
public void testGetArtifactByChecksum()
throws Exception
{
Date whenGathered = new Date();
-
+
ArtifactsByChecksumConstraint constraint = new ArtifactsByChecksumConstraint( "a1b2c3aksjhdasfkdasasd" );
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 );
artifacts.add( artifact );
-
+
archivaDAOControl.expectAndReturn( archivaDAO.getArtifactDAO(), artifactDAO );
artifactDAO.queryArtifacts( constraint );
artifactDAOControl.setMatcher( MockControl.ALWAYS_MATCHER );
artifactDAOControl.setReturnValue( artifacts );
-
+
archivaDAOControl.replay();
artifactDAOControl.replay();
-
+
List<Artifact> results = searchService.getArtifactByChecksum( "a1b2c3aksjhdasfkdasasd" );
-
+
archivaDAOControl.verify();
artifactDAOControl.verify();
-
+
assertNotNull( results );
assertEquals( 1, results.size() );
}
-
+
/* query artifact versions */
-
+
public void testGetArtifactVersionsArtifactExists()
throws Exception
{
Date whenGathered = new Date();
-
+
List<String> observableRepoIds = new ArrayList<String>();
observableRepoIds.add( "repo1.mirror" );
observableRepoIds.add( "public.releases" );
-
+
List<String> versions = new ArrayList<String>();
versions.add( "1.0" );
versions.add( "1.1-beta-1" );
versions.add( "1.1" );
versions.add( "1.2" );
versions.add( "1.2.1-SNAPSHOT" );
-
+
BrowsingResults results = new BrowsingResults( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID );
results.setSelectedRepositoryIds( observableRepoIds );
results.setVersions( versions );
-
+
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 );
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 );
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 );
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 );
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 );
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 );
archivaArtifacts.add( archivaArtifact );
-
+
userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds );
- repoBrowsingControl.expectAndReturn( repoBrowsing.selectArtifactId( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID,
- ARCHIVA_TEST_ARTIFACT_ID ), results );
+ repoBrowsingControl.expectAndReturn(
+ repoBrowsing.selectArtifactId( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID ),
+ results );
archivaDAOControl.expectAndReturn( archivaDAO.getArtifactDAO(), artifactDAO );
-
- artifactDAOControl.expectAndDefaultReturn( artifactDAO.getArtifact( ARCHIVA_TEST_GROUP_ID,
- ARCHIVA_TEST_ARTIFACT_ID, versions.get( 0 ), "", "pom", "repo1.mirror" ), archivaArtifacts.get( 0 ) );
- artifactDAOControl.expectAndDefaultReturn( artifactDAO.getArtifact( ARCHIVA_TEST_GROUP_ID,
- ARCHIVA_TEST_ARTIFACT_ID, versions.get( 1 ), "", "pom", "public.releases" ), archivaArtifacts.get( 1 ) );
- artifactDAOControl.expectAndDefaultReturn( artifactDAO.getArtifact( ARCHIVA_TEST_GROUP_ID,
- ARCHIVA_TEST_ARTIFACT_ID, versions.get( 2 ), "", "pom", "repo1.mirror" ), archivaArtifacts.get( 2 ) );
- artifactDAOControl.expectAndDefaultReturn( artifactDAO.getArtifact( ARCHIVA_TEST_GROUP_ID,
- ARCHIVA_TEST_ARTIFACT_ID, versions.get( 3 ), "", "pom", "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 ) );
-
+
+ artifactDAOControl.expectAndDefaultReturn(
+ artifactDAO.getArtifact( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, versions.get( 0 ), "", "pom",
+ "repo1.mirror" ), archivaArtifacts.get( 0 ) );
+ artifactDAOControl.expectAndDefaultReturn(
+ artifactDAO.getArtifact( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, versions.get( 1 ), "", "pom",
+ "public.releases" ), archivaArtifacts.get( 1 ) );
+ artifactDAOControl.expectAndDefaultReturn(
+ artifactDAO.getArtifact( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, versions.get( 2 ), "", "pom",
+ "repo1.mirror" ), archivaArtifacts.get( 2 ) );
+ artifactDAOControl.expectAndDefaultReturn(
+ artifactDAO.getArtifact( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, versions.get( 3 ), "", "pom",
+ "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();
repoBrowsingControl.replay();
artifactDAOControl.replay();
-
+
List<Artifact> artifacts = searchService.getArtifactVersions( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID );
-
+
userReposControl.verify();
repoBrowsingControl.verify();
artifactDAOControl.verify();
-
+
assertNotNull( artifacts );
assertEquals( 6, artifacts.size() );
}
-
+
/* query artifact versions since a given date */
-
+
public void testGetArtifactVersionsByDateArtifactExists()
throws Exception
{
-
+
}
-
+
public void testGetArtifactVersionsByDateArtifactDoesNotExist()
throws Exception
{
-
+
}
-
+
/* query artifact dependencies */
-
+
public void testGetDependenciesArtifactExists()
throws Exception
- {
+ {
List<String> observableRepoIds = new ArrayList<String>();
observableRepoIds.add( "repo1.mirror" );
observableRepoIds.add( "public.releases" );
-
+
ArchivaProjectModel model = new ArchivaProjectModel();
model.setGroupId( ARCHIVA_TEST_GROUP_ID );
model.setArtifactId( ARCHIVA_TEST_ARTIFACT_ID );
model.setVersion( "1.0" );
-
+
org.apache.maven.archiva.model.Dependency dependency = new org.apache.maven.archiva.model.Dependency();
dependency.setGroupId( "commons-logging" );
dependency.setArtifactId( "commons-logging" );
dependency.setVersion( "2.0" );
-
+
model.addDependency( dependency );
-
+
dependency = new org.apache.maven.archiva.model.Dependency();
dependency.setGroupId( "junit" );
dependency.setArtifactId( "junit" );
dependency.setVersion( "2.4" );
dependency.setScope( "test" );
-
+
model.addDependency( dependency );
-
- userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds );
- repoBrowsingControl.expectAndReturn(
- repoBrowsing.selectVersion( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ), model );
-
- repoBrowsingControl.replay();
+
+ userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds );
+ repoBrowsingControl.expectAndReturn(
+ repoBrowsing.selectVersion( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ),
+ model );
+
+ repoBrowsingControl.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();
userReposControl.verify();
-
+
assertNotNull( dependencies );
assertEquals( 2, dependencies.size() );
}
-
+
public void testGetDependenciesArtifactDoesNotExist()
throws Exception
{
List<String> observableRepoIds = new ArrayList<String>();
observableRepoIds.add( "repo1.mirror" );
observableRepoIds.add( "public.releases" );
-
+
userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds );
- repoBrowsingControl.expectAndThrow(
- repoBrowsing.selectVersion( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ), new ObjectNotFoundException( "Artifact does not exist." ) );
-
+ repoBrowsingControl.expectAndThrow(
+ repoBrowsing.selectVersion( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ),
+ new ObjectNotFoundException( "Artifact does not exist." ) );
+
userReposControl.replay();
repoBrowsingControl.replay();
-
+
try
{
searchService.getDependencies( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" );
{
assertEquals( "Artifact does not exist.", e.getMessage() );
}
-
+
userReposControl.verify();
repoBrowsingControl.verify();
}
-
+
public void testGetDependencyTreeArtifactExists()
throws Exception
{
// TODO
}
-
+
public void testGetDependencyTreeArtifactDoesNotExist()
throws Exception
{
// TODO
}
-
+
public void testGetDependees()
throws Exception
{
List<String> observableRepoIds = new ArrayList<String>();
observableRepoIds.add( "repo1.mirror" );
observableRepoIds.add( "public.releases" );
-
+
List<ArchivaProjectModel> dependeeModels = new ArrayList<ArchivaProjectModel>();
ArchivaProjectModel dependeeModel = new ArchivaProjectModel();
dependeeModel.setGroupId( ARCHIVA_TEST_GROUP_ID );
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" ), dependeeModels );
-
- repoBrowsingControl.replay();
+ repoBrowsingControl.expectAndReturn(
+ repoBrowsing.getUsedBy( "", observableRepoIds, ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ),
+ dependeeModels );
+
+ repoBrowsingControl.replay();
userReposControl.replay();
List<Artifact> dependees = searchService.getDependees( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" );
-
+
repoBrowsingControl.verify();
userReposControl.verify();
-
+
assertNotNull( dependees );
assertEquals( 2, dependees.size() );
}
-
+
public void testGetDependeesArtifactDoesNotExist()
throws Exception
{
List<String> observableRepoIds = new ArrayList<String>();
observableRepoIds.add( "repo1.mirror" );
observableRepoIds.add( "public.releases" );
-
+
List dependeeModels = new ArrayList();
ArchivaProjectModel dependeeModel = new ArchivaProjectModel();
dependeeModel.setGroupId( ARCHIVA_TEST_GROUP_ID );
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 );
-
- repoBrowsingControl.replay();
+ repoBrowsingControl.expectAndReturn(
+ repoBrowsing.getUsedBy( "", observableRepoIds, 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" );
+ List<Artifact> dependees =
+ searchService.getDependees( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" );
fail( "An exception should have been thrown." );
}
catch ( Exception e )