use of ddf.catalog.federation.FederationStrategy in project ddf by codice.
the class CatalogFrameworkImplTest method testPostQueryStopExecution.
@Test(expected = FederationException.class)
public void testPostQueryStopExecution() throws UnsupportedQueryException, FederationException, SourceUnavailableException {
SourcePoller poller = mock(SourcePoller.class);
when(poller.getCachedSource(isA(Source.class))).thenReturn(null);
BundleContext context = null;
FilterFactory filterFactory = new FilterFactoryImpl();
Filter filter = filterFactory.like(filterFactory.property(Metacard.METADATA), "goodyear", "*", "?", "/", false);
QueryRequest request = new QueryRequestImpl(new QueryImpl(filter));
SourceResponseImpl sourceResponse = new SourceResponseImpl(request, new ArrayList<Result>());
QueryResponseImpl queryResponse = new QueryResponseImpl(sourceResponse, "anyId");
CatalogProvider provider = mock(CatalogProvider.class);
when(provider.query(isA(QueryRequest.class))).thenReturn(sourceResponse);
FederationStrategy federationStrategy = mock(FederationStrategy.class);
when(federationStrategy.federate(isA(List.class), isA(QueryRequest.class))).thenReturn(queryResponse);
PostQueryPlugin stopQueryPlugin = new PostQueryPlugin() {
@Override
public QueryResponse process(QueryResponse input) throws PluginExecutionException, StopProcessingException {
throw new StopProcessingException("Testing that the framework will stop the query.");
}
};
FrameworkProperties props = new FrameworkProperties();
props.setCatalogProviders(Collections.singletonList((CatalogProvider) provider));
props.setBundleContext(context);
props.setPostQuery(Arrays.asList(stopQueryPlugin));
props.setFederationStrategy(federationStrategy);
props.setQueryResponsePostProcessor(mock(QueryResponsePostProcessor.class));
props.setSourcePoller(poller);
props.setFilterBuilder(new GeotoolsFilterBuilder());
CatalogFrameworkImpl framework = createFramework(props);
framework.query(request);
}
use of ddf.catalog.federation.FederationStrategy 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.federation.FederationStrategy in project ddf by codice.
the class FanoutCatalogFrameworkTest method testBlacklistedTagDeleteRequestFails.
@Test(expected = IngestException.class)
public void testBlacklistedTagDeleteRequestFails() throws Exception {
Metacard metacard = new MetacardImpl();
metacard.setAttribute(new AttributeImpl(Metacard.ID, "metacardId"));
metacard.setAttribute(new AttributeImpl(Metacard.TAGS, "blacklisted"));
CatalogProvider catalogProvider = mock(CatalogProvider.class);
doReturn(true).when(catalogProvider).isAvailable();
StorageProvider storageProvider = new MockMemoryStorageProvider();
FilterBuilder filterBuilder = new GeotoolsFilterBuilder();
FilterAdapter filterAdapter = mock(FilterAdapter.class);
ValidationQueryFactory validationQueryFactory = new ValidationQueryFactory(filterAdapter, filterBuilder);
QueryRequestImpl queryRequest = new QueryRequestImpl(mock(Query.class));
ResultImpl result = new ResultImpl(metacard);
List<Result> results = new ArrayList<>();
results.add(result);
QueryResponseImpl queryResponse = new QueryResponseImpl(queryRequest, results, 1);
FederationStrategy strategy = mock(FederationStrategy.class);
when(strategy.federate(anyList(), any())).thenReturn(queryResponse);
QueryResponsePostProcessor queryResponsePostProcessor = mock(QueryResponsePostProcessor.class);
doNothing().when(queryResponsePostProcessor).processResponse(any());
frameworkProperties.setCatalogProviders(Collections.singletonList(catalogProvider));
frameworkProperties.setStorageProviders(Collections.singletonList(storageProvider));
frameworkProperties.setFilterBuilder(filterBuilder);
frameworkProperties.setValidationQueryFactory(validationQueryFactory);
frameworkProperties.setFederationStrategy(strategy);
frameworkProperties.setQueryResponsePostProcessor(queryResponsePostProcessor);
OperationsSecuritySupport opsSecurity = new OperationsSecuritySupport();
MetacardFactory metacardFactory = new MetacardFactory(frameworkProperties.getMimeTypeToTransformerMapper(), uuidGenerator);
OperationsMetacardSupport opsMetacard = new OperationsMetacardSupport(frameworkProperties, metacardFactory);
SourceOperations sourceOperations = new SourceOperations(frameworkProperties);
sourceOperations.bind(catalogProvider);
sourceOperations.bind(storageProvider);
TransformOperations transformOperations = new TransformOperations(frameworkProperties);
QueryOperations queryOperations = new QueryOperations(frameworkProperties, sourceOperations, opsSecurity, opsMetacard);
OperationsCatalogStoreSupport opsCatStore = new OperationsCatalogStoreSupport(frameworkProperties, sourceOperations);
ResourceOperations resourceOperations = new ResourceOperations(frameworkProperties, queryOperations, opsSecurity);
DeleteOperations deleteOperations = new DeleteOperations(frameworkProperties, queryOperations, sourceOperations, opsSecurity, null);
deleteOperations.setOpsCatStoreSupport(opsCatStore);
framework = new CatalogFrameworkImpl(null, null, deleteOperations, queryOperations, resourceOperations, sourceOperations, transformOperations);
framework.setId(NEW_SOURCE_ID);
framework.setFanoutEnabled(true);
framework.setFanoutTagBlacklist(Collections.singletonList("blacklisted"));
DeleteRequest request = new DeleteRequestImpl(metacard.getId());
framework.delete(request);
}
Aggregations