use of ddf.catalog.resource.impl.URLResourceReader in project ddf by codice.
the class TestResourceReader method testRetrieveResourceCantDetectMimeType.
/**
* Tests the case in which the Resource in the ResourceResponse returned by the
* URLResourceReader has a null mime type and tika can't detect the mime type.
*/
@Test
public void testRetrieveResourceCantDetectMimeType() 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);
ResourceResponse mockResourceResponse = getMockResourceResponse(null);
URLResourceReader mockUrlResourceReader = getMockUrlResourceReader(uri, mockResourceResponse);
setupMockTika(null);
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));
}
use of ddf.catalog.resource.impl.URLResourceReader in project ddf by codice.
the class TestResourceReader method testRetrieveResourceTextHtmlDetectedByTika.
@Test
public void testRetrieveResourceTextHtmlDetectedByTika() throws Exception {
// Setup
Response mockResponse = getMockResponse();
setupMockWebClient(mockResponse);
setupMockTika(MediaType.TEXT_HTML);
URLResourceReader urlResourceReader = new URLResourceReader(null) {
@Override
protected WebClient getWebClient(String uri, Map<String, Serializable> properties) {
return mockWebClient;
}
};
OgcUrlResourceReader resourceReader = new OgcUrlResourceReader(urlResourceReader, mockTika);
String httpUriStr = HTTP_SCHEME_PLUS_SEP + MOCK_HTTP_SERVER_HOST + ":" + MOCK_HTTP_SERVER_PORT + MOCK_HTTP_SERVER_PATH;
URI uri = new URI(httpUriStr);
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.resource.impl.URLResourceReader in project ddf by codice.
the class TestResourceReader method testRetrieveResourceOriginalUrlResourceReaderResponseReturned.
/**
* Tests the case in which the mime type of the Resource in the ResourceResponse returned by the
* URLResourceReader is not text/html, application/unknown or application/octet-stream. The original
* response from the URLResourceReader is returned.
*/
@Test
public void testRetrieveResourceOriginalUrlResourceReaderResponseReturned() 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);
ResourceResponse mockResourceResponse = getMockResourceResponse(new MimeType("image/jpeg"));
URLResourceReader mockUrlResourceReader = getMockUrlResourceReader(uri, mockResourceResponse);
setupMockTika(null);
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));
}
use of ddf.catalog.resource.impl.URLResourceReader in project ddf by codice.
the class TestResourceReader method getMockUrlResourceReader.
private URLResourceReader getMockUrlResourceReader(URI uri, ResourceResponse resourceResponse) throws Exception {
URLResourceReader mockUrlResourceReader = mock(URLResourceReader.class);
when(mockUrlResourceReader.retrieveResource(eq(uri), any(Map.class))).thenReturn(resourceResponse);
return mockUrlResourceReader;
}
use of ddf.catalog.resource.impl.URLResourceReader in project ddf by codice.
the class DownloadsStatusEventListenerTest method testGetDownloadStatus.
@Test
public void testGetDownloadStatus() throws URISyntaxException, DownloadException, InterruptedException {
File downloadFile = new File(System.getProperty("user.dir") + "/src/test/resources/125bytes.txt");
MetacardImpl testMetacard = new MetacardImpl();
testMetacard.setId("easyas123");
testMetacard.setResourceURI(downloadFile.toURI());
testMetacard.setResourceSize("125");
testMetacard.setType(BasicTypes.BASIC_METACARD);
URLResourceReader testURLResourceReader = new URLResourceReader();
testURLResourceReader.setRootResourceDirectories(new HashSet<String>(Arrays.asList(new String[] { System.getProperty("user.dir") })));
List<ResourceReader> testResourceReaderList = Collections.singletonList((ResourceReader) testURLResourceReader);
Map<String, Serializable> tmpMap = Collections.emptyMap();
Map<String, Integer> idToBytes = new HashMap<String, Integer>();
testGetDownloadStatusHelper(null, null, null);
testDownloadManager.download(mock(ResourceRequest.class), testMetacard, new LocalResourceRetriever(testResourceReaderList, testMetacard.getResourceURI(), tmpMap));
TimeUnit.SECONDS.sleep(2);
testGetDownloadStatusHelper(idToBytes, DownloadManagerState.DownloadState.COMPLETED.name(), downloadFile.getName());
}
Aggregations