You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

ProjectBulkDeletionTest.java 3.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2018 SonarSource SA
  4. * mailto:info AT sonarsource DOT com
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU Lesser General Public
  8. * License as published by the Free Software Foundation; either
  9. * version 3 of the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * Lesser General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU Lesser General Public License
  17. * along with this program; if not, write to the Free Software Foundation,
  18. * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
  19. */
  20. package org.sonarqube.tests.project;
  21. import com.sonar.orchestrator.Orchestrator;
  22. import java.util.List;
  23. import java.util.stream.IntStream;
  24. import org.junit.ClassRule;
  25. import org.junit.Rule;
  26. import org.junit.Test;
  27. import org.sonarqube.qa.util.Tester;
  28. import org.sonarqube.ws.Organizations;
  29. import org.sonarqube.ws.Projects.CreateWsResponse;
  30. import org.sonarqube.ws.Projects.SearchWsResponse.Component;
  31. import org.sonarqube.ws.client.projects.BulkDeleteRequest;
  32. import org.sonarqube.ws.client.projects.SearchRequest;
  33. import static org.assertj.core.api.Assertions.assertThat;
  34. import static util.ItUtils.runProjectAnalysis;
  35. public class ProjectBulkDeletionTest {
  36. @ClassRule
  37. public static Orchestrator orchestrator = ProjectSuite.ORCHESTRATOR;
  38. @Rule
  39. public Tester tester = new Tester(orchestrator);
  40. @Test
  41. public void delete_projects() {
  42. Organizations.Organization organization = tester.organizations().generate();
  43. CreateWsResponse.Project firstProvisionedProject = tester.projects().provision(organization, p -> p.setProject("first-provisioned-project"));
  44. CreateWsResponse.Project secondProvisionedProject = tester.projects().provision(organization, p -> p.setProject("second-provisioned-project"));
  45. CreateWsResponse.Project analyzedProject = tester.projects().provision(organization);
  46. analyzeProject(analyzedProject.getKey(), organization.getKey());
  47. tester.wsClient().projects().bulkDelete(new BulkDeleteRequest()
  48. .setOrganization(organization.getKey())
  49. .setQ("FIRST-PROVISIONED")
  50. .setOnProvisionedOnly("true"));
  51. List<Component> projects = tester.wsClient().projects().search(new SearchRequest().setOrganization(organization.getKey())).getComponentsList();
  52. assertThat(projects).extracting(Component::getKey)
  53. .containsExactlyInAnyOrder(analyzedProject.getKey(), secondProvisionedProject.getKey())
  54. .doesNotContain(firstProvisionedProject.getKey());
  55. }
  56. @Test
  57. public void delete_more_than_50_projects_at_the_same_time() {
  58. Organizations.Organization organization = tester.organizations().generate();
  59. IntStream.range(0, 60).forEach(i -> tester.projects().provision(organization));
  60. SearchRequest searchRequest = new SearchRequest().setOrganization(organization.getKey());
  61. BulkDeleteRequest deleteRequest = new BulkDeleteRequest().setOrganization(organization.getKey());
  62. assertThat(tester.wsClient().projects().search(searchRequest).getPaging().getTotal()).isEqualTo(60);
  63. tester.wsClient().projects().bulkDelete(deleteRequest);
  64. assertThat(tester.wsClient().projects().search(searchRequest).getComponentsList()).isEmpty();
  65. assertThat(tester.wsClient().projects().search(searchRequest).getPaging().getTotal()).isEqualTo(0);
  66. }
  67. private void analyzeProject(String projectKey, String organizationKey) {
  68. runProjectAnalysis(orchestrator, "shared/xoo-sample",
  69. "sonar.organization", organizationKey,
  70. "sonar.projectKey", projectKey,
  71. "sonar.login", "admin",
  72. "sonar.password", "admin");
  73. }
  74. }