Search in sources :

Example 6 with FederationStrategy

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);
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) FederationStrategy(ddf.catalog.federation.FederationStrategy) StopProcessingException(ddf.catalog.plugin.StopProcessingException) Source(ddf.catalog.source.Source) ByteSource(com.google.common.io.ByteSource) CachedSource(ddf.catalog.util.impl.CachedSource) FederatedSource(ddf.catalog.source.FederatedSource) FilterFactory(org.opengis.filter.FilterFactory) SourcePoller(ddf.catalog.util.impl.SourcePoller) Result(ddf.catalog.data.Result) QueryImpl(ddf.catalog.operation.impl.QueryImpl) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) Filter(org.opengis.filter.Filter) CatalogProvider(ddf.catalog.source.CatalogProvider) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) FilterFactoryImpl(org.geotools.filter.FilterFactoryImpl) ArrayList(java.util.ArrayList) List(java.util.List) Matchers.anyList(org.mockito.Matchers.anyList) PostQueryPlugin(ddf.catalog.plugin.PostQueryPlugin) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Example 7 with FederationStrategy

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));
}
Also used : ResourceReader(ddf.catalog.resource.ResourceReader) Set(java.util.Set) HashSet(java.util.HashSet) ArrayList(java.util.ArrayList) ResultImpl(ddf.catalog.data.impl.ResultImpl) Matchers.anyString(org.mockito.Matchers.anyString) URI(java.net.URI) Source(ddf.catalog.source.Source) ByteSource(com.google.common.io.ByteSource) CachedSource(ddf.catalog.util.impl.CachedSource) FederatedSource(ddf.catalog.source.FederatedSource) SourcePoller(ddf.catalog.util.impl.SourcePoller) Result(ddf.catalog.data.Result) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) HashSet(java.util.HashSet) QueryRequest(ddf.catalog.operation.QueryRequest) FederationStrategy(ddf.catalog.federation.FederationStrategy) SourceMonitor(ddf.catalog.source.SourceMonitor) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) FederatedSource(ddf.catalog.source.FederatedSource) Metacard(ddf.catalog.data.Metacard) CatalogProvider(ddf.catalog.source.CatalogProvider) QueryResponse(ddf.catalog.operation.QueryResponse) Test(org.junit.Test)

Example 8 with FederationStrategy

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);
}
Also used : OperationsCatalogStoreSupport(ddf.catalog.impl.operations.OperationsCatalogStoreSupport) Query(ddf.catalog.operation.Query) AttributeImpl(ddf.catalog.data.impl.AttributeImpl) MockMemoryStorageProvider(ddf.catalog.content.impl.MockMemoryStorageProvider) ArrayList(java.util.ArrayList) FilterAdapter(ddf.catalog.filter.FilterAdapter) ResultImpl(ddf.catalog.data.impl.ResultImpl) DeleteOperations(ddf.catalog.impl.operations.DeleteOperations) Result(ddf.catalog.data.Result) MetacardFactory(ddf.catalog.impl.operations.MetacardFactory) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) FilterBuilder(ddf.catalog.filter.FilterBuilder) GeotoolsFilterBuilder(ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder) SourceOperations(ddf.catalog.impl.operations.SourceOperations) FederationStrategy(ddf.catalog.federation.FederationStrategy) ResourceOperations(ddf.catalog.impl.operations.ResourceOperations) DeleteRequestImpl(ddf.catalog.operation.impl.DeleteRequestImpl) ValidationQueryFactory(ddf.catalog.cache.solr.impl.ValidationQueryFactory) StorageProvider(ddf.catalog.content.StorageProvider) MockMemoryStorageProvider(ddf.catalog.content.impl.MockMemoryStorageProvider) TransformOperations(ddf.catalog.impl.operations.TransformOperations) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Metacard(ddf.catalog.data.Metacard) QueryResponseImpl(ddf.catalog.operation.impl.QueryResponseImpl) CatalogProvider(ddf.catalog.source.CatalogProvider) QueryOperations(ddf.catalog.impl.operations.QueryOperations) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) OperationsSecuritySupport(ddf.catalog.impl.operations.OperationsSecuritySupport) OperationsMetacardSupport(ddf.catalog.impl.operations.OperationsMetacardSupport) DeleteRequest(ddf.catalog.operation.DeleteRequest) Test(org.junit.Test)

Aggregations

FederationStrategy (ddf.catalog.federation.FederationStrategy)8 Result (ddf.catalog.data.Result)6 ArrayList (java.util.ArrayList)6 Test (org.junit.Test)6 ByteSource (com.google.common.io.ByteSource)5 QueryRequest (ddf.catalog.operation.QueryRequest)5 QueryResponse (ddf.catalog.operation.QueryResponse)5 FederatedSource (ddf.catalog.source.FederatedSource)5 Source (ddf.catalog.source.Source)5 CachedSource (ddf.catalog.util.impl.CachedSource)5 SourcePoller (ddf.catalog.util.impl.SourcePoller)5 GeotoolsFilterBuilder (ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder)4 QueryResponseImpl (ddf.catalog.operation.impl.QueryResponseImpl)4 CatalogProvider (ddf.catalog.source.CatalogProvider)4 Metacard (ddf.catalog.data.Metacard)3 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)3 ResultImpl (ddf.catalog.data.impl.ResultImpl)3 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)3 ValidationQueryFactory (ddf.catalog.cache.solr.impl.ValidationQueryFactory)2 QueryOperations (ddf.catalog.impl.operations.QueryOperations)2