Search in sources :

Example 1 with ResourceReader

use of ddf.catalog.resource.ResourceReader in project ddf by codice.

the class TestOpenSearchSource method givenSource.

private OpenSearchSource givenSource(Answer<BinaryContent> answer) throws IOException, ResourceNotFoundException, ResourceNotSupportedException {
    WebClient client = mock(WebClient.class);
    ResourceReader mockReader = mock(ResourceReader.class);
    Response clientResponse = mock(Response.class);
    when(clientResponse.getEntity()).thenReturn(getBinaryData());
    when(clientResponse.getHeaderString(eq(OpenSearchSource.HEADER_ACCEPT_RANGES))).thenReturn(OpenSearchSource.BYTES);
    when(client.get()).thenReturn(clientResponse);
    SecureCxfClientFactory factory = getMockFactory(client);
    when(mockReader.retrieveResource(any(URI.class), any(Map.class))).thenReturn(new ResourceResponseImpl(new ResourceImpl(getBinaryData(), "")));
    MultivaluedMap<String, Object> headers = new MultivaluedHashMap<String, Object>();
    headers.put(HttpHeaders.CONTENT_TYPE, Arrays.<Object>asList("application/octet-stream"));
    when(clientResponse.getHeaders()).thenReturn(headers);
    OverriddenOpenSearchSource source = new OverriddenOpenSearchSource(FILTER_ADAPTER, encryptionService);
    source.setEndpointUrl("http://localhost:8181/services/catalog/query");
    source.setParameters(DEFAULT_PARAMETERS);
    source.init();
    source.setLocalQueryOnly(true);
    source.setInputTransformer(getMockInputTransformer());
    source.factory = factory;
    source.setResourceReader(mockReader);
    return source;
}
Also used : ResourceReader(ddf.catalog.resource.ResourceReader) SecureCxfClientFactory(org.codice.ddf.cxf.SecureCxfClientFactory) ResourceResponseImpl(ddf.catalog.operation.impl.ResourceResponseImpl) Matchers.containsString(org.hamcrest.Matchers.containsString) WebClient(org.apache.cxf.jaxrs.client.WebClient) URI(java.net.URI) Response(javax.ws.rs.core.Response) ResourceResponse(ddf.catalog.operation.ResourceResponse) SourceResponse(ddf.catalog.operation.SourceResponse) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) ResourceImpl(ddf.catalog.resource.impl.ResourceImpl) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) MultivaluedMap(javax.ws.rs.core.MultivaluedMap)

Example 2 with ResourceReader

use of ddf.catalog.resource.ResourceReader in project ddf by codice.

the class TestCswSource method testRetrieveResourceUsingGetRecordById.

@Test
public void testRetrieveResourceUsingGetRecordById() throws CswException, ResourceNotFoundException, IOException, ResourceNotSupportedException, URISyntaxException {
    Csw csw = createMockCsw();
    CswRecordCollection collection = mock(CswRecordCollection.class);
    Resource resource = mock(Resource.class);
    when(collection.getResource()).thenReturn(resource);
    when(csw.getRecordById(any(GetRecordByIdRequest.class), anyString())).thenReturn(collection);
    AbstractCswSource cswSource = getCswSource(csw, mockContext, null, null, null, null);
    ResourceReader reader = mock(ResourceReader.class);
    when(reader.retrieveResource(any(URI.class), any(Map.class))).thenReturn(mock(ResourceResponse.class));
    cswSource.setResourceReader(reader);
    Map<String, Serializable> props = new HashMap<>();
    props.put(Core.ID, "ID");
    cswSource.retrieveResource(new URI("http://example.com/resource"), props);
    // Verify
    verify(csw, times(1)).getRecordById(any(GetRecordByIdRequest.class), any(String.class));
}
Also used : ResourceReader(ddf.catalog.resource.ResourceReader) Serializable(java.io.Serializable) HashMap(java.util.HashMap) Csw(org.codice.ddf.spatial.ogc.csw.catalog.common.Csw) Resource(ddf.catalog.resource.Resource) Matchers.anyString(org.mockito.Matchers.anyString) GetRecordByIdRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.GetRecordByIdRequest) URI(java.net.URI) ResourceResponse(ddf.catalog.operation.ResourceResponse) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) Map(java.util.Map) Matchers.anyMap(org.mockito.Matchers.anyMap) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 3 with ResourceReader

use of ddf.catalog.resource.ResourceReader in project ddf by codice.

the class TestCswSource method testRetrieveResourceUsingGetRecordByIdWithNoId.

