From 71f252b734abaa3818d81708c14760a914699267 Mon Sep 17 00:00:00 2001 From: "Jevica Arianne B. Zurbano" Date: Sat, 15 May 2010 12:56:34 +0000 Subject: [PATCH] [MRM-1125] - default search should be AND not OR for multiple keywords * 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 --- .../search/NexusRepositorySearchTest.java | 96 +++++++++++++++++++ .../src/test/resources/testng.properties | 4 + .../apache/archiva/web/test/SearchTest.java | 33 +++++++ 3 files changed, 133 insertions(+) diff --git a/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/NexusRepositorySearchTest.java b/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/NexusRepositorySearchTest.java index b31c61491..fc03763a9 100644 --- a/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/NexusRepositorySearchTest.java +++ b/archiva-modules/archiva-base/archiva-indexer/src/test/java/org/apache/archiva/indexer/search/NexusRepositorySearchTest.java @@ -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 selectedRepos = new ArrayList(); + 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 files = new ArrayList(); + 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 selectedRepos = new ArrayList(); + 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 files = new ArrayList(); + 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 selectedRepos = new ArrayList(); + 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 { diff --git a/archiva-modules/archiva-web/archiva-webapp-test/src/test/resources/testng.properties b/archiva-modules/archiva-web/archiva-webapp-test/src/test/resources/testng.properties index 1230adab3..5ceeebe76 100644 --- a/archiva-modules/archiva-web/archiva-webapp-test/src/test/resources/testng.properties +++ b/archiva-modules/archiva-web/archiva-webapp-test/src/test/resources/testng.properties @@ -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 diff --git a/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/SearchTest.java b/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/SearchTest.java index 718418b00..a451328a1 100644 --- a/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/SearchTest.java +++ b/archiva-modules/archiva-web/archiva-webapp-test/src/test/testng/org/apache/archiva/web/test/SearchTest.java @@ -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 ); -- 2.39.5