Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
unit and integration tested info resource, resolves #135
  • Loading branch information
ddossot committed Nov 9, 2011
1 parent 3118472 commit 07592c8
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 2 deletions.
22 changes: 21 additions & 1 deletion src/it/java/eu/openanalytics/rsb/RestMiscITCase.java
Expand Up @@ -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);
Expand Down
Expand Up @@ -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 })
Expand Down
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -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;

/**
Expand All @@ -64,11 +67,30 @@ public void prepareTest() throws URISyntaxException {
when(configuration.getDefaultRserviPoolUri()).thenReturn(defaultPoolUri);
}

@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));
Expand Down

0 comments on commit 07592c8

Please sign in to comment.