@Test(expected = ResourceNotFoundException.class)
public void testRetrieveResourceUsingGetRecordByIdWithNoId() throws CswException, ResourceNotFoundException, IOException, ResourceNotSupportedException, URISyntaxException {
    Csw csw = createMockCsw();
    CswRecordCollection collection = mock(CswRecordCollection.class);
    Resource resource = mock(Resource.class);
    when(collection.getResource()).thenReturn(resource);
    when(csw.getRecordById(any(GetRecordByIdRequest.class), anyString())).thenReturn(collection);
    AbstractCswSource cswSource = getCswSource(csw, mockContext, null, null, null, null);
    ResourceReader reader = mock(ResourceReader.class);
    when(reader.retrieveResource(any(URI.class), any(Map.class))).thenReturn(mock(ResourceResponse.class));
    cswSource.setResourceReader(reader);
    Map<String, Serializable> props = new HashMap<>();
    cswSource.retrieveResource(new URI("http://example.com/resource"), props);
}
Also used : ResourceReader(ddf.catalog.resource.ResourceReader) Serializable(java.io.Serializable) HashMap(java.util.HashMap) Csw(org.codice.ddf.spatial.ogc.csw.catalog.common.Csw) Resource(ddf.catalog.resource.Resource) Matchers.anyString(org.mockito.Matchers.anyString) GetRecordByIdRequest(org.codice.ddf.spatial.ogc.csw.catalog.common.GetRecordByIdRequest) URI(java.net.URI) ResourceResponse(ddf.catalog.operation.ResourceResponse) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) Map(java.util.Map) Matchers.anyMap(org.mockito.Matchers.anyMap) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 4 with ResourceReader

use of ddf.catalog.resource.ResourceReader in project ddf by codice.

the class TestCswSource method testRetrieveResourceUsingReader.

@Test
public void testRetrieveResourceUsingReader() throws URISyntaxException, ResourceNotFoundException, IOException, ResourceNotSupportedException, CswException {
    configureMockCsw();
    AbstractCswSource cswSource = getCswSource(mockCsw, mockContext, null, null, null, null);
    ResourceReader reader = mock(ResourceReader.class);
    when(reader.retrieveResource(any(URI.class), any(Map.class))).thenReturn(mock(ResourceResponse.class));
    cswSource.setResourceReader(reader);
    Map<String, Serializable> props = new HashMap<>();
    props.put(Core.ID, "ID");
    cswSource.retrieveResource(new URI("http://example.com/resource"), props);
    // Verify
    verify(reader, times(1)).retrieveResource(any(URI.class), anyMap());
}
Also used : ResourceReader(ddf.catalog.resource.ResourceReader) Serializable(java.io.Serializable) ResourceResponse(ddf.catalog.operation.ResourceResponse) HashMap(java.util.HashMap) Matchers.anyString(org.mockito.Matchers.anyString) URI(java.net.URI) Map(java.util.Map) Matchers.anyMap(org.mockito.Matchers.anyMap) HashMap(java.util.HashMap) Test(org.junit.Test)

Example 5 with ResourceReader

use of ddf.catalog.resource.ResourceReader in project ddf by codice.

the class ResourceOperations method getOptionsFromLocalProvider.

/**
 * Get the supported options from the {@link ResourceReader} that matches the scheme in the
 * specified {@link Metacard}'s URI. Only look in the local provider for the specified {@link
 * Metacard}.
 *
 * @param metacard the {@link Metacard} to get the supported options for
 * @return the {@link Set} of supported options for the metacard
 * @deprecated
 */
@Deprecated
private Set<String> getOptionsFromLocalProvider(Metacard metacard) {
    LOGGER.trace(ENTERING_STR, "getOptionsFromLocalProvider");
    Set<String> supportedOptions = Collections.emptySet();
    URI resourceUri = metacard.getResourceURI();
    for (ResourceReader reader : frameworkProperties.getResourceReaders()) {
        LOGGER.debug("reader id: {}", reader.getId());
        Set<String> rrSupportedSchemes = reader.getSupportedSchemes();
        String metacardScheme = resourceUri.getScheme();
        if (metacardScheme != null && rrSupportedSchemes.contains(metacardScheme)) {
            supportedOptions = reader.getOptions(metacard);
        }
    }
    LOGGER.trace(EXITING_STR, "getOptionsFromLocalProvider");
    return supportedOptions;
}
Also used : ResourceReader(ddf.catalog.resource.ResourceReader) URI(java.net.URI)

Aggregations

ResourceReader (ddf.catalog.resource.ResourceReader)15 URI (java.net.URI)14 ResourceResponse (ddf.catalog.operation.ResourceResponse)12 HashMap (java.util.HashMap)12 Test (org.junit.Test)12 Serializable (java.io.Serializable)11 Map (java.util.Map)9 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)8 Resource (ddf.catalog.resource.Resource)5 ImmutableMap (com.google.common.collect.ImmutableMap)4 ResourceResponseImpl (ddf.catalog.operation.impl.ResourceResponseImpl)3 ResourceImpl (ddf.catalog.resource.impl.ResourceImpl)3 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)3 Csw (org.codice.ddf.spatial.ogc.csw.catalog.common.Csw)3 CswRecordCollection (org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection)3 GetRecordByIdRequest (org.codice.ddf.spatial.ogc.csw.catalog.common.GetRecordByIdRequest)3 ArgumentMatchers.anyMap (org.mockito.ArgumentMatchers.anyMap)3 Matchers.anyMap (org.mockito.Matchers.anyMap)3 Matchers.anyString (org.mockito.Matchers.anyString)3 Metacard (ddf.catalog.data.Metacard)2