use of javax.ws.rs.core.UriInfo in project ddf by codice.
the class MetricsEndpointTest method testGetMetricsGraphPositiveCase.
@Test
public void testGetMetricsGraphPositiveCase() 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 graph from the endpoint
MetricsEndpoint endpoint = getEndpoint();
endpoint.setMetricsDir(TEST_DIR);
Response response = endpoint.getMetricsData("uptime", "png", "2013-03-25T06:00:00-07:00", "2013-03-25T07:10:00-07:00", null, "my label", "my title", uriInfo);
cleanupRrd();
assertThat(response.getEntity(), not(nullValue()));
// NOTE: There are other branches in MetricsEndpoint that could/should be tested, e.g.,
// when startDate specified and no endDate is specified (which is valid) - unfortunately,
// RRD provides no methods to get info on the graph other than the byte[] it returns.
// Hence, only could verify that a non null graph is returned. These tests seem not
// to be worth writing at this time.
}
use of javax.ws.rs.core.UriInfo in project ddf by codice.
the class MetricsEndpointTest method testGetMetricsGraphPositiveCaseWithDefaults.
@Test
public void testGetMetricsGraphPositiveCaseWithDefaults() 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 graph from the endpoint
MetricsEndpoint endpoint = getEndpoint();
endpoint.setMetricsDir(TEST_DIR);
Response response = endpoint.getMetricsData("uptime", "png", null, null, null, null, null, uriInfo);
cleanupRrd();
assertThat(response.getEntity(), not(nullValue()));
}
use of javax.ws.rs.core.UriInfo in project ddf by codice.
the class MetricsEndpointTest method testGetMetricsDataAsXls.
@Test
public void testGetMetricsDataAsXls() 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", "xls", null, null, Integer.toString(dateOffset), "my label", "my title", uriInfo);
cleanupRrd();
InputStream xls = (InputStream) response.getEntity();
assertThat(xls, not(nullValue()));
HSSFWorkbook wb = new HSSFWorkbook(xls);
assertThat(wb.getNumberOfSheets(), equalTo(1));
HSSFSheet sheet = wb.getSheet("Uptime");
assertThat(sheet, not(nullValue()));
// Expect 7 rows: title + blank + column headers + 2 rows of samples + blank +
// totalQueryCount
assertThat(sheet.getPhysicalNumberOfRows(), equalTo(7));
// first row should have title in first cell
HSSFRow row = sheet.getRow(0);
assertThat(row, not(nullValue()));
assertThat(row.getCell(0).getStringCellValue(), startsWith("Uptime for"));
// third row should have column headers in first and second cells
row = sheet.getRow(2);
assertThat(row.getCell(0).getStringCellValue(), equalTo("Timestamp"));
assertThat(row.getCell(1).getStringCellValue(), equalTo("Value"));
// should have 2 rows of samples' data
row = sheet.getRow(3);
assertThat(row.getCell(0).getStringCellValue(), not(nullValue()));
assertThat(row.getCell(1).getNumericCellValue(), not(nullValue()));
row = sheet.getRow(4);
assertThat(row.getCell(0).getStringCellValue(), not(nullValue()));
assertThat(row.getCell(1).getNumericCellValue(), not(nullValue()));
// last row should have totalQueryCount in first cell
row = sheet.getRow(sheet.getLastRowNum());
assertThat(row.getCell(0).getStringCellValue(), startsWith("Total Count:"));
assertThat(row.getCell(1).getNumericCellValue(), not(nullValue()));
}
use of javax.ws.rs.core.UriInfo in project ddf by codice.
the class MetricsEndpointTest method testGetMetricsReportAsXls.
@Test
public void testGetMetricsReportAsXls() throws Exception {
// Create RRD file that Metrics Endpoint will detect
// 15 minutes in seconds
int dateOffset = 900;
createRrdFile(dateOffset, "uptime");
UriInfo uriInfo = createUriInfo();
// Get the metrics data from the endpoint
MetricsEndpoint endpoint = getEndpoint();
endpoint.setMetricsDir(TEST_DIR);
Response response = endpoint.getMetricsReport("xls", null, null, Integer.toString(dateOffset), "minute", uriInfo);
cleanupRrd();
MultivaluedMap<String, Object> headers = response.getHeaders();
assertTrue(headers.getFirst("Content-Disposition").toString().contains("attachment; filename="));
InputStream is = (InputStream) response.getEntity();
assertThat(is, not(nullValue()));
HSSFWorkbook wb = new HSSFWorkbook(is);
assertThat(wb.getNumberOfSheets(), equalTo(1));
HSSFSheet sheet = wb.getSheetAt(0);
assertThat(sheet, not(nullValue()));
}
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) {
}
}
Aggregations