]> source.dussan.org Git - archiva.git/commitdiff
[MRM-1125] - default search should be AND not OR for multiple keywords
authorJevica Arianne B. Zurbano <jzurbano@apache.org>
Sat, 15 May 2010 12:56:34 +0000 (12:56 +0000)
committerJevica Arianne B. Zurbano <jzurbano@apache.org>
Sat, 15 May 2010 12:56:34 +0000 (12:56 +0000)
* applied patch
* added additional unit and selenium tests for quick search

Submitted by: Gwen Harold Autencio

git-svn-id: https://svn.apache.org/repos/asf/archiva/trunk@944632 13f79535-47bb-0310-9956-ffa450edef68

archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/NexusRepositorySearchTest.java
archiva-modules/archiva-web/archiva-webapp-test/src/test/resources/testng.properties
archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/SearchTest.java

index b31c6149173f210315ba9111bc26926d6dcde5ef..fc03763a9255cf70fae859c7c799a5638017de21 100644 (file)
@@ -195,6 +195,26 @@ public class NexusRepositorySearchTest
         //TODO: search for class & package names
     }
     
+    // search for existing artifact using multiple keywords
+    public void testQuickSearchWithMultipleKeywords()
+        throws Exception
+    {   
+        createIndexForQuickSearch();
+        
+        List<String> selectedRepos = new ArrayList<String>();
+        selectedRepos.add( TEST_REPO_1 );
+
+        archivaConfigControl.expectAndReturn( archivaConfig.getConfiguration(), config );
+        archivaConfigControl.replay();
+        
+        SearchResults results = search.search( "user", selectedRepos, "archiva search", null, null );
+        
+        archivaConfigControl.verify();
+        
+        assertNotNull( results );
+        assertEquals( 0, results.getTotalHits() );
+    }
+    
     public void testQuickSearchWithPagination()
         throws Exception
     {   
@@ -573,6 +593,48 @@ public class NexusRepositorySearchTest
         }
     }
     
+    public void testAdvancedSearchAllSearchCriteriaSpecified()
+        throws Exception
+    {
+        List<File> files = new ArrayList<File>();
+        files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
+            "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar" ) );
+        files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
+            "/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.jar" ) );
+        files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
+            "/org/apache/archiva/archiva-test/2.0/archiva-test-2.0.jar" ) );
+
+        createIndex( TEST_REPO_1, files );
+        
+        List<String> selectedRepos = new ArrayList<String>();
+        selectedRepos.add( TEST_REPO_1 );
+        
+        SearchFields searchFields = new SearchFields();
+        searchFields.setGroupId( "org.apache.archiva" );
+        searchFields.setArtifactId( "archiva-test" );
+        searchFields.setVersion( "2.0" );
+        searchFields.setPackaging( "jar" );
+        searchFields.setClassName( "org.apache.archiva.test.App" );
+        searchFields.setRepositories( selectedRepos );
+        
+        archivaConfigControl.expectAndDefaultReturn( archivaConfig.getConfiguration(), config );
+        
+        archivaConfigControl.replay();
+        
+        SearchResults results = search.search( "user", searchFields, null );
+        
+        archivaConfigControl.verify();
+        
+        assertNotNull( results );
+        
+        assertEquals( 1, results.getTotalHits() );
+        
+        SearchResultHit hit = results.getHits().get( 0 );
+        assertEquals( "org.apache.archiva", hit.getGroupId() );
+        assertEquals( "archiva-test", hit.getArtifactId() );
+        assertEquals( "2.0", hit.getVersions().get( 0 ) );
+    }
+    
     public void testAdvancedSearchJarArtifacts()
         throws Exception
     {
@@ -613,6 +675,40 @@ public class NexusRepositorySearchTest
         assertEquals( 5, results.getTotalHits() );        
     }
     
