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.

ProjectQualityGatePageTest.java 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136
  1. /*
  2. * SonarQube
  3. * Copyright (C) 2009-2017 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.qualityGate;
  21. import com.codeborne.selenide.Condition;
  22. import com.codeborne.selenide.SelenideElement;
  23. import com.sonar.orchestrator.Orchestrator;
  24. import org.junit.After;
  25. import org.junit.Before;
  26. import org.junit.ClassRule;
  27. import org.junit.Rule;
  28. import org.junit.Test;
  29. import org.sonar.wsclient.qualitygate.QualityGate;
  30. import org.sonar.wsclient.qualitygate.QualityGateClient;
  31. import org.sonarqube.qa.util.Tester;
  32. import org.sonarqube.qa.util.pageobjects.Navigation;
  33. import org.sonarqube.qa.util.pageobjects.ProjectQualityGatePage;
  34. import org.sonarqube.ws.client.PostRequest;
  35. import org.sonarqube.ws.client.qualitygates.SelectRequest;
  36. public class ProjectQualityGatePageTest {
  37. @ClassRule
  38. public static Orchestrator orchestrator = QualityGateSuite.ORCHESTRATOR;
  39. @Rule
  40. public Tester tester = new Tester(orchestrator)
  41. // all the tests of QualityGateSuite must disable organizations
  42. .disableOrganizations();
  43. @Before
  44. public void setUp() {
  45. tester.wsClient().wsConnector().call(new PostRequest("api/projects/create")
  46. .setParam("name", "Sample")
  47. .setParam("key", "sample"));
  48. defaultGate = qualityGateClient().list().defaultGate();
  49. }
  50. private QualityGate defaultGate;
  51. @After
  52. public void tearDown() {
  53. if (defaultGate != null) {
  54. qualityGateClient().setDefault(defaultGate.id());
  55. }
  56. }
  57. @Test
  58. public void should_display_default() {
  59. QualityGate customQualityGate = createCustomQualityGate("should_display_default");
  60. qualityGateClient().setDefault(customQualityGate.id());
  61. try {
  62. ProjectQualityGatePage page = openPage();
  63. SelenideElement selectedQualityGate = page.getSelectedQualityGate();
  64. selectedQualityGate.should(Condition.text("Default"));
  65. selectedQualityGate.should(Condition.text(customQualityGate.name()));
  66. } finally {
  67. qualityGateClient().destroy(customQualityGate.id());
  68. }
  69. }
  70. @Test
  71. public void should_display_custom() {
  72. QualityGate customQualityGate = createCustomQualityGate("should_display_custom");
  73. associateWithQualityGate(customQualityGate);
  74. ProjectQualityGatePage page = openPage();
  75. SelenideElement selectedQualityGate = page.getSelectedQualityGate();
  76. selectedQualityGate.shouldNot(Condition.text("Default"));
  77. selectedQualityGate.should(Condition.text(customQualityGate.name()));
  78. }
  79. @Test
  80. public void should_set_custom() {
  81. QualityGate customQualityGate = createCustomQualityGate("should_set_custom");
  82. ProjectQualityGatePage page = openPage();
  83. page.setQualityGate(customQualityGate.name());
  84. SelenideElement selectedQualityGate = page.getSelectedQualityGate();
  85. selectedQualityGate.should(Condition.text(customQualityGate.name()));
  86. }
  87. @Test
  88. public void should_set_default() {
  89. QualityGate customQualityGate = createCustomQualityGate("should_set_default");
  90. qualityGateClient().setDefault(customQualityGate.id());
  91. try {
  92. ProjectQualityGatePage page = openPage();
  93. page.setQualityGate(customQualityGate.name());
  94. SelenideElement selectedQualityGate = page.getSelectedQualityGate();
  95. selectedQualityGate.should(Condition.text("Default"));
  96. selectedQualityGate.should(Condition.text(customQualityGate.name()));
  97. } finally {
  98. qualityGateClient().destroy(customQualityGate.id());
  99. }
  100. }
  101. private ProjectQualityGatePage openPage() {
  102. tester.wsClient().users().skipOnboardingTutorial();
  103. Navigation navigation = tester.openBrowser().logIn().submitCredentials("admin");
  104. return navigation.openProjectQualityGate("sample");
  105. }
  106. private QualityGate createCustomQualityGate(String name) {
  107. return qualityGateClient().create(name);
  108. }
  109. private void associateWithQualityGate(QualityGate qualityGate) {
  110. tester.wsClient().qualitygates().select(new SelectRequest().setProjectKey("sample").setGateId(String.valueOf(qualityGate.id())));
  111. }
  112. private QualityGateClient qualityGateClient() {
  113. return orchestrator.getServer().adminWsClient().qualityGateClient();
  114. }
  115. }