]> source.dussan.org Git - sonarqube.git/commitdiff
SONAR-10344 Create IT's for webhooks console page
authorGrégoire Aubert <gregoire.aubert@sonarsource.com>
Fri, 2 Feb 2018 15:29:10 +0000 (16:29 +0100)
committerGuillaume Jambet <guillaume.jambet@gmail.com>
Thu, 1 Mar 2018 14:21:05 +0000 (15:21 +0100)
cix.sh
server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/Navigation.java
server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/WebhooksPage.java [new file with mode: 0644]
tests/src/test/java/org/sonarqube/tests/Category3Suite.java
tests/src/test/java/org/sonarqube/tests/webhook/WebhooksSuite.java [new file with mode: 0644]
tests/src/test/java/org/sonarqube/tests/webhook/WebhooksTest.java

diff --git a/cix.sh b/cix.sh
index 715a27db7c9380d970bcf01ee14ecc8dfbacbf57..a6d4f3a2491d82e00eea299bc0481fa4d11d43a5 100755 (executable)
--- a/cix.sh
+++ b/cix.sh
@@ -43,7 +43,7 @@ case "$RUN_ACTIVITY" in
           ;;
 
         Category4)
-          CATEGORY="Category4|duplication|user"
+          CATEGORY="Category4|duplication|user|webhook"
           ;;
 
         Category5)
index ede43929a06bba06ad81e941a91f980d199581a8..073df461b8ba1e390598b4cdb902551305489e65 100644 (file)
@@ -202,6 +202,18 @@ public class Navigation {
     return open("/organizations/" + orgKey + "/projects_management", ProjectsManagementPage.class);
   }
 
+  public WebhooksPage openWebhooks() {
+    return open("/admin/webhooks", WebhooksPage.class);
+  }
+
+  public WebhooksPage openOrganizationWebhooks(String orgKey) {
+    return open("/organizations/" + orgKey + "/webhooks", WebhooksPage.class);
+  }
+
+  public WebhooksPage openProjectWebhooks(String projectKey) {
+    return open("/project/webhooks?id="+ projectKey, WebhooksPage.class);
+  }
+
   public LoginPage openLogin() {
     return open("/sessions/login", LoginPage.class);
   }
diff --git a/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/WebhooksPage.java b/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/pageobjects/WebhooksPage.java
new file mode 100644 (file)
index 0000000..af6c8c6
--- /dev/null
@@ -0,0 +1,48 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 SonarSource SA
+ * mailto:info 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 org.sonarqube.qa.util.pageobjects;
+
+import com.codeborne.selenide.ElementsCollection;
+
+import static com.codeborne.selenide.Condition.exist;
+import static com.codeborne.selenide.Condition.text;
+import static com.codeborne.selenide.Selenide.$;
+import static com.codeborne.selenide.Selenide.$$;
+
+public class WebhooksPage {
+
+  public WebhooksPage() {
+    $(".page-header .page-title").should(exist).shouldHave(text("Webhooks"));
+  }
+
+  public WebhooksPage hasWebhook(String text) {
+    getWebhooks().find(text(text)).should(exist);
+    return this;
+  }
+
+  public WebhooksPage countWebhooks(Integer number) {
+    getWebhooks().shouldHaveSize(number);
+    return this;
+  }
+
+  private static ElementsCollection getWebhooks() {
+    return $$(".boxed-group tbody tr");
+  }
+}
index 60fbc385ab8cabfcbdd33321f96990cd075a11c5..2924b41373f9da9b439f64ee8ec55a6b4b1cdc13 100644 (file)
@@ -65,8 +65,7 @@ import static util.ItUtils.xooPlugin;
   ReportDumpTest.class,
   SSLTest.class,
   FavoriteTest.class,
