use of ddf.catalog.resource.Resource in project alliance by codice.
the class CatalogOutputAdapterTest method testGetNitfSegmentsFlow.
@Test
public void testGetNitfSegmentsFlow() throws IOException, NitfFormatException {
Resource resource = mock(Resource.class);
when(resource.getInputStream()).thenReturn(getInputStream("/i_3001a.ntf"));
ResourceResponse resourceResponse = mock(ResourceResponse.class);
when(resourceResponse.getResource()).thenReturn(resource);
NitfSegmentsFlow nitfSegmentsFlow = catalogOutputAdapter.getNitfSegmentsFlow(resourceResponse);
assertThat(nitfSegmentsFlow, notNullValue());
}
use of ddf.catalog.resource.Resource in project ddf by codice.
the class ReliableResourceDownloaderTest method getMockResourceResponse.
private ResourceResponse getMockResourceResponse(InputStream stream) throws Exception {
ResourceRequest resourceRequest = mock(ResourceRequest.class);
Map<String, Serializable> requestProperties = new HashMap<String, Serializable>();
when(resourceRequest.getPropertyNames()).thenReturn(requestProperties.keySet());
mockResource = mock(Resource.class);
when(mockResource.getInputStream()).thenReturn(stream);
when(mockResource.getName()).thenReturn("test-resource");
when(mockResource.getMimeType()).thenReturn(new MimeType("text/plain"));
mockResponse = mock(ResourceResponse.class);
when(mockResponse.getRequest()).thenReturn(resourceRequest);
when(mockResponse.getResource()).thenReturn(mockResource);
Map<String, Serializable> responseProperties = new HashMap<String, Serializable>();
when(mockResponse.getProperties()).thenReturn(responseProperties);
return mockResponse;
}
use of ddf.catalog.resource.Resource in project ddf by codice.
the class ReliableResourceDownloadManagerTest method getMockResourceResponse.
private ResourceResponse getMockResourceResponse() throws Exception {
resourceRequest = mock(ResourceRequest.class);
Map<String, Serializable> requestProperties = new HashMap<String, Serializable>();
when(resourceRequest.getPropertyNames()).thenReturn(requestProperties.keySet());
resource = mock(Resource.class);
when(resource.getInputStream()).thenReturn(mis);
when(resource.getName()).thenReturn("test-resource");
when(resource.getMimeType()).thenReturn(new MimeType("text/plain"));
resourceResponse = mock(ResourceResponse.class);
when(resourceResponse.getRequest()).thenReturn(resourceRequest);
when(resourceResponse.getResource()).thenReturn(resource);
Map<String, Serializable> responseProperties = new HashMap<String, Serializable>();
when(resourceResponse.getProperties()).thenReturn(responseProperties);
return resourceResponse;
}
use of ddf.catalog.resource.Resource in project ddf by codice.
the class ResourceOperationsTest method testGetResource.
@Test
public void testGetResource() throws Exception {
ArrayList<Result> mockResultList = new ArrayList<>();
mockResultList.add(resultMock);
setGetResourceMocks();
when(queryResponseMock.getResults()).thenReturn(mockResultList);
when(queryResponseMock.getResults().get(0).getMetacard()).thenReturn(metacard);
when(reliableResourceDownloadManagerMock.download(any(ResourceRequest.class), any(MetacardImpl.class), isNull())).thenReturn(resourceResponseMock);
Resource resourceMock = mock(Resource.class);
when(resourceResponseMock.getResource()).thenReturn(resourceMock);
frameworkProperties.setReliableResourceDownloadManager(reliableResourceDownloadManagerMock);
resourceOperations.getResource(resourceRequestMock, isEnterprise, resourceName, fanoutEnabled);
verify(resourceResponseMock).getResource();
}
use of ddf.catalog.resource.Resource in project ddf by codice.
the class DumpCommand method createZip.
private void createZip(CatalogFacade catalog, QueryRequest queryRequest, File outputFile, AtomicLong resultCount) throws CatalogTransformerException {
try (FileOutputStream fileOutputStream = new FileOutputStream(outputFile);
ZipOutputStream zipOutputStream = new ZipOutputStream(fileOutputStream)) {
// write the metacards to the zip
ResultIterable.resultIterable(catalog::query, queryRequest).stream().map(Result::getMetacard).forEach(metacard -> {
writeMetacardToZip(zipOutputStream, metacard);
if (hasLocalResources(metacard)) {
// write the resources to the zip
Map<String, Resource> resourceMap = getAllMetacardContent(metacard);
resourceMap.forEach((filename, resource) -> writeResourceToZip(zipOutputStream, filename, resource));
}
resultCount.incrementAndGet();
});
} catch (IOException e) {
throw new CatalogTransformerException(String.format("Error occurred when initializing/closing ZipOutputStream with path %s.", outputFile.getAbsoluteFile()), e);
}
}
Aggregations