Search in sources :

Example 6 with URLResourceReader

use of ddf.catalog.resource.impl.URLResourceReader in project ddf by codice.

the class TestResourceReader method testRetrieveResourceMimeTypeTextHtml.

/**
     * Tests the case in which the Resource in the ResourceResponse returned by the
     * URLResourceReader has a text/html mime type.
     */
@Test
public void testRetrieveResourceMimeTypeTextHtml() throws Exception {
    // Setup
    String httpUriStr = HTTP_SCHEME_PLUS_SEP + MOCK_HTTP_SERVER_HOST + ":" + MOCK_HTTP_SERVER_PORT + MOCK_HTTP_SERVER_PATH;
    URI uri = new URI(httpUriStr);
    Response mockResponse = getMockResponse();
    setupMockWebClient(mockResponse);
    ResourceResponse mockResourceResponse = getMockResourceResponse(new MimeType("application/octet-stream"));
    URLResourceReader mockUrlResourceReader = getMockUrlResourceReader(uri, mockResourceResponse);
    setupMockTika(MediaType.TEXT_HTML);
    OgcUrlResourceReader resourceReader = new OgcUrlResourceReader(mockUrlResourceReader, mockTika);
    HashMap<String, Serializable> arguments = new HashMap<String, Serializable>();
    // Perform Test
    ResourceResponse resourceResponse = resourceReader.retrieveResource(uri, arguments);
    // Verify
    StringWriter writer = new StringWriter();
    IOUtils.copy(resourceResponse.getResource().getInputStream(), writer, MOCK_HTTP_SERVER_ENCODING);
    String responseString = writer.toString();
    LOGGER.info("Response {}", responseString);
    assertThat(responseString, is("<html><script type=\"text/javascript\">window.location.replace(\"" + httpUriStr + "\");</script></html>"));
}
Also used : ResourceResponse(ddf.catalog.operation.ResourceResponse) Response(javax.ws.rs.core.Response) Serializable(java.io.Serializable) ResourceResponse(ddf.catalog.operation.ResourceResponse) URLResourceReader(ddf.catalog.resource.impl.URLResourceReader) StringWriter(java.io.StringWriter) HashMap(java.util.HashMap) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) URI(java.net.URI) MimeType(javax.activation.MimeType) Test(org.junit.Test)

Example 7 with URLResourceReader

use of ddf.catalog.resource.impl.URLResourceReader in project ddf by codice.

the class TestResourceReader method testRetrieveResourceApplicationUnknownResourceMimeType.

/**
     * Tests the case in which the Resource in the ResourceResponse returned by the
     * URLResourceReader has an application/unknown mime type.
     */
@Test
public void testRetrieveResourceApplicationUnknownResourceMimeType() throws Exception {
    // Setup
    String httpUriStr = HTTP_SCHEME_PLUS_SEP + MOCK_HTTP_SERVER_HOST + ":" + MOCK_HTTP_SERVER_PORT + MOCK_HTTP_SERVER_PATH;
    URI uri = new URI(httpUriStr);
    Response mockResponse = getMockResponse();
    setupMockWebClient(mockResponse);
    ResourceResponse mockResourceResponse = getMockResourceResponse(new MimeType("application/octet-stream"));
    URLResourceReader mockUrlResourceReader = getMockUrlResourceReader(uri, mockResourceResponse);
    setupMockTika(MediaType.TEXT_HTML);
    OgcUrlResourceReader resourceReader = new OgcUrlResourceReader(mockUrlResourceReader, mockTika);
    HashMap<String, Serializable> arguments = new HashMap<String, Serializable>();
    // Perform Test
    ResourceResponse resourceResponse = resourceReader.retrieveResource(uri, arguments);
    // Verify
    StringWriter writer = new StringWriter();
    IOUtils.copy(resourceResponse.getResource().getInputStream(), writer, MOCK_HTTP_SERVER_ENCODING);
    String responseString = writer.toString();
    LOGGER.info("Response {}", responseString);
    assertThat(responseString, is("<html><script type=\"text/javascript\">window.location.replace(\"" + httpUriStr + "\");</script></html>"));
}
Also used : ResourceResponse(ddf.catalog.operation.ResourceResponse) Response(javax.ws.rs.core.Response) Serializable(java.io.Serializable) ResourceResponse(ddf.catalog.operation.ResourceResponse) URLResourceReader(ddf.catalog.resource.impl.URLResourceReader) StringWriter(java.io.StringWriter) HashMap(java.util.HashMap) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) URI(java.net.URI) MimeType(javax.activation.MimeType) Test(org.junit.Test)

Example 8 with URLResourceReader

use of ddf.catalog.resource.impl.URLResourceReader in project ddf by codice.

the class TestResourceReader method testRetrieveResourceNullResourceMimeType.

/**
     * Tests the case in which the Resource in the ResourceResponse returned by the
     * URLResourceReader has a null mime type.
     */
