Search in sources :

Example 11 with ResourceRequest

use of ddf.catalog.operation.ResourceRequest in project ddf by codice.

the class ReliableResourceDownloadManagerTest method testDownloadWithNullMetacard.

@Test(expected = DownloadException.class)
public void testDownloadWithNullMetacard() throws Exception {
    resourceRequest = mock(ResourceRequest.class);
    ResourceRetriever retriever = mock(ResourceRetriever.class);
    downloadMgr.download(resourceRequest, null, retriever);
}
Also used : ResourceRetriever(ddf.catalog.resourceretriever.ResourceRetriever) ResourceRequest(ddf.catalog.operation.ResourceRequest) Test(org.junit.Test)

Example 12 with ResourceRequest

use of ddf.catalog.operation.ResourceRequest in project ddf by codice.

the class ReliableResourceDownloadManagerTest method testDownloadWithNullResourceRetriever.

@Test(expected = DownloadException.class)
public void testDownloadWithNullResourceRetriever() throws Exception {
    Metacard metacard = getMockMetacard(EXPECTED_METACARD_ID, EXPECTED_METACARD_SOURCE_ID);
    resourceRequest = mock(ResourceRequest.class);
    downloadMgr.download(resourceRequest, metacard, null);
}
Also used : Metacard(ddf.catalog.data.Metacard) ResourceRequest(ddf.catalog.operation.ResourceRequest) Test(org.junit.Test)

Example 13 with ResourceRequest

use of ddf.catalog.operation.ResourceRequest in project ddf by codice.

the class SecurityPluginTest method testNominalCaseResource.

@Test
public void testNominalCaseResource() throws Exception {
    Subject mockSubject = mock(Subject.class);
    ThreadContext.bind(mockSubject);
    ResourceRequest request = new MockResourceRequest();
    SecurityPlugin plugin = new SecurityPlugin();
    request = plugin.processPreResource(request);
    assertThat(request.getPropertyValue(SecurityConstants.SECURITY_SUBJECT), equalTo(mockSubject));
}
Also used : ResourceRequest(ddf.catalog.operation.ResourceRequest) Subject(ddf.security.Subject) Test(org.junit.Test)

Example 14 with ResourceRequest

use of ddf.catalog.operation.ResourceRequest in project ddf by codice.

the class ResourceDownload method copyToLocalSite.

@Override
public void copyToLocalSite(String sourceId, String metacardId) throws MBeanException {
    LOGGER.debug("Downloading resource associated with metacard id [{}] from source [{}] to the local site.", metacardId, sourceId);
    ResourceRequest resourceRequest = new ResourceRequestById(metacardId);
    if (!resourceCacheMBean.isCacheEnabled()) {
        String message = "Caching of resources is not enabled.";
        LOGGER.info(message);
        throw new MBeanException(new DownloadToLocalSiteException(Status.BAD_REQUEST, message), message);
    }
    try {
        LOGGER.debug("Attempting to download the resource associated with metacard [{}] from source [{}] to the local site.", metacardId, sourceId);
        ResourceResponse resourceResponse = catalogFramework.getResource(resourceRequest, sourceId);
        if (resourceResponse == null) {
            String message = String.format(ERROR_MESSAGE_TEMPLATE, metacardId, sourceId);
            LOGGER.debug(message);
            throw new MBeanException(new DownloadToLocalSiteException(Status.INTERNAL_SERVER_ERROR, message), message);
        }
    } catch (IOException | ResourceNotSupportedException e) {
        String message = String.format(ERROR_MESSAGE_TEMPLATE, metacardId, sourceId);
        LOGGER.debug(message, e);
        throw new MBeanException(new DownloadToLocalSiteException(Status.INTERNAL_SERVER_ERROR, message), message);
    } catch (ResourceNotFoundException e) {
        String message = String.format(ERROR_MESSAGE_TEMPLATE + " The resource could not be found.", metacardId, sourceId);
        LOGGER.debug(message, e);
        throw new MBeanException(new DownloadToLocalSiteException(Status.NOT_FOUND, message), message);
    }
}
Also used : ResourceResponse(ddf.catalog.operation.ResourceResponse) ResourceNotSupportedException(ddf.catalog.resource.ResourceNotSupportedException) ResourceRequestById(ddf.catalog.operation.impl.ResourceRequestById) NotCompliantMBeanException(javax.management.NotCompliantMBeanException) MBeanException(javax.management.MBeanException) ResourceRequest(ddf.catalog.operation.ResourceRequest) DownloadToLocalSiteException(org.codice.ddf.catalog.resource.download.DownloadToLocalSiteException) IOException(java.io.IOException) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException)

Example 15 with ResourceRequest

use of ddf.catalog.operation.ResourceRequest in project ddf by codice.

the class TestResourceUsagePlugin method testPreResourceLocalSourceNoLocalMonitoring.

@Test
public void testPreResourceLocalSourceNoLocalMonitoring() throws StopProcessingException, PluginExecutionException, PersistenceException {
    plugin.setMonitorLocalSources(false);
    ResourceRequest originalRequest = getMockLocalResourceRequest(RESOURCE_SIZE, TEST_USER);
    ResourceRequest request = plugin.process(originalRequest);
    assertThat(request, is(notNullValue()));
    assertThat(request, is(originalRequest));
    verify(attributeStore, never()).getDataLimitByUser(anyString());
    verify(attributeStore, never()).getCurrentDataUsageByUser(anyString());
}
Also used : ResourceRequest(ddf.catalog.operation.ResourceRequest) Test(org.junit.Test)

Aggregations

ResourceRequest (ddf.catalog.operation.ResourceRequest)34 Test (org.junit.Test)20 ResourceResponse (ddf.catalog.operation.ResourceResponse)11 Metacard (ddf.catalog.data.Metacard)10 Resource (ddf.catalog.resource.Resource)7 Serializable (java.io.Serializable)7 HashMap (java.util.HashMap)7 ResourceRequestById (ddf.catalog.operation.impl.ResourceRequestById)6 ResourceNotFoundException (ddf.catalog.resource.ResourceNotFoundException)6 ResourceNotSupportedException (ddf.catalog.resource.ResourceNotSupportedException)6 IOException (java.io.IOException)6 Matchers.anyString (org.mockito.Matchers.anyString)6 QueryRequest (ddf.catalog.operation.QueryRequest)5 ResourceRetriever (ddf.catalog.resourceretriever.ResourceRetriever)5 Result (ddf.catalog.data.Result)4 DeleteRequest (ddf.catalog.operation.DeleteRequest)4 QueryResponse (ddf.catalog.operation.QueryResponse)4 MimeType (javax.activation.MimeType)4 Subject (ddf.security.Subject)3 ArrayList (java.util.ArrayList)3