Search in sources :

Example 36 with StopProcessingException

use of ddf.catalog.plugin.StopProcessingException in project ddf by codice.

the class ExceptionsTest method testStopProcessingException.

@Test
public void testStopProcessingException() {
    StopProcessingException spe = new StopProcessingException(msg);
    assertEquals(spe.getMessage(), msg);
}
Also used : StopProcessingException(ddf.catalog.plugin.StopProcessingException) Test(org.junit.Test)

Example 37 with StopProcessingException

use of ddf.catalog.plugin.StopProcessingException in project ddf by codice.

the class CatalogFrameworkImplTest method testPostQueryStopExecution.

@Test(expected = FederationException.class)
public void testPostQueryStopExecution() throws UnsupportedQueryException, FederationException, SourceUnavailableException {
    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.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) FilterFactory(org.opengis.filter.FilterFactory) 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) ArgumentMatchers.anyList(org.mockito.ArgumentMatchers.anyList) ArrayList(java.util.ArrayList) List(java.util.List) PostQueryPlugin(ddf.catalog.plugin.PostQueryPlugin) BundleContext(org.osgi.framework.BundleContext) Test(org.junit.Test)

Example 38 with StopProcessingException

use of ddf.catalog.plugin.StopProcessingException in project ddf by codice.

the class SortedFederationStrategyTest 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 SortedFederationStrategy(queryExecutor, Arrays.asList(mockPlug, mockPlug2), new ArrayList<>());
    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);
}
Also used : PreFederatedQueryPlugin(ddf.catalog.plugin.PreFederatedQueryPlugin) QueryRequest(ddf.catalog.operation.QueryRequest) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) ArrayList(java.util.ArrayList) StopProcessingException(ddf.catalog.plugin.StopProcessingException) Source(ddf.catalog.source.Source) Test(org.junit.Test)

Aggregations

StopProcessingException (ddf.catalog.plugin.StopProcessingException)38 QueryResponse (ddf.catalog.operation.QueryResponse)11 Metacard (ddf.catalog.data.Metacard)10 PluginExecutionException (ddf.catalog.plugin.PluginExecutionException)10 QueryRequest (ddf.catalog.operation.QueryRequest)9 ArrayList (java.util.ArrayList)9 Test (org.junit.Test)8 Attribute (ddf.catalog.data.Attribute)7 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)7 QueryResponseImpl (ddf.catalog.operation.impl.QueryResponseImpl)7 Serializable (java.io.Serializable)7 HashMap (java.util.HashMap)7 Result (ddf.catalog.data.Result)6 Query (ddf.catalog.operation.Query)6 PreFederatedQueryPlugin (ddf.catalog.plugin.PreFederatedQueryPlugin)6 Source (ddf.catalog.source.Source)6 Map (java.util.Map)6 Subject (org.apache.shiro.subject.Subject)6 KeyValueCollectionPermission (ddf.security.permission.KeyValueCollectionPermission)5 List (java.util.List)5