Search in sources :

Example 1 with PostQueryPlugin

use of ddf.catalog.plugin.PostQueryPlugin 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)

Aggregations

ByteSource (com.google.common.io.ByteSource)1 Result (ddf.catalog.data.Result)1 FederationStrategy (ddf.catalog.federation.FederationStrategy)1 GeotoolsFilterBuilder (ddf.catalog.filter.proxy.builder.GeotoolsFilterBuilder)1 QueryRequest (ddf.catalog.operation.QueryRequest)1 QueryResponse (ddf.catalog.operation.QueryResponse)1 QueryImpl (ddf.catalog.operation.impl.QueryImpl)1 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)1 QueryResponseImpl (ddf.catalog.operation.impl.QueryResponseImpl)1 SourceResponseImpl (ddf.catalog.operation.impl.SourceResponseImpl)1 PostQueryPlugin (ddf.catalog.plugin.PostQueryPlugin)1 StopProcessingException (ddf.catalog.plugin.StopProcessingException)1 CatalogProvider (ddf.catalog.source.CatalogProvider)1 FederatedSource (ddf.catalog.source.FederatedSource)1 Source (ddf.catalog.source.Source)1 CachedSource (ddf.catalog.util.impl.CachedSource)1 SourcePoller (ddf.catalog.util.impl.SourcePoller)1 ArrayList (java.util.ArrayList)1 List (java.util.List)1 FilterFactoryImpl (org.geotools.filter.FilterFactoryImpl)1