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.

ProjectLeakPageTest.java 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  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 com.sonar.orchestrator.build.SonarScanner;
  23. import java.util.ArrayList;
  24. import java.util.List;
  25. import javax.annotation.Nullable;
  26. import org.junit.Before;
  27. import org.junit.ClassRule;
  28. import org.junit.Rule;
  29. import org.junit.Test;
  30. import org.sonarqube.qa.util.Tester;
  31. import org.sonarqube.qa.util.pageobjects.projects.ProjectsPage;
  32. import org.sonarqube.ws.Organizations.Organization;
  33. import static com.codeborne.selenide.WebDriverRunner.url;
  34. import static java.util.Arrays.asList;
  35. import static org.assertj.core.api.Assertions.assertThat;
  36. import static util.ItUtils.newProjectKey;
  37. import static util.ItUtils.projectDir;
  38. import static util.ItUtils.restoreProfile;
  39. public class ProjectLeakPageTest {
  40. @ClassRule
  41. public static Orchestrator orchestrator = ProjectSuite.ORCHESTRATOR;
  42. @Rule
  43. public Tester tester = new Tester(orchestrator);
  44. private Organization organization;
  45. @Before
  46. public void setUp() {
  47. tester.settings().setGlobalSettings("sonar.leak.period", "previous_version");
  48. organization = tester.organizations().generate();
  49. restoreProfile(orchestrator, ProjectLeakPageTest.class.getResource("/projectSearch/SearchProjectsTest/with-many-rules.xml"), organization.getKey());
  50. }
  51. @Test
  52. public void should_display_leak_information() {
  53. // This project has 0% duplication on new code
  54. String projectKey2 = newProjectKey();
  55. analyzeProject(projectKey2, "projectSearch/xoo-history-v1", "2016-12-31");
  56. analyzeProject(projectKey2, "projectSearch/xoo-history-v2", null);
  57. // This project has no duplication on new code
  58. String projectKey1 = newProjectKey();
  59. analyzeProject(projectKey1, "shared/xoo-sample", "2016-12-31");
  60. analyzeProject(projectKey1, "shared/xoo-sample", null);
  61. // Check the facets and project cards
  62. ProjectsPage page = tester.openBrowser().openProjects(organization.getKey());
  63. page.changePerspective("Leak");
  64. assertThat(url()).endsWith("/projects?view=leak");
  65. page.shouldHaveTotal(2);
  66. page.getProjectByKey(projectKey2)
  67. .shouldHaveMeasure("new_reliability_rating", "0A")
  68. .shouldHaveMeasure("new_security_rating", "0A")
  69. .shouldHaveMeasure("new_maintainability_rating", "17A")
  70. .shouldHaveMeasure("new_coverage", "–")
  71. .shouldHaveMeasure("new_duplicated_lines_density", "0.0%")
  72. .shouldHaveMeasure("new_lines", "17");
  73. page.getFacetByProperty("new_duplications")
  74. .shouldHaveValue("1", "1")
  75. .shouldHaveValue("2", "0")
  76. .shouldHaveValue("3", "0")
  77. .shouldHaveValue("4", "0")
  78. .shouldHaveValue("5", "0")
  79. .shouldHaveValue("6", "1");
  80. }
  81. private void analyzeProject(String projectKey, String relativePath, @Nullable String analysisDate) {
  82. List<String> keyValueProperties = new ArrayList<>(asList(
  83. "sonar.projectKey", projectKey,
  84. "sonar.organization", organization.getKey(),
  85. "sonar.profile", "with-many-rules",
  86. "sonar.login", "admin", "sonar.password", "admin",
  87. "sonar.scm.disabled", "false"));
  88. if (analysisDate != null) {
  89. keyValueProperties.add("sonar.projectDate");
  90. keyValueProperties.add(analysisDate);
  91. }
  92. orchestrator.executeBuild(SonarScanner.create(projectDir(relativePath), keyValueProperties.toArray(new String[0])));
  93. }
  94. }