use of javax.ws.rs.core.UriInfo in project ddf by codice.
the class MetricsEndpointTest method testGetMetricsGraphWithMetricsGraphException.
// NOTE: "expected" annotation does not work when test case extends XMLTestCase,
// hence the usage of the try/catch/fail approach for the expected exception
@Test
public // (expected = MetricsEndpointException.class)
void testGetMetricsGraphWithMetricsGraphException() throws Exception {
UriInfo uriInfo = createUriInfo();
RrdMetricsRetriever metricsRetriever = mock(RrdMetricsRetriever.class);
when(metricsRetriever.createGraph(anyString(), anyString(), anyLong(), anyLong(), anyString(), anyString())).thenThrow(MetricsGraphException.class);
MetricsEndpoint endpoint = getEndpoint();
endpoint.setMetricsDir(TEST_DIR);
endpoint.setMetricsRetriever(metricsRetriever);
try {
endpoint.getMetricsData("uptime", "png", "2013-03-25T06:00:00-07:00", "2013-03-25T07:10:00-07:00", null, "my label", "my title", uriInfo);
fail();
} catch (MetricsEndpointException e) {
}
}
use of javax.ws.rs.core.UriInfo in project ddf by codice.
the class MetricsEndpointTest method testGetMetricsDataAsXml.
@Test
public void testGetMetricsDataAsXml() throws Exception {
// Create RRD file that Metrics Endpoint will detect
// 15 minutes in seconds
int dateOffset = 900;
createRrdFile(dateOffset);
UriInfo uriInfo = createUriInfo();
// Get the metrics data from the endpoint
MetricsEndpoint endpoint = getEndpoint();
endpoint.setMetricsDir(TEST_DIR);
Response response = endpoint.getMetricsData("uptime", "xml", null, null, Integer.toString(dateOffset), "my label", "my title", uriInfo);
cleanupRrd();
String xml = (String) response.getEntity();
LOGGER.debug("xml = {}", xml);
// Requires XmlUnit, but when this class extends XMLTestCase causes test case
// testGetMetricsGraphWithDateOffsetAndDates to fail (exception is thrown but
// unit test does not see it)
assertXpathExists("/uptime", xml);
assertXpathExists("/uptime/title", xml);
assertXpathExists("/uptime/data", xml);
assertXpathExists("/uptime/data/sample", xml);
assertXpathExists("/uptime/data/sample/timestamp", xml);
assertXpathExists("/uptime/data/sample/value", xml);
assertXpathExists("/uptime/data/totalCount", xml);
}
use of javax.ws.rs.core.UriInfo in project ddf by codice.
the class MetricsEndpointTest method verifyException.
private void verifyException(String format, Class exceptionClass) throws Exception {
UriInfo uriInfo = createUriInfo();
RrdMetricsRetriever metricsRetriever = mock(RrdMetricsRetriever.class);
when(metricsRetriever.createJsonData(anyString(), anyString(), anyLong(), anyLong())).thenThrow(exceptionClass);
when(metricsRetriever.createCsvData(anyString(), anyLong(), anyLong())).thenThrow(exceptionClass);
when(metricsRetriever.createXlsData(anyString(), anyString(), anyLong(), anyLong())).thenThrow(exceptionClass);
when(metricsRetriever.createXmlData(anyString(), anyString(), anyLong(), anyLong())).thenThrow(exceptionClass);
// Get the metrics data from the endpoint
MetricsEndpoint endpoint = getEndpoint();
endpoint.setMetricsDir(TEST_DIR);
endpoint.setMetricsRetriever(metricsRetriever);
try {
Response response = endpoint.getMetricsData("uptime", format, null, null, "900", "my label", "my title", uriInfo);
fail();
} catch (MetricsEndpointException e) {
}
}
use of javax.ws.rs.core.UriInfo in project ddf by codice.
the class MetricsEndpointTest method createUriInfo.
protected UriInfo createUriInfo() throws URISyntaxException {
UriInfo info = mock(UriInfo.class);
when(info.getBaseUri()).thenReturn(new URI(ENDPOINT_ADDRESS));
when(info.getRequestUri()).thenReturn(new URI(ENDPOINT_ADDRESS));
when(info.getAbsolutePath()).thenReturn(new URI(ENDPOINT_ADDRESS));
UriBuilder builder = mock(UriBuilder.class);
when(info.getAbsolutePathBuilder()).thenReturn(builder);
when(builder.path("/uptime.png")).thenReturn(builder);
when(builder.build()).thenReturn(new URI(ENDPOINT_ADDRESS + "/uptime.png"));
return info;
}
use of javax.ws.rs.core.UriInfo in project ddf by codice.
the class MetricsEndpointTest method testGetMetricsGraphWithDateOffsetAndDates.
// NOTE: "expected" annotation does not work when test case extends XMLTestCase,
// hence the usage of the try/catch/fail approach for the expected exception
@Test
public // (expected = MetricsEndpointException.class)
void testGetMetricsGraphWithDateOffsetAndDates() throws Exception {
UriInfo uriInfo = createUriInfo();
MetricsEndpoint endpoint = getEndpoint();
endpoint.setMetricsDir(TEST_DIR);
try {
endpoint.getMetricsData("uptime", "png", "2013-03-25T06:00:00-07:00", "2013-03-25T07:10:00-07:00", "3600", "my label", "my title", uriInfo);
fail();
} catch (MetricsEndpointException e) {
}
}
Aggregations