]> source.dussan.org Git - archiva.git/commitdiff
add unit test for search with guest user.
authorOlivier Lamy <olamy@apache.org>
Sun, 26 Feb 2012 16:58:50 +0000 (16:58 +0000)
committerOlivier Lamy <olamy@apache.org>
Sun, 26 Feb 2012 16:58:50 +0000 (16:58 +0000)
git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@1293871 13f79535-47bb-0310-9956-ffa450edef68

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

index 1c83301b17eb16a894cae95c429ee69fdebf892a..c3b5f154e26b1355bb356f8b336fec8be9593d9c 100644 (file)
@@ -73,7 +73,6 @@ public class DefaultSearchService
         }
 
         SearchResultLimits limits = new SearchResultLimits( 0 );
-        List<String> observableRepoIds = getObservableRepos();
         try
         {
             SearchResults searchResults =
index e648b7ccabfb4c47c464ac8221d313638a7d95e1..880492246eb74e062732ecbfe3553e1de549dc6d 100644 (file)
@@ -329,6 +329,9 @@ public abstract class AbstractArchivaRestTest
         getRoleManagementService( authorizationHeader ).assignTemplatedRole(
             ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, testRepoId, "admin" );
 
+        getRoleManagementService( authorizationHeader ).assignTemplatedRole(
+            ArchivaRoleConstants.TEMPLATE_REPOSITORY_OBSERVER, testRepoId, "guest" );
+
         getRepositoriesService( authorizationHeader ).scanRepositoryNow( testRepoId, true );
 
     }
index 89ac79b0d8e7f9e5a2ac9d9a5094fc0031642c15..19219c6390c31d5d9bb8d7a9a7c48116aeb33bc2 100644 (file)
@@ -18,18 +18,13 @@ package org.apache.archiva.rest.services;
  * under the License.
  */
 
-import org.apache.archiva.admin.model.beans.ManagedRepository;
 import org.apache.archiva.rest.api.model.Artifact;
 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.junit.Test;
 
-import java.io.File;
 import java.util.Arrays;
 import java.util.Collection;
-import java.util.Date;
 import java.util.List;
 
 /**
@@ -70,6 +65,40 @@ public class SearchServiceTest
         deleteTestRepo( testRepoId );
     }
 
+    /**
+     * same search but with Guest user
+     * @throws Exception
+     */
+    @Test
+    public void quickSearchOnArtifactIdGuest()
+        throws Exception
+    {
+
+        String testRepoId = "test-repo";
+        // force guest user creation if not exists
+        if ( getUserService( authorizationHeader ).getGuestUser() == null )
+        {
+            assertNotNull( getUserService( authorizationHeader ).createGuestUser() );
+        }
+
+        createAndIndexRepo( testRepoId, "src/test/repo-with-osgi" );
+
+        SearchService searchService = getSearchService( null );
+
+        // START SNIPPET: quick-search
+        List<Artifact> artifacts = searchService.quickSearch( "commons-logging" );
+        // return all artifacts with groupId OR artifactId OR version OR packaging OR className
+        // NOTE : only artifacts with classifier empty are returned
+        // END SNIPPET: quick-search
+
+        assertNotNull( artifacts );
+        assertTrue( " not 6 results for commons-logging search but " + artifacts.size() + ":" + artifacts,
+                    artifacts.size() == 6 );
+        log.info( "artifacts for commons-logging size {} search {}", artifacts.size(), artifacts );
+
+        deleteTestRepo( testRepoId );
+    }
+
     @Test
     public void searchArtifactVersions()
         throws Exception