Search in sources :

Example 61 with ResourceResponse

use of ddf.catalog.operation.ResourceResponse 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 62 with ResourceResponse

use of ddf.catalog.operation.ResourceResponse 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)

Example 63 with ResourceResponse

use of ddf.catalog.operation.ResourceResponse in project ddf by codice.

the class ResourceReaderTest method testServerDoesNotSupportPartialContent.

/**
     * Tests that if the server does not support range-header requests and responds with the entire
     * product's contents (no Content-Range header and a 200 response), an input is still returned
     * with the requested byte offset.
     * @throws Exception
     */
@Test
public void testServerDoesNotSupportPartialContent() throws Exception {
    URI uri = new URI(HTTP_SCHEME_PLUS_SEP + HOST + TEST_PATH + BAD_FILE_NAME);
    Response mockResponse = mock(Response.class);
    when(mockWebClient.get()).thenReturn(mockResponse);
    MultivaluedMap<String, Object> map = new MultivaluedHashMap<>();
    map.put(HttpHeaders.CONTENT_DISPOSITION, Arrays.asList("inline; filename=\"" + JPEG_FILE_NAME_1 + "\""));
    when(mockResponse.getHeaders()).thenReturn(map);
    when(mockResponse.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
    when(mockResponse.getEntity()).thenReturn(getBinaryData());
    String bytesToSkip = "2";
    ResourceResponse response = verifyFileFromURLResourceReader(uri, JPEG_FILE_NAME_1, JPEG_MIME_TYPE, bytesToSkip);
    // verify that the requested bytes 3-5 were returned
    assertEquals(3, response.getResource().getByteArray().length);
}
Also used : Response(javax.ws.rs.core.Response) ResourceResponse(ddf.catalog.operation.ResourceResponse) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) ResourceResponse(ddf.catalog.operation.ResourceResponse) Matchers.containsString(org.hamcrest.Matchers.containsString) URI(java.net.URI) Test(org.junit.Test)

Example 64 with ResourceResponse

use of ddf.catalog.operation.ResourceResponse in project alliance by codice.

the class CatalogOutputAdapterTest method testGetImageNullResource.

@Test(expected = IllegalArgumentException.class)
public void testGetImageNullResource() throws IOException {
    ResourceResponse resourceResponse = mock(ResourceResponse.class);
    when(resourceResponse.getResource()).thenReturn(null);
    catalogOutputAdapter.getImage(resourceResponse);
}
Also used : ResourceResponse(ddf.catalog.operation.ResourceResponse) Test(org.junit.Test)

Example 65 with ResourceResponse

use of ddf.catalog.operation.ResourceResponse in project alliance by codice.

the class CatalogOutputAdapterTest method testGetImage.

@Test
public void testGetImage() throws IOException {
    InputStream is = getInputStream(I_3001A);
    ResourceResponse resourceResponse = mock(ResourceResponse.class);
    Resource resource = mock(Resource.class);
    when(resourceResponse.getResource()).thenReturn(resource);
    when(resource.getInputStream()).thenReturn(is);
    BufferedImage image = catalogOutputAdapter.getImage(resourceResponse);
    assertThat(image, is(notNullValue()));
    assertThat(image.getWidth(), is(1024));
    assertThat(image.getHeight(), is(1024));
}
Also used : ResourceResponse(ddf.catalog.operation.ResourceResponse) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Resource(ddf.catalog.resource.Resource) BufferedImage(java.awt.image.BufferedImage) Test(org.junit.Test)

Aggregations

ResourceResponse (ddf.catalog.operation.ResourceResponse)94 Test (org.junit.Test)49 URI (java.net.URI)30 HashMap (java.util.HashMap)28 Serializable (java.io.Serializable)26 Resource (ddf.catalog.resource.Resource)25 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)23 ResourceRequest (ddf.catalog.operation.ResourceRequest)18 IOException (java.io.IOException)18 ResourceNotFoundException (ddf.catalog.resource.ResourceNotFoundException)17 Metacard (ddf.catalog.data.Metacard)16 MimeType (javax.activation.MimeType)16 Response (javax.ws.rs.core.Response)15 ResourceNotSupportedException (ddf.catalog.resource.ResourceNotSupportedException)14 URLResourceReader (ddf.catalog.resource.impl.URLResourceReader)14 ResourceRequestById (ddf.catalog.operation.impl.ResourceRequestById)10 InputStream (java.io.InputStream)9 Map (java.util.Map)9 ResourceResponseImpl (ddf.catalog.operation.impl.ResourceResponseImpl)8 StringWriter (java.io.StringWriter)8