From: Brett Porter Date: Mon, 30 Nov 2009 02:43:00 +0000 (+0000) Subject: formatting changes only X-Git-Tag: archiva-1.4-M1~1017^2~128 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=0caebfc6b621579481aca223a76e24be0be9f0c3;p=archiva.git formatting changes only git-svn-id: https://svn.apache.org/repos/asf/archiva/branches/MRM-1025@885316 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImpl.java b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImpl.java index 24cbb57a0..30d819100 100644 --- a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImpl.java +++ b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/main/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImpl.java @@ -47,189 +47,196 @@ import org.slf4j.LoggerFactory; /** * 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 quickSearch( String queryString ) throws Exception - { + { List artifacts = new ArrayList(); List 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 versions = - (List) archivaDAO.query( new UniqueVersionConstraint( observableRepos, resultHit.getGroupId(), - resultHit.getArtifactId() ) ); + final List versions = (List) archivaDAO.query( + new UniqueVersionConstraint( observableRepos, resultHit.getGroupId(), resultHit.getArtifactId() ) ); if ( versions != null && !versions.isEmpty() ) { resultHit.setVersion( null ); resultHit.setVersions( filterTimestampedSnapshots( versions ) ); } - + List 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 filterTimestampedSnapshots(List versions) + private static List filterTimestampedSnapshots( List versions ) { final List filtered = new ArrayList(); - 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 getArtifactByChecksum( String checksum ) + + public List 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 results = new ArrayList(); ArtifactDAO artifactDAO = archivaDAO.getArtifactDAO(); - + ArtifactsByChecksumConstraint constraint = new ArtifactsByChecksumConstraint( checksum ); List 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 getArtifactVersions( String groupId, String artifactId ) + + public List getArtifactVersions( String groupId, String artifactId ) throws Exception { - final List artifacts = new ArrayList(); + final List artifacts = new ArrayList(); final List 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 getArtifactVersionsByDate( String groupId, String artifactId, String version, Date since ) throws Exception { List artifacts = new ArrayList(); - + // 1. get observable repositories // 2. use RepositoryBrowsing method to query uniqueVersions? (but with date) - + return artifacts; } - - public List getDependencies( String groupId, String artifactId, String version ) + + public List getDependencies( String groupId, String artifactId, String version ) throws Exception - { - List dependencies = new ArrayList(); + { + List dependencies = new ArrayList(); List observableRepos = xmlRpcUserRepositories.getObservableRepositories(); - + try { ArchivaProjectModel model = repoBrowsing.selectVersion( "", observableRepos, groupId, artifactId, version ); List 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 ); } } @@ -237,34 +244,34 @@ public class SearchServiceImpl { throw new Exception( "Artifact does not exist." ); } - + return dependencies; } - - public List getDependencyTree( String groupId, String artifactId, String version ) + + public List getDependencyTree( String groupId, String artifactId, String version ) throws Exception { List a = new ArrayList(); - + return a; } - - //get artifacts that depend on a given artifact + + //get artifacts that depend on a given artifact public List getDependees( String groupId, String artifactId, String version ) throws Exception { List artifacts = new ArrayList(); List observableRepos = xmlRpcUserRepositories.getObservableRepositories(); - - List dependees = repoBrowsing.getUsedBy( "", observableRepos, groupId, artifactId, version ); - for( ArchivaProjectModel model : dependees ) + + List 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; } } diff --git a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImplTest.java b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImplTest.java index 654e8237a..8ef4b076d 100644 --- a/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImplTest.java +++ b/archiva-modules/archiva-web/archiva-xmlrpc/archiva-xmlrpc-services/src/test/java/org/apache/archiva/web/xmlrpc/services/SearchServiceImplTest.java @@ -18,7 +18,7 @@ package org.apache.archiva.web.xmlrpc.services; * specific language governing permissions and limitations * under the License. */ - + import java.util.ArrayList; import java.util.Date; @@ -48,32 +48,32 @@ import org.easymock.classextension.MockClassControl; /** * 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"; @@ -85,79 +85,85 @@ public class SearchServiceImplTest 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 observableRepoIds = new ArrayList(); observableRepoIds.add( "repo1.mirror" ); observableRepoIds.add( "public.releases" ); - + userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds ); - - SearchResults results = new SearchResults(); + + SearchResults results = new SearchResults(); List versions = new ArrayList(); 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 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() ); @@ -166,7 +172,7 @@ public class SearchServiceImplTest assertNotNull( "Repository should not be null!", artifact.getRepositoryId() ); assertEquals( "repo1.mirror", artifact.getRepositoryId() ); } - + // returned model is null! public void testQuickSearchDefaultPackagingIsUsed() throws Exception @@ -174,69 +180,74 @@ public class SearchServiceImplTest List observableRepoIds = new ArrayList(); observableRepoIds.add( "repo1.mirror" ); observableRepoIds.add( "public.releases" ); - + userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds ); - - SearchResults results = new SearchResults(); + + SearchResults results = new SearchResults(); List versions = new ArrayList(); 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 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 // { @@ -283,62 +294,66 @@ public class SearchServiceImplTest // assertNotNull( artifacts ); // assertEquals( 1, artifacts.size() ); // } - + public void testQuickSearchArtifactRegularSearch() throws Exception { List observableRepoIds = new ArrayList(); observableRepoIds.add( "repo1.mirror" ); observableRepoIds.add( "public.releases" ); - + userReposControl.expectAndReturn( userRepos.getObservableRepositories(), observableRepoIds ); - - SearchResults results = new SearchResults(); + + SearchResults results = new SearchResults(); List versions = new ArrayList(); 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 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() ); @@ -347,73 +362,75 @@ public class SearchServiceImplTest assertNotNull( "Repository should not be null!", artifact.getRepositoryId() ); assertEquals( "repo1.mirror", artifact.getRepositoryId() ); } - - public void testQuickSearchNoResults( ) + + public void testQuickSearchNoResults() throws Exception { List observableRepoIds = new ArrayList(); 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 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 artifacts = new ArrayList(); - 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 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 observableRepoIds = new ArrayList(); observableRepoIds.add( "repo1.mirror" ); observableRepoIds.add( "public.releases" ); - + List versions = new ArrayList(); versions.add( "1.0" ); versions.add( "1.1-beta-1" ); @@ -421,141 +438,163 @@ public class SearchServiceImplTest 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 archivaArtifacts = new ArrayList(); - 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 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 observableRepoIds = new ArrayList(); 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 dependencies = searchService.getDependencies( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ); - + + List 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 observableRepoIds = new ArrayList(); 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" ); @@ -565,23 +604,23 @@ public class SearchServiceImplTest { 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 { @@ -589,7 +628,7 @@ public class SearchServiceImplTest List observableRepoIds = new ArrayList(); observableRepoIds.add( "repo1.mirror" ); observableRepoIds.add( "public.releases" ); - + List dependeeModels = new ArrayList(); ArchivaProjectModel dependeeModel = new ArchivaProjectModel(); dependeeModel.setGroupId( ARCHIVA_TEST_GROUP_ID ); @@ -597,30 +636,31 @@ public class SearchServiceImplTest 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 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 { @@ -628,7 +668,7 @@ public class SearchServiceImplTest List observableRepoIds = new ArrayList(); observableRepoIds.add( "repo1.mirror" ); observableRepoIds.add( "public.releases" ); - + List dependeeModels = new ArrayList(); ArchivaProjectModel dependeeModel = new ArchivaProjectModel(); dependeeModel.setGroupId( ARCHIVA_TEST_GROUP_ID ); @@ -636,24 +676,26 @@ public class SearchServiceImplTest 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 dependees = searchService.getDependees( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ); + List dependees = + searchService.getDependees( ARCHIVA_TEST_GROUP_ID, ARCHIVA_TEST_ARTIFACT_ID, "1.0" ); fail( "An exception should have been thrown." ); } catch ( Exception e )