From: Julien Lancelot Date: Thu, 20 Oct 2016 13:03:19 +0000 (+0200) Subject: SONAR-8221 Add IT on search projects action X-Git-Tag: 6.2-RC1~331 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=20aa37c82a9b850b19d3ec388ec7119fdf5c73de;p=sonarqube.git SONAR-8221 Add IT on search projects action --- 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 - - - - - - - - - - diff --git a/server/sonar-server/src/test/resources/org/sonar/server/platform/BackendCleanupTest/shared.xml b/server/sonar-server/src/test/resources/org/sonar/server/platform/BackendCleanupTest/shared.xml new file mode 100644 index 00000000000..c34799a9cff --- /dev/null +++ b/server/sonar-server/src/test/resources/org/sonar/server/platform/BackendCleanupTest/shared.xml @@ -0,0 +1,62 @@ + + + + + + + + + + + diff --git a/sonar-ws/src/main/java/org/sonarqube/ws/client/component/SearchProjectsRequest.java b/sonar-ws/src/main/java/org/sonarqube/ws/client/component/SearchProjectsRequest.java index b4f0d23f6e1..8ae6cb22d8e 100644 --- a/sonar-ws/src/main/java/org/sonarqube/ws/client/component/SearchProjectsRequest.java +++ b/sonar-ws/src/main/java/org/sonarqube/ws/client/component/SearchProjectsRequest.java @@ -20,6 +20,8 @@ package org.sonarqube.ws.client.component; +import javax.annotation.CheckForNull; + import static com.google.common.base.Preconditions.checkArgument; public class SearchProjectsRequest { @@ -36,6 +38,7 @@ public class SearchProjectsRequest { this.filter = builder.filter; } + @CheckForNull public String getFilter() { return filter; } @@ -83,12 +86,7 @@ public class SearchProjectsRequest { if (pageSize == null) { pageSize = DEFAULT_PAGE_SIZE; } - if (filter == null) { - filter = ""; - } - checkArgument(pageSize <= MAX_PAGE_SIZE, "Page size must not be greater than %s", MAX_PAGE_SIZE); - return new SearchProjectsRequest(this); } }