-  RedirectTest.class,
-  WebhooksTest.class
+  RedirectTest.class
 })
 public class Category3Suite {
 
diff --git a/tests/src/test/java/org/sonarqube/tests/webhook/WebhooksSuite.java b/tests/src/test/java/org/sonarqube/tests/webhook/WebhooksSuite.java
new file mode 100644 (file)
index 0000000..261c88f
--- /dev/null
@@ -0,0 +1,43 @@
+/*
+ * SonarQube
+ * Copyright (C) 2009-2018 SonarSource SA
+ * mailto:info 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 org.sonarqube.tests.webhook;
+
+import com.sonar.orchestrator.Orchestrator;
+import org.junit.ClassRule;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+
+import static util.ItUtils.xooPlugin;
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses({
+  WebhooksTest.class
+})
+public class WebhooksSuite {
+
+  @ClassRule
+  public static final Orchestrator ORCHESTRATOR = Orchestrator.builderEnv()
+    .addPlugin(xooPlugin())
+
+    // reduce memory for Elasticsearch
+    .setServerProperty("sonar.search.javaOpts", "-Xms128m -Xmx128m")
+
+    .build();
+}
index 0bbed5291359f35b56991f6f38add531c1bd80f8..2531d8674b1077d7e70aa335f95f10ef0ce44d59 100644 (file)
@@ -33,12 +33,14 @@ import org.junit.ClassRule;
 import org.junit.Rule;
 import org.junit.Test;
 import org.sonarqube.qa.util.Tester;
-import org.sonarqube.tests.Category3Suite;
+import org.sonarqube.qa.util.pageobjects.WebhooksPage;
 import org.sonarqube.ws.Issues.Issue;
 import org.sonarqube.ws.Organizations.Organization;
 import org.sonarqube.ws.Projects.CreateWsResponse.Project;
 import org.sonarqube.ws.Qualitygates;
 import org.sonarqube.ws.Qualityprofiles.CreateWsResponse.QualityProfile;
+import org.sonarqube.ws.Users;
+import org.sonarqube.ws.Users.CreateWsResponse.User;
 import org.sonarqube.ws.Webhooks;
 import org.sonarqube.ws.client.HttpException;
 import org.sonarqube.ws.client.WsClient;
@@ -67,7 +69,7 @@ public class WebhooksTest {
   private static final String PROJECT_WEBHOOK_PROPERTY = "sonar.webhooks.project";
 
   @ClassRule
-  public static Orchestrator orchestrator = Category3Suite.ORCHESTRATOR;
+  public static Orchestrator orchestrator = WebhooksSuite.ORCHESTRATOR;
   @ClassRule
   public static ExternalServer externalServer = new ExternalServer();
 
@@ -287,6 +289,28 @@ public class WebhooksTest {
     assertThat(gate.get("status")).isEqualTo("OK");
   }
 
+  @Test
+  public void list_global_webhooks() {
+    enableGlobalWebhooks(new Webhook("foo", "http://foo.bar"), new Webhook("bar", "https://bar.baz/test"));
+    tester.wsClient().users().skipOnboardingTutorial();
+    WebhooksPage webhooksPage = tester.openBrowser().logIn().submitCredentials("admin").openWebhooks();
+    webhooksPage
+      .countWebhooks(2)
+      .hasWebhook("http://foo.bar");
+  }
+
+  @Test
+  public void list_project_webhooks() {
+    analyseProject();
+    enableProjectWebhooks(PROJECT_KEY, new Webhook("foo", "http://foo.bar"), new Webhook("bar", "https://bar.baz/test"));
+    User user = tester.users().generateAdministratorOnDefaultOrganization();
+    tester.wsClient().users().skipOnboardingTutorial();
+    WebhooksPage webhooksPage = tester.openBrowser().logIn().submitCredentials(user.getLogin()).openProjectWebhooks(PROJECT_KEY);
+    webhooksPage
+      .countWebhooks(2)
+      .hasWebhook("http://foo.bar");
+  }
+
   private void analyseProject() {
     runProjectAnalysis(orchestrator, "shared/xoo-sample",
       "sonar.projectKey", PROJECT_KEY,