aboutsummaryrefslogtreecommitdiffstats
path: root/sonar-ws-client
diff options
context:
space:
mode:
authorsimonbrandhof <simon.brandhof@gmail.com>2010-11-02 18:15:15 +0000
committersimonbrandhof <simon.brandhof@gmail.com>2010-11-02 18:15:15 +0000
commit2aa3df37b9c857da35590e048c49ab5c6050b00d (patch)
treea30dd743d0846b73b82a7755c2589d0c07d86f4c /sonar-ws-client
parentd97d0f40e1b7e4390dc6c637e1ae63f3ce533369 (diff)
downloadsonarqube-2aa3df37b9c857da35590e048c49ab5c6050b00d.tar.gz
sonarqube-2aa3df37b9c857da35590e048c49ab5c6050b00d.zip
SONAR-1911 New web service to get server status
Diffstat (limited to 'sonar-ws-client')
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/services/Server.java30
-rw-r--r--sonar-ws-client/src/main/java/org/sonar/wsclient/unmarshallers/ServerUnmarshaller.java10
-rw-r--r--sonar-ws-client/src/test/java/org/sonar/wsclient/unmarshallers/ServerUnmarshallerTest.java15
3 files changed, 49 insertions, 6 deletions
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<Server> {
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<Server> 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());
+ }
}