From 88f79fe1e7688750f3236feb71a5288e6891abe1 Mon Sep 17 00:00:00 2001 From: "Maria Odea B. Ching" Date: Mon, 12 Oct 2009 08:44:10 +0000 Subject: [MRM-1080] Update SearchServiceImplTest so that it uses the new search API submitted by Gwen Harold Autencio o added tests for quick search (with search hits and with no search hits) additional changes to the patch: o updated testQuickSearchArtifactRegularSearch() to conform to the recent changes in SearchServiceImpl from MRM-1230 git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@824259 13f79535-47bb-0310-9956-ffa450edef68 --- .../web/xmlrpc/services/SearchServiceImplTest.java | 120 +++++++++++++-------- 1 file changed, 77 insertions(+), 43 deletions(-) (limited to 'archiva-modules/archiva-web') 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 e83c685cf..6f28bf008 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 @@ -272,49 +272,83 @@ 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 ); -// -// Date whenGathered = new Date(); -// SearchResults results = new SearchResults(); -// ArchivaArtifact artifact = new ArchivaArtifact( "org.apache.archiva", "archiva-test", "1.0", "", "jar", "public.releases" ); -// artifact.getModel().setWhenGathered( whenGathered ); -// -// -// SearchResultHit resultHit = new SearchResultHit(); -// resultHit.setArtifact(artifact); -// resultHit.setRepositoryId("repo1.mirror"); -// results.addHit(SearchUtil.getHitId(artifact.getGroupId(), artifact.getArtifactId()), resultHit); -// -// SearchResultLimits limits = new SearchResultLimits( SearchResultLimits.ALL_PAGES ); -// -// searchControl.expectAndDefaultReturn( search.search( "", observableRepoIds, "archiva", limits, null ), results ); -// -// archivaDAOControl.expectAndReturn( archivaDAO.getArtifactDAO(), artifactDAO ); -// artifactDAOControl.expectAndReturn( artifactDAO.getArtifact( "org.apache.archiva", "archiva-test", "1.0", "", "pom", "public.releases" ), artifact ); -// -// userReposControl.replay(); -// searchControl.replay(); -// archivaDAOControl.replay(); -// artifactDAOControl.replay(); -// -// List artifacts = searchService.quickSearch( "archiva" ); -// -// userReposControl.verify(); -// searchControl.verify(); -// archivaDAOControl.verify(); -// artifactDAOControl.verify(); -// -// 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(); + List versions = new ArrayList(); + versions.add( "1.0" ); + + SearchResultHit resultHit = new SearchResultHit(); + resultHit.setGroupId( "org.apache.archiva" ); + resultHit.setArtifactId( "archiva-test" ); + resultHit.setVersions( versions ); + resultHit.setRepositoryId("repo1.mirror"); + + results.addHit( SearchUtil.getHitId( resultHit.getGroupId(), resultHit.getArtifactId() ), resultHit ); + + 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 ); + + ArchivaProjectModel model = new ArchivaProjectModel(); + model.setGroupId( "org.apache.archiva" ); + model.setArtifactId( "archiva-test" ); + model.setVersion( "1.0" ); + model.setPackaging( "jar" ); + + repoBrowsingControl.expectAndReturn( repoBrowsing.selectVersion( "", observableRepoIds, "org.apache.archiva", "archiva-test", "1.0" ), model ); + + 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() ); + } + + 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 ); + userReposControl.replay(); + searchControl.replay(); + + List artifacts = searchService.quickSearch( "test" ); + + userReposControl.verify(); + searchControl.verify(); + + assertNotNull( artifacts ); + assertEquals( 0, artifacts.size() ); + } /* query artifact by checksum */ -- cgit v1.2.3