use of ddf.catalog.operation.ResourceResponse in project ddf by codice.
the class ReliableResourceDownloaderTest method testBadKeyName.
@Test
public void testBadKeyName() throws Exception {
Metacard metacard = getMockMetacard(DOWNLOAD_ID, ":badsourcename");
downloaderConfig.setCacheEnabled(true);
ResourceResponse mockResponse = getMockResourceResponse(mockStream);
ResourceCacheImpl mockCache = mock(ResourceCacheImpl.class);
when(mockCache.isPending(anyString())).thenReturn(false);
when(mockCache.getProductCacheDirectory()).thenReturn(productCacheDirectory);
downloaderConfig.setResourceCache(mockCache);
ReliableResourceDownloader downloader = new ReliableResourceDownloader(downloaderConfig, new AtomicBoolean(), DOWNLOAD_ID, mockResponse, getMockRetriever());
downloader.setupDownload(metacard, new DownloadStatusInfoImpl());
verify(mockCache, never()).addPendingCacheEntry(any(ReliableResource.class));
}
use of ddf.catalog.operation.ResourceResponse in project ddf by codice.
the class ReliableResourceInputStreamTest method setup.
@Before
public void setup() {
fbos = new FileBackedOutputStream(THRESHOLD);
countingFbos = new CountingOutputStream(fbos);
downloadState = mock(DownloadManagerState.class);
when(downloadState.getDownloadState()).thenReturn(DownloadManagerState.DownloadState.COMPLETED);
reliableResourceCallable = mock(ReliableResourceCallable.class);
downloadFuture = mock(Future.class);
downloadIdentifier = UUID.randomUUID().toString();
resourceResponse = mock(ResourceResponse.class);
}
use of ddf.catalog.operation.ResourceResponse in project ddf by codice.
the class ReliableResourceDownloadManagerTest method testDownloadWithoutCaching.
@Test
public //@Ignore
void testDownloadWithoutCaching() throws Exception {
mis = new MockInputStream(productInputFilename);
Metacard metacard = getMockMetacard(EXPECTED_METACARD_ID, EXPECTED_METACARD_SOURCE_ID);
resourceResponse = getMockResourceResponse();
ResourceRetriever retriever = mock(ResourceRetriever.class);
when(retriever.retrieveResource()).thenReturn(resourceResponse);
int chunkSize = 50;
downloadMgr.setChunkSize(chunkSize);
ResourceResponse newResourceResponse = downloadMgr.download(resourceRequest, metacard, retriever);
assertThat(newResourceResponse, is(notNullValue()));
productInputStream = newResourceResponse.getResource().getInputStream();
assertThat(productInputStream, is(instanceOf(ReliableResourceInputStream.class)));
ByteArrayOutputStream clientBytesRead = clientRead(chunkSize, productInputStream);
verifyClientBytesRead(clientBytesRead);
cleanup();
}
use of ddf.catalog.operation.ResourceResponse 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.operation.ResourceResponse in project ddf by codice.
the class ReliableResourceDownloaderTest method testNullReliableResourceCallableAndStatus.
@Test
public void testNullReliableResourceCallableAndStatus() throws Exception {
ResourceResponse mockResponse = getMockResourceResponse(mockStream);
ResourceRetriever mockResourceRetriever = mock(ResourceRetriever.class);
when(mockResourceRetriever.retrieveResource(any(Byte.class))).thenReturn(mockResponse);
ReliableResourceStatus resourceStatus = new ReliableResourceStatus(DownloadStatus.RESOURCE_DOWNLOAD_INTERRUPTED, 0L);
ReliableResourceCallable mockCallable = mock(ReliableResourceCallable.class);
when(mockCallable.getReliableResourceStatus()).thenReturn(resourceStatus);
PowerMockito.whenNew(ReliableResourceCallable.class).withAnyArguments().thenReturn(null, mockCallable);
PowerMockito.whenNew(ResourceRetrievalMonitor.class).withAnyArguments().thenThrow(new CancellationException());
int retries = 5;
downloaderConfig.setMaxRetryAttempts(retries);
ReliableResourceDownloader downloader = new ReliableResourceDownloader(downloaderConfig, new AtomicBoolean(), DOWNLOAD_ID, mockResponse, mockResourceRetriever);
downloader.setupDownload(mockMetacard, new DownloadStatusInfoImpl());
downloader.run();
verify(mockPublisher, times(retries)).postRetrievalStatus(any(ResourceResponse.class), eq(ProductRetrievalStatus.RETRYING), any(Metacard.class), anyString(), anyLong(), eq(DOWNLOAD_ID));
}
Aggregations