From 20aa37c82a9b850b19d3ec388ec7119fdf5c73de Mon Sep 17 00:00:00 2001 From: Julien Lancelot Date: Thu, 20 Oct 2016 15:03:19 +0200 Subject: [PATCH] SONAR-8221 Add IT on search projects action --- .../src/test/java/it/Category4Suite.java | 3 + .../it/projectSearch/SearchProjectsTest.java | 73 +++++++++++++++++++ .../es/ProjectMeasuresResultSetIterator.java | 2 +- .../sonar/server/platform/BackendCleanup.java | 4 +- ...ediumTest.java => BackendCleanupTest.java} | 13 +++- .../shared.xml | 0 .../component/SearchProjectsRequest.java | 8 +- 7 files changed, 93 insertions(+), 10 deletions(-) create mode 100644 it/it-tests/src/test/java/it/projectSearch/SearchProjectsTest.java rename server/sonar-server/src/test/java/org/sonar/server/platform/{BackendCleanupMediumTest.java => BackendCleanupTest.java} (87%) rename server/sonar-server/src/test/resources/org/sonar/server/platform/{BackendCleanupMediumTest => BackendCleanupTest}/shared.xml (100%) diff --git a/it/it-tests/src/test/java/it/Category4Suite.java b/it/it-tests/src/test/java/it/Category4Suite.java index d32ea11c17c..fe2aa8342cf 100644 --- a/it/it-tests/src/test/java/it/Category4Suite.java +++ b/it/it-tests/src/test/java/it/Category4Suite.java @@ -34,6 +34,7 @@ import it.duplication.NewDuplicationsTest; import it.http.HttpHeadersTest; import it.projectComparison.ProjectComparisonTest; import it.projectEvent.EventTest; +import it.projectSearch.SearchProjectsTest; import it.qualityProfile.QualityProfilesPageTest; import it.serverSystem.LogsTest; import it.serverSystem.ServerSystemTest; @@ -87,6 +88,8 @@ import static util.ItUtils.xooPlugin; DashboardTest.class, // project comparison ProjectComparisonTest.class, + // project search + SearchProjectsTest.class, // component search AllProjectsTest.class, // http diff --git a/it/it-tests/src/test/java/it/projectSearch/SearchProjectsTest.java b/it/it-tests/src/test/java/it/projectSearch/SearchProjectsTest.java new file mode 100644 index 00000000000..7790ae1589e --- /dev/null +++ b/it/it-tests/src/test/java/it/projectSearch/SearchProjectsTest.java @@ -0,0 +1,73 @@ +/* + * SonarQube + * Copyright (C) 2009-2016 SonarSource SA + * mailto:contact AT sonarsource DOT com + * + * This program is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 3 of the License, or (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public License + * along with this program; if not, write to the Free Software Foundation, + * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. + */ + +package it.projectSearch; + +import com.sonar.orchestrator.Orchestrator; +import com.sonar.orchestrator.build.SonarScanner; +import it.Category4Suite; +import java.io.IOException; +import org.junit.Before; +import org.junit.ClassRule; +import org.junit.Test; +import org.sonarqube.ws.WsComponents.Component; +import org.sonarqube.ws.WsComponents.SearchProjectsWsResponse; +import org.sonarqube.ws.client.component.SearchProjectsRequest; + +import static org.assertj.core.api.Java6Assertions.assertThat; +import static util.ItUtils.newAdminWsClient; +import static util.ItUtils.projectDir; + +public class SearchProjectsTest { + + @ClassRule + public static Orchestrator orchestrator = Category4Suite.ORCHESTRATOR; + + @Before + public void setUp() throws Exception { + orchestrator.resetData(); + } + + @Test + public void search_projects_with_filter_having_one_criterion() throws Exception { + orchestrator.executeBuild(SonarScanner.create(projectDir("shared/xoo-sample"))); + + SearchProjectsWsResponse response = searchProjects("ncloc > 1"); + + assertThat(response.getComponentsList()).extracting(Component::getKey).containsOnly("sample"); + } + + @Test + public void return_project_even_without_analysis() throws Exception { + orchestrator.getServer().provisionProject("sample", "sample"); + + SearchProjectsWsResponse response = searchProjects(SearchProjectsRequest.builder().build()); + + assertThat(response.getComponentsList()).extracting(Component::getKey).containsOnly("sample"); + } + + private SearchProjectsWsResponse searchProjects(String filter) throws IOException { + return searchProjects(SearchProjectsRequest.builder().setFilter(filter).build()); + } + + private SearchProjectsWsResponse searchProjects(SearchProjectsRequest request) throws IOException { + return newAdminWsClient(orchestrator).components().searchProjects(request); + } +} diff --git a/server/sonar-server/src/main/java/org/sonar/server/component/es/ProjectMeasuresResultSetIterator.java b/server/sonar-server/src/main/java/org/sonar/server/component/es/ProjectMeasuresResultSetIterator.java index fe6798aa8f2..2e9c1c1daa5 100644 --- a/server/sonar-server/src/main/java/org/sonar/server/component/es/ProjectMeasuresResultSetIterator.java +++ b/server/sonar-server/src/main/java/org/sonar/server/component/es/ProjectMeasuresResultSetIterator.java @@ -141,7 +141,7 @@ public class ProjectMeasuresResultSetIterator extends ResultSetIterator