Search in sources :

Example 91 with UriInfo

use of javax.ws.rs.core.UriInfo in project ddf by codice.

the class TestRestEndpoint method createSpecificUriInfo.

/**
     * Creates a UriInfo with a user specified URL
     *
     * @param url
     * @return
     * @throws URISyntaxException
     */
protected UriInfo createSpecificUriInfo(String url) throws URISyntaxException {
    UriInfo uriInfo = mock(UriInfo.class);
    URI uri = new URI(url);
    when(uriInfo.getAbsolutePath()).thenReturn(uri);
    when(uriInfo.getQueryParameters()).thenReturn(mock(MultivaluedMap.class));
    return uriInfo;
}
Also used : MultivaluedMap(javax.ws.rs.core.MultivaluedMap) URI(java.net.URI) UriInfo(javax.ws.rs.core.UriInfo)

Example 92 with UriInfo

use of javax.ws.rs.core.UriInfo in project ddf by codice.

the class TestRestEndpoint method executeTest.

private Response executeTest(CatalogFramework framework, String transformer, boolean local, HttpServletRequest request) throws URISyntaxException {
    RESTEndpoint restEndpoint = new RESTEndpoint(framework);
    restEndpoint.setTikaMimeTypeResolver(new TikaMimeTypeResolver());
    FilterBuilder filterBuilder = new GeotoolsFilterBuilder();
    restEndpoint.setFilterBuilder(filterBuilder);
    UriInfo uriInfo;
    Response response;
    if (local) {
        uriInfo = createSpecificUriInfo(LOCAL_RETRIEVE_ADDRESS);
        response = restEndpoint.getDocument(GET_ID, transformer, uriInfo, request);
    } else {
        uriInfo = createSpecificUriInfo(FED_RETRIEVE_ADDRESS);
        response = restEndpoint.getDocument(GET_SITENAME, GET_ID, transformer, uriInfo, request);
    }
    return response;
}
Also used : QueryResponse(ddf.catalog.operation.QueryResponse) Response(javax.ws.rs.core.Response) SourceInfoResponse(ddf.catalog.operation.SourceInfoResponse) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) FilterBuilder(ddf.catalog.filter.FilterBuilder) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) TikaMimeTypeResolver(ddf.mime.tika.TikaMimeTypeResolver) UriInfo(javax.ws.rs.core.UriInfo)

Example 93 with UriInfo

use of javax.ws.rs.core.UriInfo in project ddf by codice.

the class TestRestEndpoint method headTest.

private Response headTest(boolean local) throws CatalogTransformerException, URISyntaxException, UnsupportedEncodingException, UnsupportedQueryException, SourceUnavailableException, FederationException, IngestException {
    MetacardImpl metacard = null;
    List<Result> list = new ArrayList<Result>();
    Result result = mock(Result.class);
    InputStream inputStream = null;
    UriInfo uriInfo;
    Response response;
    CatalogFramework framework = givenCatalogFramework(SAMPLE_ID);
    list.add(result);
    QueryResponse queryResponse = mock(QueryResponse.class);
    when(queryResponse.getResults()).thenReturn(list);
    when(framework.query(isA(QueryRequest.class), isNull(FederationStrategy.class))).thenReturn(queryResponse);
    metacard = new MetacardImpl();
    metacard.setSourceId(GET_SITENAME);
    when(result.getMetacard()).thenReturn(metacard);
    Resource resource = mock(Resource.class);
    inputStream = new ByteArrayInputStream(GET_STREAM.getBytes(GET_OUTPUT_TYPE));
    when(resource.getInputStream()).thenReturn(inputStream);
    when(resource.getMimeTypeValue()).thenReturn(GET_MIME_TYPE);
    when(resource.getName()).thenReturn(GET_FILENAME);
    when(framework.transform(isA(Metacard.class), anyString(), isA(Map.class))).thenReturn(resource);
    RESTEndpoint restEndpoint = new RESTEndpoint(framework);
    restEndpoint.setTikaMimeTypeResolver(new TikaMimeTypeResolver());
    FilterBuilder filterBuilder = new GeotoolsFilterBuilder();
    restEndpoint.setFilterBuilder(filterBuilder);
    uriInfo = createSpecificUriInfo(LOCAL_RETRIEVE_ADDRESS);
    if (local) {
        response = restEndpoint.getHeaders(GET_ID, uriInfo, null);
    } else {
        response = restEndpoint.getHeaders(null, GET_ID, uriInfo, null);
    }
    return response;
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) FederationStrategy(ddf.catalog.federation.FederationStrategy) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) Resource(ddf.catalog.resource.Resource) TikaMimeTypeResolver(ddf.mime.tika.TikaMimeTypeResolver) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) QueryResponse(ddf.catalog.operation.QueryResponse) Response(javax.ws.rs.core.Response) SourceInfoResponse(ddf.catalog.operation.SourceInfoResponse) Metacard(ddf.catalog.data.Metacard) ByteArrayInputStream(java.io.ByteArrayInputStream) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) FilterBuilder(ddf.catalog.filter.FilterBuilder) QueryResponse(ddf.catalog.operation.QueryResponse) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) CatalogFramework(ddf.catalog.CatalogFramework) Map(java.util.Map) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) UriInfo(javax.ws.rs.core.UriInfo)

