diff options
author | Simon Brandhof <simon.brandhof@sonarsource.com> | 2017-08-28 22:47:50 +0200 |
---|---|---|
committer | Sébastien Lesaint <sebastien.lesaint@sonarsource.com> | 2017-09-13 15:50:48 +0200 |
commit | 5b9d6018431f09d090b71fa3179a9d9bed5dc0ab (patch) | |
tree | e46067ff924f4a700434bc05db7ca9709337d6b6 /tests | |
parent | af99398a59677d6a1d8d94fbf3529327ac891ef2 (diff) | |
download | sonarqube-5b9d6018431f09d090b71fa3179a9d9bed5dc0ab.tar.gz sonarqube-5b9d6018431f09d090b71fa3179a9d9bed5dc0ab.zip |
SONAR-9739 add protobuf response to WS api/system/status
Diffstat (limited to 'tests')
4 files changed, 18 insertions, 37 deletions
diff --git a/tests/src/test/java/org/sonarqube/tests/serverSystem/RestartTest.java b/tests/src/test/java/org/sonarqube/tests/serverSystem/RestartTest.java index ee69d37febb..eac784ff61e 100644 --- a/tests/src/test/java/org/sonarqube/tests/serverSystem/RestartTest.java +++ b/tests/src/test/java/org/sonarqube/tests/serverSystem/RestartTest.java @@ -29,10 +29,9 @@ import org.junit.rules.DisableOnDebug; import org.junit.rules.ExpectedException; import org.junit.rules.TestRule; import org.junit.rules.Timeout; -import org.sonarqube.ws.client.GetRequest; +import org.sonarqube.ws.WsSystem; import org.sonarqube.ws.client.PostRequest; import org.sonarqube.ws.client.WsClient; -import org.sonarqube.ws.client.WsResponse; import org.sonarqube.ws.client.permission.AddUserWsRequest; import util.ItUtils; @@ -76,8 +75,7 @@ public class RestartTest { createSystemAdministrator("big", "boss"); ItUtils.newUserWsClient(orchestrator, "big", "boss").system().restart(); - WsResponse wsResponse = newAdminWsClient(orchestrator).wsConnector().call(new GetRequest("/api/system/status")).failIfNotSuccessful(); - assertThat(wsResponse.content()).contains("RESTARTING"); + assertThat(newAdminWsClient(orchestrator).system().status().getStatus()).isEqualTo(WsSystem.Status.RESTARTING); // we just wait five seconds, for a lack of a better approach to waiting for the restart process to start in SQ Thread.sleep(5000); diff --git a/tests/src/test/java/org/sonarqube/tests/serverSystem/ServerSystemRestartingOrchestrator.java b/tests/src/test/java/org/sonarqube/tests/serverSystem/ServerSystemRestartingOrchestrator.java index 02e7887b6cf..cd4e2c1ac78 100644 --- a/tests/src/test/java/org/sonarqube/tests/serverSystem/ServerSystemRestartingOrchestrator.java +++ b/tests/src/test/java/org/sonarqube/tests/serverSystem/ServerSystemRestartingOrchestrator.java @@ -22,19 +22,17 @@ package org.sonarqube.tests.serverSystem; import com.sonar.orchestrator.Orchestrator; import com.sonar.orchestrator.locator.FileLocation; import java.io.File; -import java.util.Map; import org.apache.commons.io.FileUtils; import org.junit.After; import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; -import org.sonarqube.ws.client.GetRequest; -import org.sonarqube.ws.client.WsResponse; +import org.sonarqube.ws.WsSystem; import util.ItUtils; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.Assert.fail; -import static util.ItUtils.newWsClient; +import static util.ItUtils.newAdminWsClient; /** * This class start a new orchestrator on each test case @@ -79,9 +77,7 @@ public class ServerSystemRestartingOrchestrator { .build(); orchestrator.start(); - WsResponse statusResponse = newWsClient(orchestrator).wsConnector().call(new GetRequest("api/system/status")); - Map<String, Object> json = ItUtils.jsonToMap(statusResponse.content()); - assertThat(json.get("status")).isEqualTo("UP"); + assertThat(newAdminWsClient(orchestrator).system().status().getStatus()).isEqualTo(WsSystem.Status.UP); } // SONAR-4748 diff --git a/tests/src/test/java/org/sonarqube/tests/serverSystem/ServerSystemTest.java b/tests/src/test/java/org/sonarqube/tests/serverSystem/ServerSystemTest.java index 5be7753116e..ac888b10998 100644 --- a/tests/src/test/java/org/sonarqube/tests/serverSystem/ServerSystemTest.java +++ b/tests/src/test/java/org/sonarqube/tests/serverSystem/ServerSystemTest.java @@ -36,8 +36,8 @@ import org.sonarqube.tests.Category4Suite; import org.sonarqube.tests.Tester; import org.sonarqube.ws.MediaTypes; import org.sonarqube.ws.ServerId.ShowWsResponse; +import org.sonarqube.ws.WsSystem; import org.sonarqube.ws.client.GetRequest; -import org.sonarqube.ws.client.WsResponse; import util.ItUtils; import static org.apache.commons.lang.StringUtils.startsWithAny; @@ -62,10 +62,10 @@ public class ServerSystemTest { @Test public void get_sonarqube_version() { - Map<String, Object> json = callStatus(); + WsSystem.StatusResponse response = tester.wsClient().system().status(); - String version = (String) json.get("version"); - if (!startsWithAny(version, new String[]{"6."})) { + String version = response.getVersion(); + if (!startsWithAny(version, new String[]{"6.", "7.", "8."})) { fail("Bad version: " + version); } } @@ -96,11 +96,6 @@ public class ServerSystemTest { assertThat(serverId).isNotEmpty(); } - private Map<String, Object> callStatus() { - WsResponse statusResponse = tester.wsClient().wsConnector().call(new GetRequest("api/system/status")); - return ItUtils.jsonToMap(statusResponse.content()); - } - /** * See http://jira.codehaus.org/browse/SONAR-2727 */ diff --git a/tests/src/test/java/org/sonarqube/tests/serverSystem/SystemStateTest.java b/tests/src/test/java/org/sonarqube/tests/serverSystem/SystemStateTest.java index 9559380e2b6..e942a432e96 100644 --- a/tests/src/test/java/org/sonarqube/tests/serverSystem/SystemStateTest.java +++ b/tests/src/test/java/org/sonarqube/tests/serverSystem/SystemStateTest.java @@ -24,7 +24,6 @@ import com.sonar.orchestrator.util.NetworkUtils; import java.io.File; import java.io.IOException; import java.net.InetAddress; -import java.util.Map; import java.util.Optional; import java.util.function.Supplier; import org.apache.commons.io.FileUtils; @@ -36,10 +35,7 @@ import org.junit.rules.TestRule; import org.junit.rules.Timeout; import org.sonarqube.tests.Elasticsearch; import org.sonarqube.ws.WsSystem; -import org.sonarqube.ws.client.GetRequest; import org.sonarqube.ws.client.WsClient; -import org.sonarqube.ws.client.WsResponse; -import util.ItUtils; import static com.google.common.base.Preconditions.checkState; import static org.assertj.core.api.Assertions.assertThat; @@ -64,17 +60,17 @@ public class SystemStateTest { commander.start(lock); commander.waitFor(() -> commander.webLogsContain("ServerStartupLock - Waiting for file to be deleted")); - commander.verifyStatus("STARTING"); + commander.verifyStatus(WsSystem.Status.STARTING); commander.verifyHealth(WsSystem.Health.RED, "SonarQube webserver is not up"); lock.unlockWeb(); // status is UP as soon as web server is up, whatever the status of Compute Engine - commander.waitFor(() -> "UP".equals(commander.status().orElse(null))); + commander.waitFor(() -> WsSystem.Status.UP == commander.status().orElse(null)); commander.verifyHealth(WsSystem.Health.RED, "Compute Engine is not operational"); lock.unlockCe(); commander.waitForHealth(WsSystem.Health.GREEN); - commander.verifyStatus("UP"); + commander.verifyStatus(WsSystem.Status.UP); } } @@ -86,12 +82,12 @@ public class SystemStateTest { commander.makeElasticsearchYellow(); commander.waitForHealth(WsSystem.Health.YELLOW, "Elasticsearch status is YELLOW"); - commander.verifyStatus("UP"); + commander.verifyStatus(WsSystem.Status.UP); commander.makeElasticsearchGreen(); commander.waitForHealth(WsSystem.Health.GREEN); // status does not change after being UP - commander.verifyStatus("UP"); + commander.verifyStatus(WsSystem.Status.UP); } } @@ -165,15 +161,11 @@ public class SystemStateTest { } } - Optional<String> status() { + Optional<WsSystem.Status> status() { if (orchestrator.getServer() != null) { WsClient wsClient = newWsClient(orchestrator); try { - WsResponse statusResponse = wsClient.wsConnector().call(new GetRequest("api/system/status")); - if (statusResponse.isSuccessful()) { - Map<String, Object> json = ItUtils.jsonToMap(statusResponse.content()); - return Optional.ofNullable((String) json.get("status")); - } + return Optional.of(wsClient.system().status().getStatus()); } catch (Exception e) { // server does not accept connections } @@ -181,7 +173,7 @@ public class SystemStateTest { return Optional.empty(); } - void verifyStatus(String expectedStatus) { + void verifyStatus(WsSystem.Status expectedStatus) { assertThat(status()).hasValue(expectedStatus); } @@ -209,7 +201,7 @@ public class SystemStateTest { void verifyHealth(WsSystem.Health expectedHealth, String... expectedMessages) { WsSystem.HealthResponse response = healthResponse().get(); - assertThat(response.getHealth()).isEqualTo(expectedHealth); + assertThat(response.getHealth()).isEqualTo(expectedHealth); assertThat(response.getCausesList()) .extracting(WsSystem.Cause::getMessage) .containsExactlyInAnyOrder(expectedMessages); |