Search in sources :

Example 46 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)

Example 47 with UriInfo

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

Example 48 with UriInfo

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

Example 49 with UriInfo

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;
}
Also used : UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) UriInfo(javax.ws.rs.core.UriInfo)

Example 50 with UriInfo

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

Aggregations

UriInfo (javax.ws.rs.core.UriInfo)86 Response (javax.ws.rs.core.Response)44 Test (org.junit.Test)43 URI (java.net.URI)31 Test (org.testng.annotations.Test)21 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 HttpServletRequest (javax.servlet.http.HttpServletRequest)11 ArrayList (java.util.ArrayList)10 Map (java.util.Map)10 MediaType (javax.ws.rs.core.MediaType)10 Api (io.swagger.annotations.Api)8 ApiOperation (io.swagger.annotations.ApiOperation)8 ApiParam (io.swagger.annotations.ApiParam)8 ApiResponse (io.swagger.annotations.ApiResponse)8 ApiResponses (io.swagger.annotations.ApiResponses)8 InputStream (java.io.InputStream)8