use of ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder in project ddf by codice.
the class CatalogFrameworkImplTest method testGetResourceOptions.
/**
* Tests that you can get a resource's (product) options. Covers the case where the source ID
* specified is actually the local catalog provider's site name (so this reduces down to a
* getResourceOptions for local provider); and the case where a federated source is specified.
* <p>
* Test for DDF-1763.
*
* @throws Exception
*/
@Test
public void testGetResourceOptions() throws Exception {
String localProviderName = "ddf";
String federatedSite1Name = "fed-site-1";
String metacardId = "123";
// The resource's URI
URI metacardUri = new URI("http:///27+Nov+12+12%3A30%3A04?MyPhotograph%0Ahttp%3A%2F%2F172.18.14.53%3A8080%2Fabc%2Fimages%2FActionable.jpg%0AMyAttachment%0Ahttp%3A%2F%2F172.18.14.53%3A8080%2Fabc#abc.xyz.dao.URLResourceOptionDataAccessObject");
Set<String> supportedOptions = new HashSet<String>();
supportedOptions.add("MyPhotograph");
supportedOptions.add("MyAttachment");
// Catalog Provider
CatalogProvider provider = mock(CatalogProvider.class);
when(provider.getId()).thenReturn(localProviderName);
when(provider.isAvailable(isA(SourceMonitor.class))).thenReturn(true);
when(provider.isAvailable()).thenReturn(true);
// Federated Source 1
FederatedSource federatedSource1 = mock(FederatedSource.class);
when(federatedSource1.getId()).thenReturn(federatedSite1Name);
when(federatedSource1.isAvailable(isA(SourceMonitor.class))).thenReturn(true);
when(federatedSource1.isAvailable()).thenReturn(true);
when(federatedSource1.getOptions(isA(Metacard.class))).thenReturn(supportedOptions);
List<FederatedSource> federatedSources = new ArrayList<FederatedSource>();
federatedSources.add(federatedSource1);
// Mock register the provider in the container
// Mock the source poller
SourcePoller mockPoller = mock(SourcePoller.class);
when(mockPoller.getCachedSource(isA(Source.class))).thenReturn(null);
MetacardImpl metacard = new MetacardImpl(BASIC_METACARD);
metacard.setId(metacardId);
metacard.setResourceURI(metacardUri);
Result result = new ResultImpl(metacard);
List<Result> results = new ArrayList<>();
results.add(result);
QueryResponse queryResponse = mock(QueryResponse.class);
when(queryResponse.getResults()).thenReturn(results);
FederationStrategy strategy = mock(FederationStrategy.class);
when(strategy.federate(isA(federatedSources.getClass()), isA(QueryRequest.class))).thenReturn(queryResponse);
ResourceReader resourceReader = mock(ResourceReader.class);
Set<String> supportedSchemes = new HashSet<String>();
supportedSchemes.add("http");
when(resourceReader.getSupportedSchemes()).thenReturn(supportedSchemes);
when(resourceReader.getOptions(isA(Metacard.class))).thenReturn(supportedOptions);
List<ResourceReader> resourceReaders = new ArrayList<ResourceReader>();
resourceReaders.add(resourceReader);
FrameworkProperties props = new FrameworkProperties();
props.setCatalogProviders(Collections.singletonList((CatalogProvider) provider));
props.setFederatedSources(Collections.singletonMap(federatedSite1Name, federatedSource1));
props.setResourceReaders(resourceReaders);
props.setFederationStrategy(strategy);
props.setQueryResponsePostProcessor(mock(QueryResponsePostProcessor.class));
props.setSourcePoller(mockPoller);
props.setFilterBuilder(new GeotoolsFilterBuilder());
props.setDefaultAttributeValueRegistry(defaultAttributeValueRegistry);
CatalogFrameworkImpl framework = createFramework(props);
framework.setId("ddf");
Set<String> ids = new HashSet<String>();
for (FederatedSource source : federatedSources) {
ids.add(source.getId());
}
ids.add(framework.getId());
// site name = local provider
Map<String, Set<String>> optionsMap = framework.getResourceOptions(metacardId, localProviderName);
LOGGER.debug("localProvider optionsMap = {}", optionsMap);
assertThat(optionsMap, hasEntry("RESOURCE_OPTION", supportedOptions));
// site name = federated site's name
optionsMap = framework.getResourceOptions(metacardId, federatedSite1Name);
LOGGER.debug("federatedSource optionsMap = {}", optionsMap);
assertThat(optionsMap, hasEntry("RESOURCE_OPTION", supportedOptions));
// site name = null (should default to local provider)
optionsMap = framework.getResourceOptions(metacardId, null);
LOGGER.debug("localProvider optionsMap = {}", optionsMap);
assertThat(optionsMap, hasEntry("RESOURCE_OPTION", supportedOptions));
// site name = empty string (should default to local provider)
optionsMap = framework.getResourceOptions(metacardId, "");
LOGGER.debug("localProvider optionsMap = {}", optionsMap);
assertThat(optionsMap, hasEntry("RESOURCE_OPTION", supportedOptions));
}
use of ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder in project ddf by codice.
the class CatalogFrameworkImplTest method testFederatedQueryPermissionsNotPermitted.
@Test(expected = FederationException.class)
public void testFederatedQueryPermissionsNotPermitted() throws Exception {
MockEventProcessor eventAdmin = new MockEventProcessor();
MockMemoryProvider provider = new MockMemoryProvider("Provider", "Provider", "v1.0", "DDF", new HashSet<>(), true, new Date());
Map<String, CatalogStore> storeMap = new HashMap<>();
Map<String, FederatedSource> sourceMap = new HashMap<>();
Map<String, Set<String>> securityAttributes = new HashMap<>();
securityAttributes.put("role", Collections.singleton("myRole"));
MockCatalogStore store = new MockCatalogStore("catalogStoreId-1", true, securityAttributes);
storeMap.put(store.getId(), store);
sourceMap.put(store.getId(), store);
CatalogFramework framework = createDummyCatalogFramework(provider, storeMap, sourceMap, eventAdmin);
FilterBuilder builder = new GeotoolsFilterBuilder();
Subject subject = mock(Subject.class);
when(subject.isPermitted(any(KeyValueCollectionPermission.class))).thenReturn(false);
HashMap<String, Serializable> properties = new HashMap<>();
properties.put(SecurityConstants.SECURITY_SUBJECT, subject);
QueryImpl query = new QueryImpl(builder.attribute(Metacard.CONTENT_TYPE).is().like().text("someType"));
QueryRequestImpl request = new QueryRequestImpl(query, false, Collections.singletonList("catalogStoreId-1"), properties);
framework.query(request);
}
use of ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder in project ddf by codice.
the class TestRestEndpoint method executeTest.
private Response executeTest(CatalogFramework framework, String transformer, boolean local, HttpServletRequest request) throws URISyntaxException {
RESTEndpoint restEndpoint = new RESTEndpoint(framework);
restEndpoint.setTikaMimeTypeResolver(new TikaMimeTypeResolver());
FilterBuilder filterBuilder = new GeotoolsFilterBuilder();
restEndpoint.setFilterBuilder(filterBuilder);
UriInfo uriInfo;
Response response;
if (local) {
uriInfo = createSpecificUriInfo(LOCAL_RETRIEVE_ADDRESS);
response = restEndpoint.getDocument(GET_ID, transformer, uriInfo, request);
} else {
uriInfo = createSpecificUriInfo(FED_RETRIEVE_ADDRESS);
response = restEndpoint.getDocument(GET_SITENAME, GET_ID, transformer, uriInfo, request);
}
return response;
}
use of ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder in project ddf by codice.
the class TestRestEndpoint method headTest.
private Response headTest(boolean local) throws CatalogTransformerException, URISyntaxException, UnsupportedEncodingException, UnsupportedQueryException, SourceUnavailableException, FederationException, IngestException {
MetacardImpl metacard = null;
List<Result> list = new ArrayList<Result>();
Result result = mock(Result.class);
InputStream inputStream = null;
UriInfo uriInfo;
Response response;
CatalogFramework framework = givenCatalogFramework(SAMPLE_ID);
list.add(result);
QueryResponse queryResponse = mock(QueryResponse.class);
when(queryResponse.getResults()).thenReturn(list);
when(framework.query(isA(QueryRequest.class), isNull(FederationStrategy.class))).thenReturn(queryResponse);
metacard = new MetacardImpl();
metacard.setSourceId(GET_SITENAME);
when(result.getMetacard()).thenReturn(metacard);
Resource resource = mock(Resource.class);
inputStream = new ByteArrayInputStream(GET_STREAM.getBytes(GET_OUTPUT_TYPE));
when(resource.getInputStream()).thenReturn(inputStream);
when(resource.getMimeTypeValue()).thenReturn(GET_MIME_TYPE);
when(resource.getName()).thenReturn(GET_FILENAME);
when(framework.transform(isA(Metacard.class), anyString(), isA(Map.class))).thenReturn(resource);
RESTEndpoint restEndpoint = new RESTEndpoint(framework);
restEndpoint.setTikaMimeTypeResolver(new TikaMimeTypeResolver());
FilterBuilder filterBuilder = new GeotoolsFilterBuilder();
restEndpoint.setFilterBuilder(filterBuilder);
uriInfo = createSpecificUriInfo(LOCAL_RETRIEVE_ADDRESS);
if (local) {
response = restEndpoint.getHeaders(GET_ID, uriInfo, null);
} else {
response = restEndpoint.getHeaders(null, GET_ID, uriInfo, null);
}
return response;
}
use of ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder in project ddf by codice.
the class CachingFederationStrategyTest method testCatchStopProcessingException.
@Test
public void testCatchStopProcessingException() throws Exception {
PreFederatedQueryPlugin mockPlug = mock(PreFederatedQueryPlugin.class);
PreFederatedQueryPlugin mockPlug2 = mock(PreFederatedQueryPlugin.class);
when(mockPlug.process(any(Source.class), any(QueryRequest.class))).thenThrow(new StopProcessingException("test exception"));
strategy = new CachingFederationStrategy(queryExecutor, Arrays.asList(mockPlug, mockPlug2), new ArrayList<>(), cache, cacheExecutor, mock(ValidationQueryFactory.class), new CacheQueryFactory(new GeotoolsFilterBuilder()));
QueryRequest fedQueryRequest = new QueryRequestImpl(mockQuery, properties);
strategy.federate(Arrays.asList(mock(Source.class)), fedQueryRequest);
// First plugin throws exception, so second plugin is untouched
verify(mockPlug).process(any(Source.class), any(QueryRequest.class));
verifyZeroInteractions(mockPlug2);
}
Aggregations