Example 94 with UriInfo

use of javax.ws.rs.core.UriInfo in project ddf by codice.

the class AuthenticationEndpointTest method setup.

@Before
public void setup() throws SecurityServiceException, URISyntaxException {
    HttpSessionFactory sessionFactory = mock(HttpSessionFactory.class);
    HttpSession session = mock(HttpSession.class);
    when(session.getAttribute(SecurityConstants.SAML_ASSERTION)).thenReturn(mock(SecurityTokenHolder.class));
    when(sessionFactory.getOrCreateSession(any())).thenReturn(session);
    policyManager = mock(ContextPolicyManager.class);
    securityManager = mock(SecurityManager.class);
    authEndpoint = new AuthenticationEndpoint(policyManager, securityManager, sessionFactory);
    UriInfo uriInfo = mock(UriInfo.class);
    UriBuilder uriBuilder = mock(UriBuilder.class);
    when(uriInfo.getBaseUriBuilder()).thenReturn(uriBuilder);
    when(uriBuilder.replacePath(anyString())).thenReturn(uriBuilder);
    when(uriBuilder.build()).thenReturn(new URI(URL));
    authEndpoint.uriInfo = uriInfo;
    mockUser(USER_NAME, PASSWORD, REALM);
}
Also used : SecurityTokenHolder(ddf.security.common.SecurityTokenHolder) SecurityManager(ddf.security.service.SecurityManager) HttpSession(javax.servlet.http.HttpSession) HttpSessionFactory(ddf.security.http.impl.HttpSessionFactory) UriBuilder(javax.ws.rs.core.UriBuilder) URI(java.net.URI) UriInfo(javax.ws.rs.core.UriInfo) ContextPolicyManager(org.codice.ddf.security.policy.context.ContextPolicyManager) Before(org.junit.Before)

Example 95 with UriInfo

use of javax.ws.rs.core.UriInfo in project ddf by codice.

the class MetricsEndpointTest method testGetMetricsList.

