diff options
author | Julien Lancelot <julien.lancelot@sonarsource.com> | 2016-12-06 16:13:01 +0100 |
---|---|---|
committer | Stas Vilchik <vilchiks@gmail.com> | 2016-12-07 14:36:18 +0100 |
commit | 4c41dd295e14c845f2f0ecdfc38fcf2350fe4d11 (patch) | |
tree | a1a4e43be4a8cc07e0a89c18b9d7fe0267c226f4 /tests | |
parent | f1976a3f56f03c67ccbf6dca7ee5060b6a21a1da (diff) | |
download | sonarqube-4c41dd295e14c845f2f0ecdfc38fcf2350fe4d11.tar.gz sonarqube-4c41dd295e14c845f2f0ecdfc38fcf2350fe4d11.zip |
SONAR-8451 Checking redirection on maintenance is now done with Selenium
As redirections are now done by JS, it's no more possible to check them with HTTP calls, Selenium should be used instead
Diffstat (limited to 'tests')
4 files changed, 78 insertions, 3 deletions
diff --git a/tests/upgrade/pom.xml b/tests/upgrade/pom.xml index b38ed6955c0..6c22dec4c96 100644 --- a/tests/upgrade/pom.xml +++ b/tests/upgrade/pom.xml @@ -54,6 +54,12 @@ <artifactId>assertj-core</artifactId> <scope>test</scope> </dependency> + <dependency> + <groupId>com.codeborne</groupId> + <artifactId>selenide</artifactId> + <version>3.7</version> + <scope>test</scope> + </dependency> </dependencies> <build> diff --git a/tests/upgrade/src/test/java/org/sonarsource/sonarqube/upgrade/MssqlConfig.java b/tests/upgrade/src/test/java/org/sonarsource/sonarqube/upgrade/MssqlConfig.java index 1db2e1ee8b2..7abf5fe50c4 100644 --- a/tests/upgrade/src/test/java/org/sonarsource/sonarqube/upgrade/MssqlConfig.java +++ b/tests/upgrade/src/test/java/org/sonarsource/sonarqube/upgrade/MssqlConfig.java @@ -23,6 +23,8 @@ import com.sonar.orchestrator.config.Configuration; import com.sonar.orchestrator.version.Version; import org.apache.commons.lang.StringUtils; +import static java.util.Objects.requireNonNull; + public class MssqlConfig { /** @@ -31,7 +33,7 @@ public class MssqlConfig { * the MS URL, so it must be changed at runtime for versions < 5.2. */ public static String fixUrl(Configuration conf, Version sqVersion) { - String jdbcUrl = conf.getString("sonar.jdbc.url"); + String jdbcUrl = requireNonNull(conf.getString("sonar.jdbc.url"), "No JDBC url configured"); if (jdbcUrl.startsWith("jdbc:sqlserver:") && !sqVersion.isGreaterThanOrEquals("5.2")) { // Job is configured with the new Microsoft driver, which is not supported by old versions of SQ String host = StringUtils.substringBetween(jdbcUrl, "jdbc:sqlserver://", ";databaseName="); diff --git a/tests/upgrade/src/test/java/org/sonarsource/sonarqube/upgrade/SelenideConfig.java b/tests/upgrade/src/test/java/org/sonarsource/sonarqube/upgrade/SelenideConfig.java new file mode 100644 index 00000000000..1304fa387cb --- /dev/null +++ b/tests/upgrade/src/test/java/org/sonarsource/sonarqube/upgrade/SelenideConfig.java @@ -0,0 +1,49 @@ +/* + * 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 org.sonarsource.sonarqube.upgrade; + +import com.codeborne.selenide.Configuration; +import com.google.common.collect.ImmutableSet; +import java.util.Set; + +import static com.google.common.base.Preconditions.checkArgument; +import static java.util.Objects.requireNonNull; + +enum SelenideConfig { + INSTANCE; + + private static final Set<String> SUPPORTED_BROWSERS = ImmutableSet.of("firefox", "phantomjs"); + + SelenideConfig() { + Configuration.reportsFolder = "target/screenshots"; + } + + public SelenideConfig setBrowser(String browser) { + checkArgument(SUPPORTED_BROWSERS.contains(requireNonNull(browser)), "Browser is not supported: %s", browser); + Configuration.browser = browser; + return this; + } + + public SelenideConfig setBaseUrl(String s) { + Configuration.baseUrl = requireNonNull(s); + return this; + } + +} diff --git a/tests/upgrade/src/test/java/org/sonarsource/sonarqube/upgrade/UpgradeTest.java b/tests/upgrade/src/test/java/org/sonarsource/sonarqube/upgrade/UpgradeTest.java index 84a2c58dee6..da86ece4389 100644 --- a/tests/upgrade/src/test/java/org/sonarsource/sonarqube/upgrade/UpgradeTest.java +++ b/tests/upgrade/src/test/java/org/sonarsource/sonarqube/upgrade/UpgradeTest.java @@ -19,6 +19,8 @@ */ package org.sonarsource.sonarqube.upgrade; +import com.codeborne.selenide.Selenide; +import com.codeborne.selenide.WebDriverRunner; import com.sonar.orchestrator.Orchestrator; import com.sonar.orchestrator.OrchestratorBuilder; import com.sonar.orchestrator.build.MavenBuild; @@ -42,6 +44,8 @@ import org.sonarqube.ws.client.WsClient; import org.sonarqube.ws.client.WsClientFactories; import org.sonarqube.ws.client.WsResponse; +import static com.codeborne.selenide.Condition.hasText; +import static com.codeborne.selenide.Selenide.$; import static org.assertj.core.api.Assertions.assertThat; public class UpgradeTest { @@ -170,6 +174,7 @@ public class UpgradeTest { .setOrchestratorProperty("javaVersion", javaVersion) .addPlugin("java").build(); orchestrator.start(); + initSelenide(orchestrator); } private void startNewServer(String sqVersion, String javaVersion) { @@ -181,6 +186,7 @@ public class UpgradeTest { .addPlugin("java"); orchestrator = builder.build(); orchestrator.start(); + initSelenide(orchestrator); } private void stopServer() { @@ -245,8 +251,7 @@ public class UpgradeTest { } private void checkUrlIsRedirectedToMaintenancePage(String url) { - WsResponse response = newWsClient(orchestrator).wsConnector().call(new GetRequest(url)).failIfNotSuccessful(); - assertThat(response.requestUrl()).contains("/maintenance"); + shouldBeRedirectToMaintenance(url); } private static WsClient newWsClient(Orchestrator orchestrator) { @@ -255,4 +260,17 @@ public class UpgradeTest { .url(server.getUrl()) .build()); } + + private static void initSelenide(Orchestrator orchestrator) { + String browser = orchestrator.getConfiguration().getString("orchestrator.browser", "firefox"); + SelenideConfig.INSTANCE + .setBrowser(browser) + .setBaseUrl(orchestrator.getServer().getUrl()); + WebDriverRunner.getWebDriver().manage().deleteAllCookies(); + } + + private void shouldBeRedirectToMaintenance(String relativeUrl) { + Selenide.open(relativeUrl); + $("#content").should(hasText("SonarQube is under maintenance")); + } } |