Nevar pievienot vairāk kā 25 tēmas Tēmai ir jāsākas ar burtu vai ciparu, tā var saturēt domu zīmes ('-') un var būt līdz 35 simboliem gara.

OrganizationQualityProfilesPageTest.java 7.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212
  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 it.organization;
  21. import com.codeborne.selenide.Condition;
  22. import com.sonar.orchestrator.Orchestrator;
  23. import com.sonar.orchestrator.build.SonarScanner;
  24. import it.Category6Suite;
  25. import org.junit.After;
  26. import org.junit.AfterClass;
  27. import org.junit.Before;
  28. import org.junit.BeforeClass;
  29. import org.junit.ClassRule;
  30. import org.junit.Ignore;
  31. import org.junit.Test;
  32. import org.sonarqube.ws.client.PostRequest;
  33. import org.sonarqube.ws.client.WsClient;
  34. import org.sonarqube.ws.client.organization.CreateWsRequest;
  35. import pageobjects.Navigation;
  36. import static com.codeborne.selenide.Selenide.$;
  37. import static it.Category6Suite.enableOrganizationsSupport;
  38. import static util.ItUtils.deleteOrganizationsIfExists;
  39. import static util.ItUtils.newAdminWsClient;
  40. import static util.ItUtils.projectDir;
  41. import static util.selenium.Selenese.runSelenese;
  42. public class OrganizationQualityProfilesPageTest {
  43. private static WsClient adminWsClient;
  44. private static final String ORGANIZATION = "test-org";
  45. @ClassRule
  46. public static Orchestrator orchestrator = Category6Suite.ORCHESTRATOR;
  47. @BeforeClass
  48. public static void setUp() {
  49. adminWsClient = newAdminWsClient(orchestrator);
  50. enableOrganizationsSupport();
  51. createOrganization();
  52. }
  53. @AfterClass
  54. public static void tearDown() throws Exception {
  55. deleteOrganizationsIfExists(orchestrator, ORGANIZATION);
  56. }
  57. @Before
  58. public void createSampleProfile() {
  59. createProfile("xoo", "sample");
  60. inheritProfile("xoo", "sample", "Basic");
  61. analyzeProject("shared/xoo-sample");
  62. addProfileToProject("xoo", "sample", "sample");
  63. }
  64. @After
  65. public void deleteSampleProfile() {
  66. setDefault("xoo", "Basic");
  67. deleteProfile("xoo", "sample");
  68. deleteProfile("xoo", "new name");
  69. }
  70. @Test
  71. public void testNoGlobalPage() {
  72. Navigation nav = Navigation.get(orchestrator);
  73. nav.open("/profiles");
  74. $(".page-wrapper-simple").should(Condition.visible);
  75. }
  76. @Test
  77. public void testHomePage() throws Exception {
  78. runSelenese(orchestrator,
  79. "/organization/OrganizationQualityProfilesPageTest/should_display_list.html",
  80. "/organization/OrganizationQualityProfilesPageTest/should_open_from_list.html",
  81. "/organization/OrganizationQualityProfilesPageTest/should_filter_by_language.html");
  82. }
  83. @Test
  84. public void testProfilePage() throws Exception {
  85. runSelenese(orchestrator,
  86. "/organization/OrganizationQualityProfilesPageTest/should_display_profile_rules.html",
  87. "/organization/OrganizationQualityProfilesPageTest/should_display_profile_inheritance.html",
  88. "/organization/OrganizationQualityProfilesPageTest/should_display_profile_projects.html",
  89. "/organization/OrganizationQualityProfilesPageTest/should_display_profile_exporters.html");
  90. }
  91. @Test
  92. public void testNotFound() {
  93. Navigation nav = Navigation.get(orchestrator);
  94. nav.open("/organizations/" + ORGANIZATION + "/quality_profiles/show?key=unknown");
  95. $(".quality-profile-not-found").should(Condition.visible);
  96. nav.open("/organizations/" + ORGANIZATION + "/quality_profiles/show?language=xoo&name=unknown");
  97. $(".quality-profile-not-found").should(Condition.visible);
  98. }
  99. @Test
  100. public void testProfileChangelog() throws Exception {
  101. runSelenese(orchestrator,
  102. "/organization/OrganizationQualityProfilesPageTest/should_display_changelog.html");
  103. }
  104. @Ignore("find a way to know profile key inside selenium tests")
  105. @Test
  106. public void testComparison() throws Exception {
  107. runSelenese(orchestrator, "/organization/OrganizationQualityProfilesPageTest/should_compare.html");
  108. }
  109. @Test
  110. public void testCreation() throws Exception {
  111. runSelenese(orchestrator, "/organization/OrganizationQualityProfilesPageTest/should_create.html");
  112. }
  113. @Test
  114. public void testDeletion() throws Exception {
  115. runSelenese(orchestrator, "/organization/OrganizationQualityProfilesPageTest/should_delete.html");
  116. }
  117. @Test
  118. public void testCopying() throws Exception {
  119. runSelenese(orchestrator, "/organization/OrganizationQualityProfilesPageTest/should_copy.html");
  120. }
  121. @Test
  122. public void testRenaming() throws Exception {
  123. runSelenese(orchestrator, "/organization/OrganizationQualityProfilesPageTest/should_rename.html");
  124. }
  125. @Test
  126. public void testSettingDefault() throws Exception {
  127. runSelenese(orchestrator, "/organization/OrganizationQualityProfilesPageTest/should_set_default.html");
  128. }
  129. @Test
  130. public void testRestoration() throws Exception {
  131. deleteProfile("xoo", "empty");
  132. runSelenese(orchestrator,
  133. "/organization/OrganizationQualityProfilesPageTest/should_restore.html",
  134. "/organization/OrganizationQualityProfilesPageTest/should_restore_built_in.html");
  135. }
  136. private static void createProfile(String language, String name) {
  137. adminWsClient.wsConnector().call(
  138. new PostRequest("api/qualityprofiles/create")
  139. .setParam("language", language)
  140. .setParam("name", name)
  141. .setParam("organization", ORGANIZATION));
  142. }
  143. private static void inheritProfile(String language, String name, String parentName) {
  144. adminWsClient.wsConnector().call(
  145. new PostRequest("api/qualityprofiles/change_parent")
  146. .setParam("language", language)
  147. .setParam("profileName", name)
  148. .setParam("parentName", parentName)
  149. .setParam("organization", ORGANIZATION));
  150. }
  151. private static void analyzeProject(String path) {
  152. orchestrator.executeBuild(SonarScanner.create(projectDir(path)).setProperties(
  153. "sonar.organization", ORGANIZATION,
  154. "sonar.login", "admin",
  155. "sonar.password", "admin"));
  156. }
  157. private static void addProfileToProject(String language, String profileName, String projectKey) {
  158. adminWsClient.wsConnector().call(
  159. new PostRequest("api/qualityprofiles/add_project")
  160. .setParam("language", language)
  161. .setParam("profileName", profileName)
  162. .setParam("organization", ORGANIZATION)
  163. .setParam("projectKey", projectKey));
  164. }
  165. private static void deleteProfile(String language, String name) {
  166. adminWsClient.wsConnector().call(
  167. new PostRequest("api/qualityprofiles/delete")
  168. .setParam("language", language)
  169. .setParam("profileName", name)
  170. .setParam("organization", ORGANIZATION));
  171. }
  172. private static void setDefault(String language, String name) {
  173. adminWsClient.wsConnector().call(
  174. new PostRequest("api/qualityprofiles/set_default")
  175. .setParam("language", language)
  176. .setParam("profileName", name)
  177. .setParam("organization", ORGANIZATION));
  178. }
  179. private static void createOrganization() {
  180. adminWsClient.organizations().create(new CreateWsRequest.Builder().setKey(ORGANIZATION).setName(ORGANIZATION).build());
  181. }
  182. }