@Test
public void testRetrieveResourceNullResourceMimeType() throws Exception {
    // Setup
    String httpUriStr = HTTP_SCHEME_PLUS_SEP + MOCK_HTTP_SERVER_HOST + ":" + MOCK_HTTP_SERVER_PORT + MOCK_HTTP_SERVER_PATH;
    URI uri = new URI(httpUriStr);
    Response mockResponse = getMockResponse();
    setupMockWebClient(mockResponse);
    ResourceResponse mockResourceResponse = getMockResourceResponse(null);
    URLResourceReader mockUrlResourceReader = getMockUrlResourceReader(uri, mockResourceResponse);
    setupMockTika(MediaType.TEXT_HTML);
    when(mockUrlResourceReader.retrieveResource(eq(uri), any(Map.class))).thenReturn(mockResourceResponse);
    OgcUrlResourceReader resourceReader = new OgcUrlResourceReader(mockUrlResourceReader, mockTika);
    HashMap<String, Serializable> arguments = new HashMap<String, Serializable>();
    // Perform Test
    ResourceResponse resourceResponse = resourceReader.retrieveResource(uri, arguments);
    // Verify
    assertThat(resourceResponse, is(mockResourceResponse));
}
Also used : ResourceResponse(ddf.catalog.operation.ResourceResponse) Response(javax.ws.rs.core.Response) Serializable(java.io.Serializable) ResourceResponse(ddf.catalog.operation.ResourceResponse) URLResourceReader(ddf.catalog.resource.impl.URLResourceReader) HashMap(java.util.HashMap) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) URI(java.net.URI) HashMap(java.util.HashMap) Map(java.util.Map) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) Test(org.junit.Test)

Example 9 with URLResourceReader

use of ddf.catalog.resource.impl.URLResourceReader in project ddf by codice.

the class TestResourceReader method testRetrieveResourceApplicationOctetStreamResourceMimeType.

/**
     * Tests the case in which the Resource in the ResourceResponse returned by the
     * URLResourceReader has an application/octet-stream mime type.
     */
@Test
public void testRetrieveResourceApplicationOctetStreamResourceMimeType() throws Exception {
    // Setup
    String httpUriStr = HTTP_SCHEME_PLUS_SEP + MOCK_HTTP_SERVER_HOST + ":" + MOCK_HTTP_SERVER_PORT + MOCK_HTTP_SERVER_PATH;
    URI uri = new URI(httpUriStr);
    Response mockResponse = getMockResponse();
    setupMockWebClient(mockResponse);
    ResourceResponse mockResourceResponse = getMockResourceResponse(new MimeType("application/octet-stream"));
    URLResourceReader mockUrlResourceReader = getMockUrlResourceReader(uri, mockResourceResponse);
    setupMockTika(MediaType.TEXT_HTML);
    OgcUrlResourceReader resourceReader = new OgcUrlResourceReader(mockUrlResourceReader, mockTika);
    HashMap<String, Serializable> arguments = new HashMap<String, Serializable>();
    // Perform Test
    ResourceResponse resourceResponse = resourceReader.retrieveResource(uri, arguments);
    // Verify
    StringWriter writer = new StringWriter();
    IOUtils.copy(resourceResponse.getResource().getInputStream(), writer, MOCK_HTTP_SERVER_ENCODING);
    String responseString = writer.toString();
    LOGGER.info("Response {}", responseString);
    assertThat(responseString, is("<html><script type=\"text/javascript\">window.location.replace(\"" + httpUriStr + "\");</script></html>"));
}
Also used : ResourceResponse(ddf.catalog.operation.ResourceResponse) Response(javax.ws.rs.core.Response) Serializable(java.io.Serializable) ResourceResponse(ddf.catalog.operation.ResourceResponse) URLResourceReader(ddf.catalog.resource.impl.URLResourceReader) StringWriter(java.io.StringWriter) HashMap(java.util.HashMap) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) URI(java.net.URI) MimeType(javax.activation.MimeType) Test(org.junit.Test)

Aggregations

URLResourceReader (ddf.catalog.resource.impl.URLResourceReader)9 HashMap (java.util.HashMap)9 Serializable (java.io.Serializable)8 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)8 Test (org.junit.Test)8 ResourceResponse (ddf.catalog.operation.ResourceResponse)7 URI (java.net.URI)7 Response (javax.ws.rs.core.Response)5 StringWriter (java.io.StringWriter)4 MimeType (javax.activation.MimeType)4 Map (java.util.Map)3 MultivaluedMap (javax.ws.rs.core.MultivaluedMap)3 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)1 ResourceRequest (ddf.catalog.operation.ResourceRequest)1 ResourceReader (ddf.catalog.resource.ResourceReader)1 LocalResourceRetriever (ddf.catalog.resourceretriever.LocalResourceRetriever)1 File (java.io.File)1