Permalink
Browse files

unit and integration tested info resource, resolves #135

  • Loading branch information...
1 parent 3118472 commit 07592c8d210e2f950de77534dcdeaae3add0e5e5 @ddossot ddossot committed Nov 9, 2011
@@ -36,7 +36,27 @@
*/
public class RestMiscITCase extends AbstractITCase {
@Test
- public void healthCheck() throws Exception {
+ public void systemInfo() throws Exception {
+ final WebConversation wc = new WebConversation();
+ final WebRequest request = new GetMethodWebRequest(RSB_BASE_URI + "/api/rest/system/info");
+ final WebResponse response = wc.sendRequest(request);
+ assertEquals(200, response.getResponseCode());
+ assertEquals("application/vnd.rsb+xml", response.getHeaderField("Content-Type"));
+
+ final String xml = response.getText();
+ assertXpathExists("/rsb:nodeInformation", xml);
+ assertXpathExists("/rsb:nodeInformation/@name", xml);
+ assertXpathExists("/rsb:nodeInformation/@healthy", xml);
+ assertXpathExists("/rsb:nodeInformation/@uptime", xml);
+ assertXpathExists("/rsb:nodeInformation/@uptimeText", xml);
+ assertXpathExists("/rsb:nodeInformation/@servletContainerInfo", xml);
+ assertXpathExists("/rsb:nodeInformation/@jvmMaxMemory", xml);
+ assertXpathExists("/rsb:nodeInformation/@jvmFreeMemory", xml);
+ assertXpathExists("/rsb:nodeInformation/@osLoadAverage", xml);
+ }
+
+ @Test
+ public void systemHealthCheck() throws Exception {
final WebConversation wc = new WebConversation();
final WebRequest request = new GetMethodWebRequest(RSB_BASE_URI + "/api/rest/system/health/check");
final WebResponse response = wc.sendRequest(request);
@@ -81,7 +81,6 @@ public Response check() {
return nodeHealthy.get() ? Response.ok("OK").build() : Response.status(Status.INTERNAL_SERVER_ERROR).entity("ERROR").build();
}
- // FIXME unit test, integration test
@GET
@Path("/info")
@Produces({ Constants.RSB_XML_CONTENT_TYPE, Constants.RSB_JSON_CONTENT_TYPE })
@@ -21,6 +21,7 @@
package eu.openanalytics.rsb.component;
import static org.hamcrest.CoreMatchers.is;
+import static org.hamcrest.CoreMatchers.notNullValue;
import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.anyString;
import static org.mockito.Mockito.mock;
@@ -29,6 +30,7 @@
import java.net.URI;
import java.net.URISyntaxException;
+import javax.servlet.ServletContext;
import javax.ws.rs.core.Response;
import org.junit.Before;
@@ -39,6 +41,7 @@
import de.walware.rj.servi.RServi;
import eu.openanalytics.rsb.config.Configuration;
+import eu.openanalytics.rsb.rest.types.NodeInformation;
import eu.openanalytics.rsb.rservi.RServiInstanceProvider;
/**
@@ -65,10 +68,29 @@ public void prepareTest() throws URISyntaxException {
}
@Test
+ public void getInfo() throws Exception {
+ final NodeInformation info = systemHealthResource.getInfo(mock(ServletContext.class));
+
+ assertThat(info, is(notNullValue()));
+ }
+
+ @Test
+ public void defaultCheck() throws Exception {
+ final RServi rServi = mock(RServi.class);
+ when(rServiInstanceProvider.getRServiInstance(anyString(), anyString())).thenReturn(rServi);
+
+ final Response checkResult = systemHealthResource.check();
+
+ assertThat(checkResult.getStatus(), is(200));
+ assertThat(checkResult.getEntity().toString(), is("OK"));
+ }
+
+ @Test
public void happyCheck() throws Exception {
final RServi rServi = mock(RServi.class);
when(rServiInstanceProvider.getRServiInstance(anyString(), anyString())).thenReturn(rServi);
+ systemHealthResource.verifyNodeHealth();
final Response checkResult = systemHealthResource.check();
assertThat(checkResult.getStatus(), is(200));

0 comments on commit 07592c8

Please sign in to comment.