Search in sources :

Example 41 with UriInfo

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.
}
Also used : Response(javax.ws.rs.core.Response) UriInfo(javax.ws.rs.core.UriInfo) Test(org.junit.Test)

Example 42 with UriInfo

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()));
}
Also used : Response(javax.ws.rs.core.Response) UriInfo(javax.ws.rs.core.UriInfo) Test(org.junit.Test)

Example 43 with UriInfo

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()));
}
Also used : Response(javax.ws.rs.core.Response) InputStream(java.io.InputStream) HSSFRow(org.apache.poi.hssf.usermodel.HSSFRow) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) UriInfo(javax.ws.rs.core.UriInfo) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Test(org.junit.Test)

Example 44 with UriInfo

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()));
}
Also used : Response(javax.ws.rs.core.Response) InputStream(java.io.InputStream) JSONObject(org.json.simple.JSONObject) HSSFSheet(org.apache.poi.hssf.usermodel.HSSFSheet) Matchers.anyString(org.mockito.Matchers.anyString) UriInfo(javax.ws.rs.core.UriInfo) HSSFWorkbook(org.apache.poi.hssf.usermodel.HSSFWorkbook) Test(org.junit.Test)

Example 45 with UriInfo

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) {
    }
}
Also used : RrdMetricsRetriever(ddf.metrics.reporting.internal.rrd4j.RrdMetricsRetriever) MetricsEndpointException(ddf.metrics.reporting.internal.MetricsEndpointException) UriInfo(javax.ws.rs.core.UriInfo) Test(org.junit.Test)

Aggregations

UriInfo (javax.ws.rs.core.UriInfo)105 Response (javax.ws.rs.core.Response)50 Test (org.junit.Test)49 URI (java.net.URI)32 Test (org.testng.annotations.Test)21 Map (java.util.Map)15 MediaType (javax.ws.rs.core.MediaType)15 HttpServletRequest (javax.servlet.http.HttpServletRequest)12 GET (javax.ws.rs.GET)12 Path (javax.ws.rs.Path)12 Context (javax.ws.rs.core.Context)12 Request (org.apache.atlas.catalog.Request)12 ResourceProvider (org.apache.atlas.catalog.ResourceProvider)12 TaxonomyResourceProvider (org.apache.atlas.catalog.TaxonomyResourceProvider)12 MetadataService (org.apache.atlas.services.MetadataService)12 AtlasTypeDefStore (org.apache.atlas.store.AtlasTypeDefStore)12 PathParam (javax.ws.rs.PathParam)11 ArrayList (java.util.ArrayList)10 Api (io.swagger.annotations.Api)8 ApiOperation (io.swagger.annotations.ApiOperation)8