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.

ProjectLinksTest.java 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  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.codeborne.selenide.Condition;
  22. import com.sonar.orchestrator.Orchestrator;
  23. import com.sonar.orchestrator.build.SonarScanner;
  24. import java.util.List;
  25. import org.junit.After;
  26. import org.junit.Before;
  27. import org.junit.BeforeClass;
  28. import org.junit.ClassRule;
  29. import org.junit.Test;
  30. import org.junit.rules.RuleChain;
  31. import org.sonarqube.qa.util.Tester;
  32. import org.sonarqube.qa.util.pageobjects.ProjectLinkItem;
  33. import org.sonarqube.qa.util.pageobjects.ProjectLinksPage;
  34. import org.sonarqube.ws.ProjectLinks.CreateWsResponse;
  35. import org.sonarqube.ws.client.projectlinks.CreateRequest;
  36. import org.sonarqube.ws.client.projectlinks.DeleteRequest;
  37. import static com.codeborne.selenide.Condition.text;
  38. import static com.codeborne.selenide.Condition.visible;
  39. import static com.codeborne.selenide.Selenide.$;
  40. import static util.ItUtils.projectDir;
  41. public class ProjectLinksTest {
  42. @ClassRule
  43. public static Orchestrator orchestrator = ProjectSuite.ORCHESTRATOR;
  44. private static Tester tester = new Tester(orchestrator);
  45. @ClassRule
  46. public static RuleChain ruleChain = RuleChain.outerRule(orchestrator).around(tester);
  47. private String customLinkId;
  48. private String adminUser;
  49. @BeforeClass
  50. public static void setUp() {
  51. orchestrator.executeBuild(
  52. SonarScanner.create(projectDir("shared/xoo-sample"))
  53. .setProperty("sonar.links.homepage", "http://example.com"));
  54. }
  55. @Before
  56. public void prepare() {
  57. customLinkId = createCustomLink().getLink().getId();
  58. adminUser = tester.users().generateAdministratorOnDefaultOrganization().getLogin();
  59. }
  60. @After
  61. public void clean() {
  62. deleteLink(customLinkId);
  63. }
  64. @Test
  65. public void should_list_links() {
  66. ProjectLinksPage page = openLinksPage();
  67. page.getLinks().shouldHaveSize(2);
  68. List<ProjectLinkItem> links = page.getLinksAsItems();
  69. ProjectLinkItem homepageLink = links.get(0);
  70. ProjectLinkItem customLink = links.get(1);
  71. homepageLink.getType().should(text("sonar.links.homepage"));
  72. homepageLink.getUrl().should(text("http://example.com"));
  73. homepageLink.getDeleteButton().shouldNot(Condition.exist);
  74. customLink.getName().should(text("Custom"));
  75. customLink.getType().shouldNot(Condition.exist);
  76. customLink.getUrl().should(text("http://example.org/custom"));
  77. customLink.getDeleteButton().shouldBe(visible);
  78. }
  79. @Test
  80. public void should_create_link() {
  81. ProjectLinksPage page = openLinksPage();
  82. page.getLinks().shouldHaveSize(2);
  83. $("#create-project-link").click();
  84. $("#create-link-name").setValue("Test");
  85. $("#create-link-url").setValue("http://example.com/test");
  86. $("#create-link-confirm").click();
  87. page.getLinks().shouldHaveSize(3);
  88. ProjectLinkItem testLink = page.getLinksAsItems().get(2);
  89. testLink.getName().should(text("Test"));
  90. testLink.getType().shouldNot(Condition.exist);
  91. testLink.getUrl().should(text("http://example.com/test"));
  92. testLink.getDeleteButton().shouldBe(visible);
  93. }
  94. @Test
  95. public void should_delete_link() {
  96. ProjectLinksPage page = openLinksPage();
  97. page.getLinks().shouldHaveSize(2);
  98. List<ProjectLinkItem> links = page.getLinksAsItems();
  99. ProjectLinkItem customLink = links.get(1);
  100. customLink.getDeleteButton().click();
  101. $(".modal").shouldBe(visible);
  102. $(".modal button[type=\"submit\"]").click();
  103. page.getLinks().shouldHaveSize(1);
  104. }
  105. private CreateWsResponse createCustomLink() {
  106. return tester.wsClient().projectLinks().create(new CreateRequest()
  107. .setProjectKey("sample")
  108. .setName("Custom")
  109. .setUrl("http://example.org/custom"));
  110. }
  111. private void deleteLink(String id) {
  112. try {
  113. tester.wsClient().projectLinks().delete(new DeleteRequest().setId(id));
  114. } catch (Exception e) {
  115. // fail silently
  116. }
  117. }
  118. private ProjectLinksPage openLinksPage() {
  119. return tester
  120. .openBrowser()
  121. .logIn()
  122. .submitCredentials(adminUser, adminUser)
  123. .openProjectLinks("sample");
  124. }
  125. }