use of ddf.catalog.operation.ResourceResponse in project ddf by codice.
the class TestResourceUsagePlugin method getMockResourceResponseNoSubject.
private ResourceResponse getMockResourceResponseNoSubject(String resourceSize) {
ResourceResponse resourceResponse = getMockResourceResponse(resourceSize, null);
when(resourceResponse.getPropertyValue(SecurityConstants.SECURITY_SUBJECT)).thenReturn(null);
return resourceResponse;
}
use of ddf.catalog.operation.ResourceResponse in project ddf by codice.
the class TestCswEndpoint method setUpMocksForProductRetrieval.
private void setUpMocksForProductRetrieval(boolean includeMimeType) throws ResourceNotFoundException, IOException, ResourceNotSupportedException {
ResourceResponse resourceResponse = mock(ResourceResponse.class);
Resource resource = mock(Resource.class);
if (includeMimeType) {
MimeType mimeType = mock(MimeType.class);
when(resource.getMimeType()).thenReturn(mimeType);
}
when(resourceResponse.getResource()).thenReturn(resource);
when(catalogFramework.getLocalResource(any(ResourceRequest.class))).thenReturn(resourceResponse);
}
use of ddf.catalog.operation.ResourceResponse 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>"));
}
use of ddf.catalog.operation.ResourceResponse 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>"));
}
use of ddf.catalog.operation.ResourceResponse in project ddf by codice.
the class TestResourceReader method getMockResourceResponse.
private ResourceResponse getMockResourceResponse(MimeType mimeType) {
Resource mockResource = mock(Resource.class);
when(mockResource.getMimeType()).thenReturn(mimeType);
ResourceResponse mockResourceResponse = mock(ResourceResponse.class);
when(mockResourceResponse.getResource()).thenReturn(mockResource);
return mockResourceResponse;
}
Aggregations