Search in sources :

Example 11 with ResourceResponse

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));
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Metacard(ddf.catalog.data.Metacard) ResourceCacheImpl(ddf.catalog.cache.impl.ResourceCacheImpl) ResourceResponse(ddf.catalog.operation.ResourceResponse) DownloadStatusInfoImpl(ddf.catalog.event.retrievestatus.DownloadStatusInfoImpl) ReliableResource(ddf.catalog.resource.data.ReliableResource) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Example 12 with ResourceResponse

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);
}
Also used : CountingOutputStream(com.google.common.io.CountingOutputStream) ResourceResponse(ddf.catalog.operation.ResourceResponse) Future(java.util.concurrent.Future) FileBackedOutputStream(com.google.common.io.FileBackedOutputStream) Before(org.junit.Before)

Example 13 with ResourceResponse

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();
}
Also used : MockInputStream(ddf.catalog.cache.MockInputStream) Metacard(ddf.catalog.data.Metacard) ResourceResponse(ddf.catalog.operation.ResourceResponse) ResourceRetriever(ddf.catalog.resourceretriever.ResourceRetriever) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.junit.Test)

Example 14 with ResourceResponse

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;
}
Also used : Serializable(java.io.Serializable) ResourceResponse(ddf.catalog.operation.ResourceResponse) HashMap(java.util.HashMap) ReliableResource(ddf.catalog.resource.data.ReliableResource) Resource(ddf.catalog.resource.Resource) ResourceRequest(ddf.catalog.operation.ResourceRequest) Matchers.anyString(org.mockito.Matchers.anyString) MimeType(javax.activation.MimeType)

Example 15 with ResourceResponse

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));
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) Metacard(ddf.catalog.data.Metacard) ResourceResponse(ddf.catalog.operation.ResourceResponse) CancellationException(java.util.concurrent.CancellationException) DownloadStatusInfoImpl(ddf.catalog.event.retrievestatus.DownloadStatusInfoImpl) ResourceRetriever(ddf.catalog.resourceretriever.ResourceRetriever) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest) Test(org.junit.Test)

Aggregations

ResourceResponse (ddf.catalog.operation.ResourceResponse)71 Test (org.junit.Test)36 HashMap (java.util.HashMap)17 Resource (ddf.catalog.resource.Resource)16 URI (java.net.URI)16 Serializable (java.io.Serializable)15 Metacard (ddf.catalog.data.Metacard)13 IOException (java.io.IOException)13 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)13 ResourceRequest (ddf.catalog.operation.ResourceRequest)12 ResourceNotFoundException (ddf.catalog.resource.ResourceNotFoundException)12 MimeType (javax.activation.MimeType)11 ResourceNotSupportedException (ddf.catalog.resource.ResourceNotSupportedException)10 Response (javax.ws.rs.core.Response)10 ResourceRequestById (ddf.catalog.operation.impl.ResourceRequestById)8 URLResourceReader (ddf.catalog.resource.impl.URLResourceReader)7 Matchers.anyString (org.mockito.Matchers.anyString)7 InputStream (java.io.InputStream)6 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)6 Matchers.containsString (org.hamcrest.Matchers.containsString)6