From 934bf664b8e032c76c9e64e28ddb3ee46d7adbc3 Mon Sep 17 00:00:00 2001 From: Simon Brandhof Date: Thu, 26 Jan 2017 18:20:57 +0100 Subject: SONAR-8704 Refactor Elasticsearch types "authorization" Multiple indices define a type "authorization". The related code was duplicated, and sometimes had some minor differences. This commits share all the management of these types in the same bunch of classes. It also allows to quickly create a project-related index, without having to fix the different locations which may require project re-indexing. --- .../java/it/projectSearch/SearchProjectsTest.java | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) (limited to 'it/it-tests') diff --git a/it/it-tests/src/test/java/it/projectSearch/SearchProjectsTest.java b/it/it-tests/src/test/java/it/projectSearch/SearchProjectsTest.java index 7790ae1589e..9b969f78e6f 100644 --- a/it/it-tests/src/test/java/it/projectSearch/SearchProjectsTest.java +++ b/it/it-tests/src/test/java/it/projectSearch/SearchProjectsTest.java @@ -35,6 +35,9 @@ import static org.assertj.core.api.Java6Assertions.assertThat; import static util.ItUtils.newAdminWsClient; import static util.ItUtils.projectDir; +/** + * Tests WS api/components/search_projects + */ public class SearchProjectsTest { @ClassRule @@ -46,16 +49,16 @@ public class SearchProjectsTest { } @Test - public void search_projects_with_filter_having_one_criterion() throws Exception { + public void filter_projects_by_measure_values() throws Exception { orchestrator.executeBuild(SonarScanner.create(projectDir("shared/xoo-sample"))); - SearchProjectsWsResponse response = searchProjects("ncloc > 1"); - - assertThat(response.getComponentsList()).extracting(Component::getKey).containsOnly("sample"); + verifyFilterMatches("ncloc > 1"); + verifyFilterMatches("ncloc > 1 and comment_lines < 10000"); + verifyFilterDoesNotMatch("ncloc <= 1"); } @Test - public void return_project_even_without_analysis() throws Exception { + public void provisioned_projects_should_be_included_to_results() throws Exception { orchestrator.getServer().provisionProject("sample", "sample"); SearchProjectsWsResponse response = searchProjects(SearchProjectsRequest.builder().build()); @@ -63,6 +66,7 @@ public class SearchProjectsTest { assertThat(response.getComponentsList()).extracting(Component::getKey).containsOnly("sample"); } + private SearchProjectsWsResponse searchProjects(String filter) throws IOException { return searchProjects(SearchProjectsRequest.builder().setFilter(filter).build()); } @@ -70,4 +74,12 @@ public class SearchProjectsTest { private SearchProjectsWsResponse searchProjects(SearchProjectsRequest request) throws IOException { return newAdminWsClient(orchestrator).components().searchProjects(request); } + + private void verifyFilterMatches(String filter) throws IOException { + assertThat(searchProjects(filter).getComponentsList()).extracting(Component::getKey).containsOnly("sample"); + } + + private void verifyFilterDoesNotMatch(String filter) throws IOException { + assertThat(searchProjects(filter).getComponentsCount()).isZero(); + } } -- cgit v1.2.3