Search in sources :

Example 21 with ResourceRequest

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

the class ZipCompression method getResource.

private Resource getResource(Metacard metacard) {
    Resource resource = null;
    try {
        ResourceRequest resourceRequest = new ResourceRequestById(metacard.getId());
        ResourceResponse resourceResponse = catalogFramework.getLocalResource(resourceRequest);
        resource = resourceResponse.getResource();
    } catch (IOException | ResourceNotFoundException | ResourceNotSupportedException e) {
        LOGGER.debug("Unable to retrieve content from metacard : {}", metacard.getId(), e);
    }
    return resource;
}
Also used : ResourceResponse(ddf.catalog.operation.ResourceResponse) ResourceNotSupportedException(ddf.catalog.resource.ResourceNotSupportedException) Resource(ddf.catalog.resource.Resource) ResourceRequestById(ddf.catalog.operation.impl.ResourceRequestById) ResourceRequest(ddf.catalog.operation.ResourceRequest) IOException(java.io.IOException) ResourceNotFoundException(ddf.catalog.resource.ResourceNotFoundException)

Example 22 with ResourceRequest

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

the class TestResourceUsagePlugin method getMockResourceRequest.

private ResourceRequest getMockResourceRequest(String resourceSize, String expectedUsername) {
    setSubject(expectedUsername);
    ResourceRequest resourceRequest = mock(ResourceRequest.class);
    Map<String, Serializable> requestProperties = new HashMap<>();
    requestProperties.put(SecurityConstants.SECURITY_SUBJECT, subject);
    requestProperties.put(Metacard.RESOURCE_SIZE, resourceSize);
    when(resourceRequest.getPropertyNames()).thenReturn(requestProperties.keySet());
    when(resourceRequest.getPropertyValue(SecurityConstants.SECURITY_SUBJECT)).thenReturn(subject);
    when(resourceRequest.getPropertyValue(Metacard.RESOURCE_SIZE)).thenReturn(resourceSize);
    return resourceRequest;
}
Also used : Serializable(java.io.Serializable) HashMap(java.util.HashMap) ResourceRequest(ddf.catalog.operation.ResourceRequest) Matchers.anyString(org.mockito.Matchers.anyString)

Example 23 with ResourceRequest

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

the class TestResourceUsagePlugin method testPreResourcePersistenceException.

@Test
public void testPreResourcePersistenceException() throws StopProcessingException, PluginExecutionException, PersistenceException {
    doThrow(PersistenceException.class).when(attributeStore).getCurrentDataUsageByUser(anyString());
    ResourceRequest originalRequest = getMockLocalResourceRequest(RESOURCE_SIZE, TEST_USER);
    ResourceRequest request = plugin.process(originalRequest);
    assertThat(request, notNullValue());
    assertThat(request, is(originalRequest));
}
Also used : ResourceRequest(ddf.catalog.operation.ResourceRequest) Test(org.junit.Test)

Example 24 with ResourceRequest

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

the class TestResourceUsagePlugin method testPreResourceValidSize.

@Test
public void testPreResourceValidSize() throws StopProcessingException, PluginExecutionException, PersistenceException {
    ArgumentCaptor<String> usernameArg = ArgumentCaptor.forClass(String.class);
    ResourceRequest originalRequest = getMockLocalResourceRequest(RESOURCE_SIZE, TEST_USER);
    ResourceRequest request = plugin.process(originalRequest);
    assertThat(request, notNullValue());
    assertThat(request, is(originalRequest));
    verify(attributeStore).getDataLimitByUser(usernameArg.capture());
    assertThat(usernameArg.getValue(), is(TEST_USER));
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) ResourceRequest(ddf.catalog.operation.ResourceRequest) Test(org.junit.Test)

Example 25 with ResourceRequest

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

the class TestResourceUsagePlugin method testPreResourceRemoteSourceValidSize.

@Test
public void testPreResourceRemoteSourceValidSize() throws Exception {
    plugin.setMonitorLocalSources(false);
    ArgumentCaptor<String> usernameArg = ArgumentCaptor.forClass(String.class);
    ResourceRequest originalRequest = getMockRemoteResourceRequest(RESOURCE_SIZE, TEST_USER);
    ResourceRequest request = plugin.process(originalRequest);
    assertThat(request, notNullValue());
    assertThat(request, is(originalRequest));
    verify(attributeStore).getDataLimitByUser(usernameArg.capture());
    assertThat(usernameArg.getValue(), is(TEST_USER));
}
Also used : Matchers.anyString(org.mockito.Matchers.anyString) 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