aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Brandhof <simon.brandhof@sonarsource.com>2015-02-24 11:18:39 +0100
committerSimon Brandhof <simon.brandhof@sonarsource.com>2015-02-24 11:18:39 +0100
commit5ac06f760d8d80d5073074e7a11e780d9663f47b (patch)
tree03afc73a42f7fbbfde6803d4cbc72a36d1824a31
parent2877ce0c94684aa5aeb37df18e584111a12f254b (diff)
downloadsonarqube-5ac06f760d8d80d5073074e7a11e780d9663f47b.tar.gz
sonarqube-5ac06f760d8d80d5073074e7a11e780d9663f47b.zip
Add missing test
-rw-r--r--server/sonar-server/src/main/java/org/sonar/server/platform/ws/SystemInfoWsAction.java4
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/platform/ws/SystemInfoWsActionTest.java51
-rw-r--r--server/sonar-server/src/test/java/org/sonar/server/ws/WsTester.java4
3 files changed, 32 insertions, 27 deletions
diff --git a/server/sonar-server/src/main/java/org/sonar/server/platform/ws/SystemInfoWsAction.java b/server/sonar-server/src/main/java/org/sonar/server/platform/ws/SystemInfoWsAction.java
index 2bf05694553..136340c696c 100644
--- a/server/sonar-server/src/main/java/org/sonar/server/platform/ws/SystemInfoWsAction.java
+++ b/server/sonar-server/src/main/java/org/sonar/server/platform/ws/SystemInfoWsAction.java
@@ -67,8 +67,4 @@ public class SystemInfoWsAction implements SystemWsAction {
}
json.endObject();
}
-
- Monitor[] getMonitors() {
- return monitors;
- }
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/platform/ws/SystemInfoWsActionTest.java b/server/sonar-server/src/test/java/org/sonar/server/platform/ws/SystemInfoWsActionTest.java
index f42f3dc09c8..eeaeaa8dc38 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/platform/ws/SystemInfoWsActionTest.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/platform/ws/SystemInfoWsActionTest.java
@@ -20,38 +20,30 @@
package org.sonar.server.platform.ws;
-import org.apache.commons.lang.StringUtils;
-import org.assertj.core.api.Condition;
-import org.junit.ClassRule;
import org.junit.Test;
import org.sonar.api.server.ws.Request;
import org.sonar.api.server.ws.Response;
+import org.sonar.api.server.ws.internal.SimpleGetRequest;
import org.sonar.core.permission.GlobalPermissions;
import org.sonar.server.exceptions.ForbiddenException;
import org.sonar.server.platform.monitoring.Monitor;
-import org.sonar.server.tester.ServerTester;
import org.sonar.server.user.MockUserSession;
+import org.sonar.server.ws.WsTester;
+
+import java.util.LinkedHashMap;
import static org.assertj.core.api.Assertions.assertThat;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
public class SystemInfoWsActionTest {
- @ClassRule
- public static ServerTester serverTester = new ServerTester();
-
- private SystemInfoWsAction sut;
-
- @Test
- public void all_monitors_have_a_name() throws Exception {
- sut = serverTester.get(SystemInfoWsAction.class);
-
- assertThat(sut.getMonitors()).areNot(withEmptyName());
- }
+ Monitor monitor1 = mock(Monitor.class);
+ Monitor monitor2 = mock(Monitor.class);
+ SystemInfoWsAction sut = new SystemInfoWsAction(monitor1, monitor2);
@Test(expected = ForbiddenException.class)
public void should_fail_when_does_not_have_admin_right() throws Exception {
- sut = serverTester.get(SystemInfoWsAction.class);
MockUserSession.set()
.setLogin("login")
.setName("name")
@@ -60,12 +52,25 @@ public class SystemInfoWsActionTest {
sut.handle(mock(Request.class), mock(Response.class));
}
- private Condition<Monitor> withEmptyName() {
- return new Condition<Monitor>() {
- @Override
- public boolean matches(Monitor m) {
- return StringUtils.isEmpty(m.name());
- }
- };
+ @Test
+ public void write_json() throws Exception {
+ MockUserSession.set()
+ .setLogin("login")
+ .setName("name")
+ .setGlobalPermissions(GlobalPermissions.SYSTEM_ADMIN);
+
+ LinkedHashMap<String, Object> attributes1 = new LinkedHashMap<>();
+ attributes1.put("foo", "bar");
+ LinkedHashMap<String, Object> attributes2 = new LinkedHashMap<>();
+ attributes2.put("one", 1);
+ attributes2.put("two", 2);
+ when(monitor1.name()).thenReturn("Monitor One");
+ when(monitor1.attributes()).thenReturn(attributes1);
+ when(monitor2.name()).thenReturn("Monitor Two");
+ when(monitor2.attributes()).thenReturn(attributes2);
+
+ WsTester.TestResponse response = new WsTester.TestResponse();
+ sut.handle(new SimpleGetRequest(), response);
+ assertThat(response.outputAsString()).isEqualTo("{\"Monitor One\":{\"foo\":\"bar\"},\"Monitor Two\":{\"one\":1,\"two\":2}}");
}
}
diff --git a/server/sonar-server/src/test/java/org/sonar/server/ws/WsTester.java b/server/sonar-server/src/test/java/org/sonar/server/ws/WsTester.java
index ac0347c9efd..8325cf15c7a 100644
--- a/server/sonar-server/src/test/java/org/sonar/server/ws/WsTester.java
+++ b/server/sonar-server/src/test/java/org/sonar/server/ws/WsTester.java
@@ -159,6 +159,10 @@ public class WsTester {
IOUtils.closeQuietly(output);
return this;
}
+
+ public String outputAsString() {
+ return new String(output.toByteArray(), Charsets.UTF_8);
+ }
}
public static class Result {