From: Olivier Lamy Date: Thu, 3 Nov 2011 23:45:14 +0000 (+0000) Subject: add unit tests to ensure javadoc is respected regarding usage of repo Ids in SearchRe... X-Git-Tag: archiva-1.4-M2~165 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=08c8f5fafdb73f7720a57f5d33647b7d3ae8e0dd;p=archiva.git add unit tests to ensure javadoc is respected regarding usage of repo Ids in SearchRequest git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1197354 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/SearchServiceTest.java b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/SearchServiceTest.java index 55774dc51..11d461279 100644 --- a/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/SearchServiceTest.java +++ b/archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/SearchServiceTest.java @@ -24,7 +24,6 @@ import org.apache.archiva.rest.api.model.SearchRequest; import org.apache.archiva.rest.api.services.ManagedRepositoriesService; import org.apache.archiva.rest.api.services.SearchService; import org.apache.archiva.security.common.ArchivaRoleConstants; -import org.apache.commons.io.FileUtils; import org.junit.Test; import java.io.File; @@ -223,6 +222,70 @@ public class SearchServiceTest deleteTestRepo( testRepoId ); } + @Test + /** + * ensure we don't return response for an unknown repo + */ + public void searchWithSearchUnknwownRepoId() + throws Exception + { + + String testRepoId = "test-repo"; + // force guest user creation if not exists + if ( getUserService( authorizationHeader ).getGuestUser() == null ) + { + assertNotNull( getUserService( authorizationHeader ).createGuestUser() ); + } + + createAndIndexRepo( testRepoId ); + + SearchService searchService = getSearchService( authorizationHeader ); + + SearchRequest searchRequest = new SearchRequest(); + searchRequest.setBundleExportPackage( "org.apache.karaf.features.command.completers" ); + searchRequest.setRepositories( Arrays.asList( "tototititata" ) ); + + List artifacts = searchService.searchArtifacts( searchRequest ); + + assertNotNull( artifacts ); + assertTrue( " not 0 results for Bundle ExportPackage org.apache.karaf.features.command.completers but " + + artifacts.size() + ":" + artifacts, artifacts.size() == 0 ); + + deleteTestRepo( testRepoId ); + } + + @Test + /** + * ensure we revert to all observable repos in case of no repo in the request + */ + public void searchWithSearchNoRepos() + throws Exception + { + + String testRepoId = "test-repo"; + // force guest user creation if not exists + if ( getUserService( authorizationHeader ).getGuestUser() == null ) + { + assertNotNull( getUserService( authorizationHeader ).createGuestUser() ); + } + + createAndIndexRepo( testRepoId ); + + SearchService searchService = getSearchService( authorizationHeader ); + + SearchRequest searchRequest = new SearchRequest(); + searchRequest.setBundleExportPackage( "org.apache.karaf.features.command.completers" ); + + List artifacts = searchService.searchArtifacts( searchRequest ); + + assertNotNull( artifacts ); + assertTrue( " not 0 results for Bundle ExportPackage org.apache.karaf.features.command.completers but " + + artifacts.size() + ":" + artifacts, artifacts.size() == 1 ); + + log.info( "artifact url " + artifacts.get( 0 ).getUrl() ); + deleteTestRepo( testRepoId ); + } + @Test public void getAllGroupIds() throws Exception