From: Daniel Schwarz Date: Tue, 24 Jan 2017 10:47:05 +0000 (+0100) Subject: SONAR-8678 allow search for components by multiple, independent words X-Git-Tag: 6.3-RC1~446 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=cb883c44ccc301e14972c0bfde83126224fc2cfb;p=sonarqube.git SONAR-8678 allow search for components by multiple, independent words --- diff --git a/server/sonar-server/src/test/java/org/sonar/server/component/index/ComponentIndexTest.java b/server/sonar-server/src/test/java/org/sonar/server/component/index/ComponentIndexTest.java index f601184a60e..5668df9613d 100644 --- a/server/sonar-server/src/test/java/org/sonar/server/component/index/ComponentIndexTest.java +++ b/server/sonar-server/src/test/java/org/sonar/server/component/index/ComponentIndexTest.java @@ -258,6 +258,36 @@ public class ComponentIndexTest { assertSearchResults("sonqub", project); } + @Test + public void should_search_for_word_and_suffix() { + assertFileMatches("plugin java", "AbstractPluginFactory.java"); + } + + @Test + public void should_search_for_word_and_suffix_in_any_order() { + assertFileMatches("java plugin", "AbstractPluginFactory.java"); + } + + @Test + public void should_search_for_two_words() { + assertFileMatches("abstract factory", "AbstractPluginFactory.java"); + } + + @Test + public void should_search_for_two_words_in_any_order() { + assertFileMatches("factory abstract", "AbstractPluginFactory.java"); + } + + @Test + public void should_find_item_with_at_least_one_matching_word() { + assertFileMatches("abstract object", "AbstractPluginFactory.java"); + } + + @Test + public void should_require_at_least_one_matching_word() { + assertNoFileMatches("monitor object", "AbstractPluginFactory.java"); + } + @Test public void should_respect_confidentiallity() { indexer.index(newProject("sonarqube", "Quality Product")); @@ -302,6 +332,19 @@ public class ComponentIndexTest { userSession.login("john").setUserId(TEST_USER_ID).setUserGroups(TEST_USER_GROUP); } + private void assertFileMatches(String query, String... fileNames) { + ComponentDto[] files = Arrays.stream(fileNames) + .map(this::indexFile) + .toArray(ComponentDto[]::new); + assertSearch(query).containsExactlyInAnyOrder(uuids(files)); + } + + private void assertNoFileMatches(String query, String... fileNames) { + Arrays.stream(fileNames) + .forEach(this::indexFile); + assertSearch(query).isEmpty(); + } + private AbstractListAssert, String> assertSearch(String query) { return assertSearch(new ComponentIndexQuery(query)); } @@ -339,6 +382,11 @@ public class ComponentIndexTest { .setName(name); } + private ComponentDto indexFile(String fileName) { + ComponentDto project = indexProject("key-1", "SonarQube"); + return indexFile(project, "src/main/java/" + fileName, fileName); + } + private ComponentDto indexFile(ComponentDto project, String fileKey, String fileName) { return index( ComponentTesting.newFileDto(project)