diff options
author | Teryk Bellahsene <teryk.bellahsene@sonarsource.com> | 2017-09-06 12:28:04 +0200 |
---|---|---|
committer | Stas Vilchik <stas.vilchik@sonarsource.com> | 2017-09-11 11:28:29 +0200 |
commit | 0926670e79d919e0afa3f0a2e11f656bdcd05916 (patch) | |
tree | fb2b9fbc78a38460fd914729b810afdbb8021cbb /tests/src/test/java | |
parent | 272dfe918009de0938fde9835961b37420808ffa (diff) | |
download | sonarqube-0926670e79d919e0afa3f0a2e11f656bdcd05916.tar.gz sonarqube-0926670e79d919e0afa3f0a2e11f656bdcd05916.zip |
SONAR-9181 WS api/projects/bulk_delete accepts the sames parameters as api/projects/search
Diffstat (limited to 'tests/src/test/java')
-rw-r--r-- | tests/src/test/java/org/sonarqube/tests/Category6Suite.java | 4 | ||||
-rw-r--r-- | tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectAdministrationTest.java | 11 | ||||
-rw-r--r-- | tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectBulkDeleteTest.java | 86 | ||||
-rw-r--r-- | tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectDeleteTest.java (renamed from tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectDeletionTest.java) | 7 |
4 files changed, 98 insertions, 10 deletions
diff --git a/tests/src/test/java/org/sonarqube/tests/Category6Suite.java b/tests/src/test/java/org/sonarqube/tests/Category6Suite.java index d075f209596..e1e4e666dc6 100644 --- a/tests/src/test/java/org/sonarqube/tests/Category6Suite.java +++ b/tests/src/test/java/org/sonarqube/tests/Category6Suite.java @@ -35,7 +35,7 @@ import org.sonarqube.tests.organization.OrganizationMembershipUiTest; import org.sonarqube.tests.organization.OrganizationTest; import org.sonarqube.tests.organization.PersonalOrganizationTest; import org.sonarqube.tests.organization.RootUserOnOrganizationTest; -import org.sonarqube.tests.projectAdministration.ProjectDeletionTest; +import org.sonarqube.tests.projectAdministration.ProjectDeleteTest; import org.sonarqube.tests.projectAdministration.ProjectKeyUpdateTest; import org.sonarqube.tests.projectAdministration.ProjectProvisioningTest; import org.sonarqube.tests.projectAdministration.ProjectSearchTest; @@ -77,7 +77,7 @@ import static util.ItUtils.xooPlugin; LeakProjectsPageTest.class, SearchProjectsTest.class, RulesWsTest.class, - ProjectDeletionTest.class, + ProjectDeleteTest.class, ProjectProvisioningTest.class, ProjectKeyUpdateTest.class, ProjectSearchTest.class, diff --git a/tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectAdministrationTest.java b/tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectAdministrationTest.java index 3a4d1aad047..b001176c914 100644 --- a/tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectAdministrationTest.java +++ b/tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectAdministrationTest.java @@ -47,8 +47,10 @@ import org.sonarqube.ws.WsPermissions; import org.sonarqube.ws.client.permission.AddUserToTemplateWsRequest; import org.sonarqube.ws.client.permission.CreateTemplateWsRequest; import org.sonarqube.ws.client.permission.UsersWsRequest; +import org.sonarqube.ws.client.project.SearchWsRequest; import static com.codeborne.selenide.Selenide.$; +import static java.util.Collections.singletonList; import static org.apache.commons.lang.time.DateUtils.addDays; import static org.assertj.core.api.Assertions.assertThat; import static util.ItUtils.getComponent; @@ -97,14 +99,15 @@ public class ProjectAdministrationTest { @Test public void fail_when_trying_to_delete_a_file() { - expectedException.expect(HttpException.class); scanSampleWithDate(ANALYSIS_DATE); - assertThat(getComponent(orchestrator, PROJECT_KEY)).isNotNull(); assertThat(getComponent(orchestrator, FILE_KEY)).isNotNull(); - // it's forbidden to delete only some files - orchestrator.getServer().adminWsClient().post(DELETE_WS_ENDPOINT, "keys", FILE_KEY); + expectedException.expect(org.sonarqube.ws.client.HttpException.class); + + tester.wsClient().projects().bulkDelete(SearchWsRequest.builder() + .setQualifiers(singletonList("FIL")) + .setProjects(singletonList(FILE_KEY)).build()); } @Test diff --git a/tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectBulkDeleteTest.java b/tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectBulkDeleteTest.java new file mode 100644 index 00000000000..28d601e0e21 --- /dev/null +++ b/tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectBulkDeleteTest.java @@ -0,0 +1,86 @@ +/* + * SonarQube + * Copyright (C) 2009-2017 SonarSource SA + * mailto:info 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 org.sonarqube.tests.projectAdministration; + +import com.sonar.orchestrator.Orchestrator; +import java.util.List; +import java.util.stream.IntStream; +import org.junit.ClassRule; +import org.junit.Rule; +import org.junit.Test; +import org.sonarqube.tests.Category6Suite; +import org.sonarqube.tests.Tester; +import org.sonarqube.ws.Organizations; +import org.sonarqube.ws.WsProjects.CreateWsResponse; +import org.sonarqube.ws.WsProjects.SearchWsResponse.Component; +import org.sonarqube.ws.client.project.SearchWsRequest; + +import static org.assertj.core.api.Assertions.assertThat; +import static util.ItUtils.runProjectAnalysis; + +public class ProjectBulkDeleteTest { + + @ClassRule + public static Orchestrator orchestrator = Category6Suite.ORCHESTRATOR; + @Rule + public Tester tester = new Tester(orchestrator); + + @Test + public void delete_projects() { + Organizations.Organization organization = tester.organizations().generate(); + CreateWsResponse.Project firstProvisionedProject = tester.projects().generate(organization, p -> p.setKey("first-provisioned-project")); + CreateWsResponse.Project secondProvisionedProject = tester.projects().generate(organization, p -> p.setKey("second-provisioned-project")); + CreateWsResponse.Project analyzedProject = tester.projects().generate(organization); + + analyzeProject(analyzedProject.getKey(), organization.getKey()); + + tester.wsClient().projects().bulkDelete(SearchWsRequest.builder() + .setOrganization(organization.getKey()) + .setQuery("FIRST-PROVISIONED") + .setOnProvisionedOnly(true).build()); + + List<Component> projects = tester.wsClient().projects().search(SearchWsRequest.builder().setOrganization(organization.getKey()).build()).getComponentsList(); + assertThat(projects).extracting(Component::getKey) + .containsExactlyInAnyOrder(analyzedProject.getKey(), secondProvisionedProject.getKey()) + .doesNotContain(firstProvisionedProject.getKey()); + } + + @Test + public void delete_more_than_50_projects_at_the_same_time() { + Organizations.Organization organization = tester.organizations().generate(); + IntStream.range(0, 60).forEach(i -> tester.projects().generate(organization)); + SearchWsRequest request = SearchWsRequest.builder().setOrganization(organization.getKey()).build(); + assertThat(tester.wsClient().projects().search(request).getPaging().getTotal()).isEqualTo(60); + + tester.wsClient().projects().bulkDelete(request); + + assertThat(tester.wsClient().projects().search(request).getComponentsList()).isEmpty(); + assertThat(tester.wsClient().projects().search(request).getPaging().getTotal()).isEqualTo(0); + } + + private void analyzeProject(String projectKey, String organizationKey) { + runProjectAnalysis(orchestrator, "shared/xoo-sample", + "sonar.organization", organizationKey, + "sonar.projectKey", projectKey, + "sonar.login", "admin", + "sonar.password", "admin"); + } +} diff --git a/tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectDeletionTest.java b/tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectDeleteTest.java index d9ea32b0bb9..b0b43103ac6 100644 --- a/tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectDeletionTest.java +++ b/tests/src/test/java/org/sonarqube/tests/projectAdministration/ProjectDeleteTest.java @@ -39,7 +39,6 @@ import org.sonarqube.ws.WsProjects.CreateWsResponse.Project; import org.sonarqube.ws.client.GetRequest; import org.sonarqube.ws.client.WsResponse; import org.sonarqube.ws.client.component.SearchProjectsRequest; -import org.sonarqube.ws.client.project.BulkDeleteRequest; import org.sonarqube.ws.client.project.CreateRequest; import org.sonarqube.ws.client.project.DeleteRequest; import org.sonarqube.ws.client.project.SearchWsRequest; @@ -48,7 +47,7 @@ import util.ItUtils; import static java.util.Collections.singletonList; import static org.assertj.core.api.Assertions.assertThat; -public class ProjectDeletionTest { +public class ProjectDeleteTest { @ClassRule public static final Orchestrator orchestrator = Category6Suite.ORCHESTRATOR; @@ -137,9 +136,9 @@ public class ProjectDeletionTest { } private void bulkDeleteProjects(Organizations.Organization organization, Project... projects) { - BulkDeleteRequest request = BulkDeleteRequest.builder() + SearchWsRequest request = SearchWsRequest.builder() .setOrganization(organization.getKey()) - .setProjectKeys(Arrays.stream(projects).map(Project::getKey).collect(Collectors.toList())) + .setProjects(Arrays.stream(projects).map(Project::getKey).collect(Collectors.toList())) .build(); tester.wsClient().projects().bulkDelete(request); } |