diff options
author | Grégoire Aubert <gregoire.aubert@sonarsource.com> | 2018-02-14 15:57:48 +0100 |
---|---|---|
committer | Guillaume Jambet <guillaume.jambet@gmail.com> | 2018-03-01 15:21:05 +0100 |
commit | bfb8b46ce0f4850775ccab4e2fa13ed83901c842 (patch) | |
tree | e0779b2bf177d0417d3c40ff0b38b7067909cabe | |
parent | bad30545b5ed235f7778c00baedbbe0e41006049 (diff) | |
download | sonarqube-bfb8b46ce0f4850775ccab4e2fa13ed83901c842.tar.gz sonarqube-bfb8b46ce0f4850775ccab4e2fa13ed83901c842.zip |
SONAR-10347 Add IT's for webhook deliveries
4 files changed, 87 insertions, 10 deletions
diff --git a/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/Tester.java b/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/Tester.java index fe1d5d8236e..b97c2638fb3 100644 --- a/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/Tester.java +++ b/server/sonar-qa-util/src/main/java/org/sonarqube/qa/util/Tester.java @@ -114,6 +114,7 @@ public class Tester extends ExternalResource implements TesterSession { projects().deleteAll(); settings().deleteAll(); qGates().deleteAll(); + webhooks().deleteAllGlobal(); } public TesterSession asAnonymous() { 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 index 75260c11e11..bca17a54cb6 100644 --- 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 @@ -21,6 +21,7 @@ package org.sonarqube.qa.util.pageobjects; import com.codeborne.selenide.ElementsCollection; import com.codeborne.selenide.SelenideElement; +import java.util.Arrays; import static com.codeborne.selenide.Condition.cssClass; import static com.codeborne.selenide.Condition.enabled; @@ -46,6 +47,16 @@ public class WebhooksPage { return this; } + public WebhooksPage hasLatestDelivery(String webhookName) { + getWebhook(webhookName).shouldNotHave(text("Never")); + return this; + } + + public WebhooksPage hasNoLatestDelivery(String webhookName) { + getWebhook(webhookName).shouldHave(text("Never")); + return this; + } + public WebhooksPage countWebhooks(Integer number) { getWebhooks().shouldHaveSize(number); return this; @@ -77,6 +88,48 @@ public class WebhooksPage { return this; } + public DeliveriesForm showDeliveries(String webhookName) { + SelenideElement webhook = getWebhook(webhookName); + webhook.$(".dropdown-toggle").shouldBe(visible).click(); + webhook.$(".js-webhook-deliveries").shouldBe(visible).click(); + modalShouldBeOpen("Recent deliveries for " + webhookName); + return new DeliveriesForm($(".modal-body")); + } + + public static class DeliveriesForm { + private final SelenideElement elt; + + public DeliveriesForm(SelenideElement elt) { + this.elt = elt; + } + + public DeliveriesForm countDeliveries(Integer number) { + this.getDeliveries().shouldHaveSize(number); + return this; + } + + public DeliveriesForm isSuccessFull(Integer deliveryIndex) { + this.getDeliveries().get(deliveryIndex).$(".js-success").should(exist); + return this; + } + + public DeliveriesForm payloadContains(Integer deliveryIndex, String... payload) { + SelenideElement delivery = this.getDeliveries().get(deliveryIndex); + SelenideElement header = delivery.$(".boxed-group-header").should(exist); + if (!delivery.$(".boxed-group-inner").exists()) { + header.click(); + } + SelenideElement inner = delivery.$(".boxed-group-inner").shouldBe(visible); + Arrays.stream(payload).forEach(p -> inner.shouldHave(text(p))); + header.click(); + return this; + } + + private ElementsCollection getDeliveries() { + return this.elt.$$(".boxed-group-accordion"); + } + } + private static SelenideElement getWebhook(String webhookName) { return getWebhooks().find(text(webhookName)).should(exist); } diff --git a/tests/src/test/java/org/sonarqube/tests/webhook/WebhooksPageTest.java b/tests/src/test/java/org/sonarqube/tests/webhook/WebhooksPageTest.java index ac3e8ed3318..f206b87ed2b 100644 --- a/tests/src/test/java/org/sonarqube/tests/webhook/WebhooksPageTest.java +++ b/tests/src/test/java/org/sonarqube/tests/webhook/WebhooksPageTest.java @@ -38,13 +38,15 @@ public class WebhooksPageTest @ClassRule public static Orchestrator orchestrator = WebhooksSuite.ORCHESTRATOR; + @ClassRule + public static ExternalServer externalServer = new ExternalServer(); + @Rule public Tester tester = new Tester(orchestrator); @Before - @After - public void reset() { - tester.webhooks().deleteAllGlobal(); + public void setUp() { + externalServer.clear(); } @Test @@ -91,7 +93,8 @@ public class WebhooksPageTest .createWebhook("my-webhook", "http://greg:pass@test.com") .countWebhooks(1) .hasWebhook("my-webhook") - .hasWebhook("http://greg:pass@test.com"); + .hasWebhook("http://greg:pass@test.com") + .hasNoLatestDelivery("my-webhook"); } @Test @@ -131,6 +134,32 @@ public class WebhooksPageTest .countWebhooks(2); } + @Test + public void display_deliveries_payloads() throws InterruptedException { + User user = tester.users().generateAdministratorOnDefaultOrganization(); + tester.wsClient().users().skipOnboardingTutorial(); + + Project project = tester.projects().provision(); + Webhook webhook = tester.webhooks().generate(project, p -> p.setUrl(externalServer.urlFor("/test_deliveries"))); + + analyseProject(project); + analyseProject(project); + + externalServer.waitUntilAllWebHooksCalled(1); + + WebhooksPage webhooksPage = tester.openBrowser().logIn().submitCredentials(user.getLogin()).openProjectWebhooks(project.getKey()); + webhooksPage + .countWebhooks(1) + .hasWebhook(webhook.getUrl()) + .hasLatestDelivery(webhook.getName()); + + WebhooksPage.DeliveriesForm deliveriesForm = webhooksPage.showDeliveries(webhook.getName()); + deliveriesForm + .countDeliveries(2) + .isSuccessFull(0) + .payloadContains(0, "Response: 200", "\"status\": \"SUCCESS\""); + } + private void analyseProject(Project project) { runProjectAnalysis(orchestrator, "shared/xoo-sample", "sonar.projectKey", project.getKey(), diff --git a/tests/src/test/java/org/sonarqube/tests/webhook/WebhooksTest.java b/tests/src/test/java/org/sonarqube/tests/webhook/WebhooksTest.java index ad73ced0d2b..27d83fc1f1f 100644 --- a/tests/src/test/java/org/sonarqube/tests/webhook/WebhooksTest.java +++ b/tests/src/test/java/org/sonarqube/tests/webhook/WebhooksTest.java @@ -60,12 +60,6 @@ public class WebhooksTest { externalServer.clear(); } - @Before - @After - public void reset() { - tester.webhooks().deleteAllGlobal(); - } - @Test public void call_multiple_global_and_project_webhooks_when_analysis_is_done() throws InterruptedException { Project project = tester.projects().provision(); |