@SuppressWarnings("rawtypes")
@Test
public // @Ignore
void testGetMetricsList() throws Exception {
    // Delete all .rrd files in test directory to ensure starting with clean directory
    File testDir = new File(TEST_DIR);
    File[] fileList = testDir.listFiles();
    if (fileList != null) {
        for (File file : fileList) {
            if (file.isFile()) {
                file.delete();
            }
        }
    }
    // Create RRD file that Metrics Endpoint will detect
    rrdPath = TEST_DIR + "uptime.rrd";
    RrdDef def = new RrdDef(rrdPath, 1);
    def.addDatasource("uptime", DsType.COUNTER, 90, 0, Double.NaN);
    def.addArchive(ConsolFun.TOTAL, 0.5, 1, 60);
    rrdDb = RrdDbPool.getInstance().requestRrdDb(def);
    UriInfo uriInfo = createUriInfo();
    // Get the metrics list from the endpoint
    MetricsEndpoint endpoint = getEndpoint();
    endpoint.setMetricsDir(TEST_DIR);
    Response response = endpoint.getMetricsList(uriInfo);
    String metricsList = (String) response.getEntity();
    LOGGER.debug("metricsList = {}", metricsList);
    cleanupRrd();
    // Useful class for simple JSON to handle collections when parsing
    // (Called internally by the simple JSON parser.parse(...) method)
    ContainerFactory containerFactory = new ContainerFactory() {

        public List creatArrayContainer() {
            return new LinkedList();
        }

        public Map createObjectContainer() {
            return new LinkedHashMap();
        }
    };
    // Parse the returned JSON text
    JSONParser parser = new JSONParser();
    Map json = (Map) parser.parse(metricsList, containerFactory);
    Set<String> metricNames = (Set<String>) json.keySet();
    assertThat(metricNames.size(), equalTo(1));
    assertThat(metricNames, hasItem("uptime"));
    Iterator metricsIter = json.entrySet().iterator();
    // http://<host>:<port>/services/internal/metrics?dateOffset=3600
    while (metricsIter.hasNext()) {
        Map.Entry entry = (Map.Entry) metricsIter.next();
        Map metricTimeRangeLinks = (Map) entry.getValue();
        LOGGER.debug("metricTimeRangeLinks = {}", metricTimeRangeLinks);
        // Verify each metric name, e.g., "uptime", has all of the time ranges represented
        assertThat(metricTimeRangeLinks.containsKey("15m"), is(true));
        assertThat(metricTimeRangeLinks.containsKey("1h"), is(true));
        // assertThat(metricTimeRangeLinks.containsKey("4h"), is(true));
        // assertThat(metricTimeRangeLinks.containsKey("12h"), is(true));
        assertThat(metricTimeRangeLinks.containsKey("1d"), is(true));
        // assertThat(metricTimeRangeLinks.containsKey("3d"), is(true));
        assertThat(metricTimeRangeLinks.containsKey("1w"), is(true));
        assertThat(metricTimeRangeLinks.containsKey("1M"), is(true));
        assertThat(metricTimeRangeLinks.containsKey("3M"), is(true));
        assertThat(metricTimeRangeLinks.containsKey("6M"), is(true));
        assertThat(metricTimeRangeLinks.containsKey("1y"), is(true));
        Iterator timeRangeLinksIter = metricTimeRangeLinks.entrySet().iterator();
        // supported formats and that the correct dateOffset is specified in the hyperlinks
        while (timeRangeLinksIter.hasNext()) {
            Map.Entry timeRangeLinkEntry = (Map.Entry) timeRangeLinksIter.next();
            String timeRange = (String) timeRangeLinkEntry.getKey();
            Map<String, String> metricHyperlinks = (Map<String, String>) timeRangeLinkEntry.getValue();
            Long dateOffset = MetricsEndpoint.TIME_RANGES.get(timeRange);
            assertThat(metricHyperlinks.containsKey("PNG"), is(true));
            assertThat(metricHyperlinks.get("PNG"), endsWith("dateOffset=" + dateOffset));
            assertThat(metricHyperlinks.containsKey("CSV"), is(true));
            assertThat(metricHyperlinks.get("CSV"), endsWith("dateOffset=" + dateOffset));
            assertThat(metricHyperlinks.containsKey("XLS"), is(true));
            assertThat(metricHyperlinks.get("XLS"), endsWith("dateOffset=" + dateOffset));
        }
    }
}
Also used : RrdDef(org.rrd4j.core.RrdDef) Set(java.util.Set) Matchers.anyString(org.mockito.Matchers.anyString) LinkedList(java.util.LinkedList) LinkedHashMap(java.util.LinkedHashMap) Response(javax.ws.rs.core.Response) Iterator(java.util.Iterator) Matchers.anyLong(org.mockito.Matchers.anyLong) ContainerFactory(org.json.simple.parser.ContainerFactory) JSONParser(org.json.simple.parser.JSONParser) File(java.io.File) Map(java.util.Map) LinkedHashMap(java.util.LinkedHashMap) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) 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