]> source.dussan.org Git - archiva.git/commitdiff
add unit tests to ensure javadoc is respected regarding usage of repo Ids in SearchRe...
authorOlivier Lamy <olamy@apache.org>
Thu, 3 Nov 2011 23:45:14 +0000 (23:45 +0000)
committerOlivier Lamy <olamy@apache.org>
Thu, 3 Nov 2011 23:45:14 +0000 (23:45 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1197354 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-web/archiva-rest/archiva-rest-services/src/test/java/org/apache/archiva/rest/services/SearchServiceTest.java

index 55774dc512b637c5fee91f82c15d3d7834f5af31..11d4612799011008e10536bde4b5a19b5796a1c7 100644 (file)
@@ -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<Artifact> 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<Artifact> 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