aboutsummaryrefslogtreecommitdiffstats
path: root/it
diff options
context:
space:
mode:
authorStas Vilchik <vilchiks@gmail.com>2016-07-29 16:08:36 +0200
committerGitHub <noreply@github.com>2016-07-29 16:08:36 +0200
commit0b1226871a26f136739f29050de52088b2aa1c3e (patch)
tree1124abd73a6cf58d45e17cc0fb075a4076ca4320 /it
parent3e3e4b1e16c0e5ebf8a485d3014cb7bd2577e192 (diff)
downloadsonarqube-0b1226871a26f136739f29050de52088b2aa1c3e.tar.gz
sonarqube-0b1226871a26f136739f29050de52088b2aa1c3e.zip
SONAR-7920 Rewrite Links project page (#1127)
Diffstat (limited to 'it')
-rw-r--r--it/it-tests/src/test/java/it/Category1Suite.java2
-rw-r--r--it/it-tests/src/test/java/it/projectAdministration/ProjectLinksPageTest.java153
-rw-r--r--it/it-tests/src/test/java/pageobjects/LoginPage.java6
-rw-r--r--it/it-tests/src/test/java/pageobjects/Navigation.java6
-rw-r--r--it/it-tests/src/test/java/pageobjects/ProjectLinkItem.java52
-rw-r--r--it/it-tests/src/test/java/pageobjects/ProjectLinksPage.java47
6 files changed, 265 insertions, 1 deletions
diff --git a/it/it-tests/src/test/java/it/Category1Suite.java b/it/it-tests/src/test/java/it/Category1Suite.java
index 65ff384d431..b613cc3ec2b 100644
--- a/it/it-tests/src/test/java/it/Category1Suite.java
+++ b/it/it-tests/src/test/java/it/Category1Suite.java
@@ -43,6 +43,7 @@ import it.measureHistory.TimeMachineTest;
import it.projectAdministration.BackgroundTasksTest;
import it.projectAdministration.BulkDeletionTest;
import it.projectAdministration.ProjectAdministrationTest;
+import it.projectAdministration.ProjectLinksPageTest;
import it.qualityGate.QualityGateNotificationTest;
import it.qualityGate.QualityGateTest;
import it.qualityGate.QualityGateUiTest;
@@ -66,6 +67,7 @@ import static util.ItUtils.xooPlugin;
// project administration
BulkDeletionTest.class,
ProjectAdministrationTest.class,
+ ProjectLinksPageTest.class,
BackgroundTasksTest.class,
// settings
PropertySetsTest.class,
diff --git a/it/it-tests/src/test/java/it/projectAdministration/ProjectLinksPageTest.java b/it/it-tests/src/test/java/it/projectAdministration/ProjectLinksPageTest.java
new file mode 100644
index 00000000000..6faea2774f0
--- /dev/null
+++ b/it/it-tests/src/test/java/it/projectAdministration/ProjectLinksPageTest.java
@@ -0,0 +1,153 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package it.projectAdministration;
+
+import com.codeborne.selenide.Condition;
+import com.sonar.orchestrator.Orchestrator;
+import com.sonar.orchestrator.build.SonarScanner;
+import it.Category1Suite;
+import java.util.List;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.ClassRule;
+import org.junit.Rule;
+import org.junit.Test;
+import org.sonarqube.ws.WsProjectLinks.CreateWsResponse;
+import org.sonarqube.ws.client.WsClient;
+import org.sonarqube.ws.client.projectlinks.CreateWsRequest;
+import org.sonarqube.ws.client.projectlinks.DeleteWsRequest;
+import pageobjects.Navigation;
+import pageobjects.ProjectLinkItem;
+import pageobjects.ProjectLinksPage;
+
+import static com.codeborne.selenide.Condition.hasText;
+import static com.codeborne.selenide.Selenide.$;
+import static util.ItUtils.newAdminWsClient;
+import static util.ItUtils.projectDir;
+
+public class ProjectLinksPageTest {
+
+ @ClassRule
+ public static Orchestrator ORCHESTRATOR = Category1Suite.ORCHESTRATOR;
+
+ @Rule
+ public Navigation nav = Navigation.get(ORCHESTRATOR);
+
+ private static WsClient wsClient;
+ private long customLinkId;
+
+ @BeforeClass
+ public static void setUp() {
+ wsClient = newAdminWsClient(ORCHESTRATOR);
+
+ ORCHESTRATOR.resetData();
+ ORCHESTRATOR.executeBuild(
+ SonarScanner.create(projectDir("shared/xoo-sample"))
+ .setProperty("sonar.links.homepage", "http://example.com"));
+ }
+
+ @Before
+ public void prepare() {
+ customLinkId = Long.parseLong(createCustomLink().getLink().getId());
+ }
+
+ @After
+ public void clean() {
+ deleteLink(customLinkId);
+ }
+
+ @Test
+ public void should_list_links() {
+ ProjectLinksPage page = openPage();
+
+ page.getLinks().shouldHaveSize(2);
+
+ List<ProjectLinkItem> links = page.getLinksAsItems();
+ ProjectLinkItem homepageLink = links.get(0);
+ ProjectLinkItem customLink = links.get(1);
+
+ homepageLink.getName().should(hasText("Home"));
+ homepageLink.getType().should(hasText("sonar.links.homepage"));
+ homepageLink.getUrl().should(hasText("http://example.com"));
+ homepageLink.getDeleteButton().shouldNot(Condition.present);
+
+ customLink.getName().should(hasText("Custom"));
+ customLink.getType().shouldNot(Condition.present);
+ customLink.getUrl().should(hasText("http://example.org/custom"));
+ customLink.getDeleteButton().shouldBe(Condition.visible);
+ }
+
+ @Test
+ public void should_create_link() {
+ ProjectLinksPage page = openPage();
+
+ page.getLinks().shouldHaveSize(2);
+
+ $("#create-project-link").click();
+ $("#create-link-name").setValue("Test");
+ $("#create-link-url").setValue("http://example.com/test");
+ $("#create-link-confirm").click();
+
+ page.getLinks().shouldHaveSize(3);
+
+ ProjectLinkItem testLink = page.getLinksAsItems().get(2);
+
+ testLink.getName().should(hasText("Test"));
+ testLink.getType().shouldNot(Condition.present);
+ testLink.getUrl().should(hasText("http://example.com/test"));
+ testLink.getDeleteButton().shouldBe(Condition.visible);
+ }
+
+ @Test
+ public void should_delete_link() {
+ ProjectLinksPage page = openPage();
+
+ page.getLinks().shouldHaveSize(2);
+
+ List<ProjectLinkItem> links = page.getLinksAsItems();
+ ProjectLinkItem customLink = links.get(1);
+
+ customLink.getDeleteButton().click();
+ $("#delete-link-confirm").click();
+
+ page.getLinks().shouldHaveSize(1);
+ }
+
+ private CreateWsResponse createCustomLink() {
+ return wsClient.projectLinks().create(new CreateWsRequest()
+ .setProjectKey("sample")
+ .setName("Custom")
+ .setUrl("http://example.org/custom"));
+ }
+
+ private void deleteLink(long id) {
+ try {
+ wsClient.projectLinks().delete(new DeleteWsRequest().setId(id));
+ } catch (Exception e) {
+ // fail silently
+ }
+ }
+
+ private ProjectLinksPage openPage() {
+ nav.logIn().submitCredentials("admin", "admin");
+ return nav.openProjectLinks("sample");
+ }
+}
diff --git a/it/it-tests/src/test/java/pageobjects/LoginPage.java b/it/it-tests/src/test/java/pageobjects/LoginPage.java
index bf946b27afa..2aea164f0cb 100644
--- a/it/it-tests/src/test/java/pageobjects/LoginPage.java
+++ b/it/it-tests/src/test/java/pageobjects/LoginPage.java
@@ -37,7 +37,10 @@ public class LoginPage {
}
public LoginPage submitWrongCredentials(String login, String password) {
- return submitCredentials(login, password, LoginPage.class);
+ $("#login").val(login);
+ $("#password").val(password);
+ $(By.name("commit")).click();
+ return page(LoginPage.class);
}
public SelenideElement getErrorMessage() {
@@ -48,6 +51,7 @@ public class LoginPage {
$("#login").val(login);
$("#password").val(password);
$(By.name("commit")).click();
+ $("#login").should(Condition.disappear);
return page(expectedResultPage);
}
}
diff --git a/it/it-tests/src/test/java/pageobjects/Navigation.java b/it/it-tests/src/test/java/pageobjects/Navigation.java
index 395509c5fad..46ee57ca425 100644
--- a/it/it-tests/src/test/java/pageobjects/Navigation.java
+++ b/it/it-tests/src/test/java/pageobjects/Navigation.java
@@ -50,6 +50,12 @@ public class Navigation extends ExternalResource {
return open("/", Navigation.class);
}
+ public ProjectLinksPage openProjectLinks(String projectKey) {
+ // TODO encode projectKey
+ String url = "/project/links?id=" + projectKey;
+ return open(url, ProjectLinksPage.class);
+ }
+
public void open(String relativeUrl) {
Selenide.open(relativeUrl);
}
diff --git a/it/it-tests/src/test/java/pageobjects/ProjectLinkItem.java b/it/it-tests/src/test/java/pageobjects/ProjectLinkItem.java
new file mode 100644
index 00000000000..cf5462009cd
--- /dev/null
+++ b/it/it-tests/src/test/java/pageobjects/ProjectLinkItem.java
@@ -0,0 +1,52 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package pageobjects;
+
+import com.codeborne.selenide.SelenideElement;
+import org.openqa.selenium.NoSuchElementException;
+
+public class ProjectLinkItem {
+
+ private final SelenideElement elt;
+
+ public ProjectLinkItem(SelenideElement elt) {
+ this.elt = elt;
+ }
+
+ public SelenideElement getName() {
+ return elt.$(".js-name");
+ }
+
+ public SelenideElement getType() {
+ try {
+ return elt.$(".js-type");
+ } catch (NoSuchElementException e) {
+ return null;
+ }
+ }
+
+ public SelenideElement getUrl() {
+ return elt.$(".js-url");
+ }
+
+ public SelenideElement getDeleteButton() {
+ return elt.$(".js-delete-button");
+ }
+}
diff --git a/it/it-tests/src/test/java/pageobjects/ProjectLinksPage.java b/it/it-tests/src/test/java/pageobjects/ProjectLinksPage.java
new file mode 100644
index 00000000000..fb143e560b6
--- /dev/null
+++ b/it/it-tests/src/test/java/pageobjects/ProjectLinksPage.java
@@ -0,0 +1,47 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2016 SonarSource SA
+ * mailto:contact AT sonarsource DOT com
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 3 of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+package pageobjects;
+
+import com.codeborne.selenide.Condition;
+import com.codeborne.selenide.ElementsCollection;
+
+import java.util.List;
+import java.util.stream.Collectors;
+
+import static com.codeborne.selenide.Selenide.$;
+import static com.codeborne.selenide.Selenide.$$;
+
+public class ProjectLinksPage {
+
+ public ProjectLinksPage() {
+ $("#project-links").should(Condition.exist);
+ }
+
+ public ElementsCollection getLinks() {
+ return $$("#project-links tr[data-name]");
+ }
+
+ public List<ProjectLinkItem> getLinksAsItems() {
+ return getLinks()
+ .stream()
+ .map(ProjectLinkItem::new)
+ .collect(Collectors.toList());
+ }
+}