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;
}
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));
}
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);
}
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());
}
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;
}
Aggregations