+    public void testAdvancedSearchWithIncorrectPackaging()
+        throws Exception
+    {
+        List<File> files = new ArrayList<File>();
+        files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
+            "/org/apache/archiva/archiva-search/1.0/archiva-search-1.0.jar" ) );
+        files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
+            "/org/apache/archiva/archiva-test/1.0/archiva-test-1.0.jar" ) );
+        files.add( new File( getBasedir(), "/target/test-classes/" + TEST_REPO_1 +
+            "/org/apache/archiva/archiva-test/2.0/archiva-test-2.0.jar" ) );
+    
+        createIndex( TEST_REPO_1, files );
+        
+        List<String> selectedRepos = new ArrayList<String>();
+        selectedRepos.add( TEST_REPO_1 );
+        
+        SearchFields searchFields = new SearchFields();
+        searchFields.setGroupId( "org.apache.archiva" );
+        searchFields.setArtifactId( "archiva-test" );
+        searchFields.setVersion( "2.0" );
+        searchFields.setPackaging( "war" );
+        searchFields.setRepositories( selectedRepos );
+        
+        archivaConfigControl.expectAndDefaultReturn( archivaConfig.getConfiguration(), config );
+        archivaConfigControl.replay();
+        
+        SearchResults results = search.search( "user", searchFields, null );
+        
+        archivaConfigControl.verify();
+        
+        assertNotNull( results );
+        assertEquals( 0, results.getTotalHits() );
+    }
+    
     public void testAdvancedSearchClassname()
         throws Exception
     {
index 1230adab38b861a20b0d6ac13cbf398764adcef9..5ceeebe76b1e5ee16f0fe32349b4342620918016 100644 (file)
@@ -18,6 +18,7 @@ ARTIFACT_GROUPID=test
 ARTIFACT_ARTIFACTID=test
 ARTIFACT_VERSION=1.0
 ARTIFACT_PACKAGING=jar
+ARTIFACT_CLASSNAME=test.App
 
 # Artifact for testing add artifact with valid values
 VALIDARTIFACT_GROUPID=addArtifactValidValues
@@ -96,6 +97,9 @@ SNAPSHOT_PACKAGING=jar
 SNAPSHOT_ARTIFACTFILEPATH=src/test/resources/snapshots/org/apache/maven/archiva/web/test/foo-bar/1.0-SNAPSHOT/foo-bar-1.0-SNAPSHOT.jar
 SNAPSHOT_REPOSITORYID=snapshots
 
+ADD_REMOVE_GROUPID=artifact.dummy
+ADD_REMOVE_ARTIFACTID=artifact-dummy
+
 # REPOSITORIES
 # Manage Repositories
 MANAGED_IDENTIFIER=testing1
index 718418b00cfff1eb657babbc5b165797b191a751..a451328a142fd1f48fab7e26f34e178d3d27295f 100644 (file)
@@ -54,6 +54,30 @@ public class SearchTest
         clickLinkWithText( getProperty( "ARTIFACT_VERSION" ) + "/" );
         assertPage( "Apache Archiva \\ Browse Repository" );
     }
+    
+    public void testSearchWithMultipleKeywords()
+    {
+        String groupId = getProperty( "ADD_REMOVE_GROUPID" );
+        String version = getProperty( "SNAPSHOT_VERSION" );
+        String packaging = getProperty( "SNAPSHOT_PACKAGING" );
+        String filePath = getProperty( "SNAPSHOT_ARTIFACTFILEPATH" );
+        String repoId = getProperty( "SNAPSHOT_REPOSITORYID" );
+        
+        String existingArtifactId = getProperty( "ADD_REMOVE_ARTIFACTID" );
+        String multiKeywords = existingArtifactId.replace( "-", " " );
+        
+        addArtifact( groupId, existingArtifactId, version, packaging, filePath, repoId );
+        
+        // verify artifact is existing
+        searchForArtifact( existingArtifactId );
+        assertTextPresent( "Results" );
+        assertTextPresent( "Hits: 1 to 1 of 1" );
+        assertLinkPresent( existingArtifactId );
+        
+        // search for existing artifact using multiple keywords
+        searchForArtifact( multiKeywords );
+        assertTextPresent( "No results found" );
+    }
 
     public void testSearchNonExistingArtifactInAdvancedSearch()
     {
@@ -85,6 +109,15 @@ public class SearchTest
         assertLinkPresent( "test" );
     }
 
+    public void testSearchExistingArtifactAllCriteriaSpecifiedInAdvancedSearch()
+    {
+        searchForArtifactAdvancedSearch( getProperty( "GROUPID" ), getProperty( "ARTIFACT_ARTIFACTID" ) , getProperty( "ARTIFACT_VERSION" ), 
+                                         getProperty( "REPOSITORYID" ), getProperty( "ARTIFACT_CLASSNAME" ), null );
+        assertTextPresent( "Results" );
+        assertTextPresent( "Hits: 1 to 1 of 1" );
+        assertLinkPresent( "test" );
+    }
+
     public void testSearchExistingArtifactUsingAdvancedSearchNotInRepository()
     {
         searchForArtifactAdvancedSearch( null, getProperty( "ARTIFACT_ARTIFACTID" ), null, "snapshots", null, null );