From 2aa3df37b9c857da35590e048c49ab5c6050b00d Mon Sep 17 00:00:00 2001 From: simonbrandhof Date: Tue, 2 Nov 2010 18:15:15 +0000 Subject: SONAR-1911 New web service to get server status --- .../java/org/sonar/wsclient/services/Server.java | 30 ++++++++++++++++++++-- .../wsclient/unmarshallers/ServerUnmarshaller.java | 10 ++++++-- .../unmarshallers/ServerUnmarshallerTest.java | 15 +++++++++-- 3 files changed, 49 insertions(+), 6 deletions(-) (limited to 'sonar-ws-client') diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Server.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Server.java index 4919fbb123d..7967a348ce5 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Server.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/services/Server.java @@ -23,8 +23,15 @@ package org.sonar.wsclient.services; * @author Evgeny Mandrikov */ public class Server extends Model { + + public static enum Status { + SETUP, UP, DOWN; + } + private String id; private String version; + private Status status; + private String statusMessage; public String getVersion() { return version; @@ -34,8 +41,8 @@ public class Server extends Model { return id; } - public Server setVersion(String version) { - this.version = version; + public Server setVersion(String s) { + this.version = s; return this; } @@ -43,4 +50,23 @@ public class Server extends Model { this.id = id; return this; } + + public Status getStatus() { + return status; + } + + public String getStatusMessage() { + return statusMessage; + } + + public Server setStatus(Status status) { + this.status = status; + return this; + } + + public Server setStatusMessage(String statusMessage) { + this.statusMessage = statusMessage; + return this; + } + } diff --git a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ServerUnmarshaller.java b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ServerUnmarshaller.java index d980876e3f8..a17a36189d4 100644 --- a/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ServerUnmarshaller.java +++ b/sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ServerUnmarshaller.java @@ -31,9 +31,15 @@ import java.util.List; public class ServerUnmarshaller implements Unmarshaller { public Server toModel(String json) { JSONObject map = (JSONObject) JSONValue.parse(json); - return new Server() + Server server = new Server() .setId(JsonUtils.getString(map, "id")) - .setVersion(JsonUtils.getString(map, "version")); + .setVersion(JsonUtils.getString(map, "version")) + .setStatusMessage(JsonUtils.getString(map, "status_msg")); + String status = JsonUtils.getString(map, "status"); + if (status != null) { + server.setStatus(Server.Status.valueOf(status)); + } + return server; } public List toModels(String json) { diff --git a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ServerUnmarshallerTest.java b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ServerUnmarshallerTest.java index 4db8b113aa9..830996828f4 100644 --- a/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ServerUnmarshallerTest.java +++ b/sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ServerUnmarshallerTest.java @@ -24,16 +24,27 @@ import org.sonar.wsclient.services.Server; import java.io.IOException; +import static org.hamcrest.CoreMatchers.nullValue; import static org.hamcrest.core.Is.is; import static org.junit.Assert.assertThat; public class ServerUnmarshallerTest { @Test - public void toModel() throws IOException { - Server server = new ServerUnmarshaller().toModel("{\"id\":\"123456789\", \"version\":\"2.0-SNAPSHOT\"}"); + public void testToModel() throws IOException { + Server server = new ServerUnmarshaller().toModel("{\"id\":\"123456789\", \"version\":\"2.0-SNAPSHOT\", \"status\":\"UP\", \"status_msg\":\"everything is under control\"}"); assertThat(server.getId(), is("123456789")); assertThat(server.getVersion(), is("2.0-SNAPSHOT")); + assertThat(server.getStatus(), is(Server.Status.UP)); + assertThat(server.getStatusMessage(), is("everything is under control")); } + @Test + public void shouldNotFailIfStatusIsMissing() throws IOException { + Server server = new ServerUnmarshaller().toModel("{\"id\":\"123456789\", \"version\":\"2.0-SNAPSHOT\"}"); + assertThat(server.getId(), is("123456789")); + assertThat(server.getVersion(), is("2.0-SNAPSHOT")); + assertThat(server.getStatus(), nullValue()); + assertThat(server.getStatusMessage(), nullValue()); + } } -- cgit v1.2.3