Search in sources :

Example 56 with QueryRequest

use of ddf.catalog.operation.QueryRequest in project ddf by codice.

the class CachingFederationStrategyTest method testFederateQueryUpdateCacheBlocking.

@Test
public void testFederateQueryUpdateCacheBlocking() throws Exception {
    properties.put(QUERY_MODE, INDEX_QUERY_MODE);
    QueryRequest fedQueryRequest = new QueryRequestImpl(mockQuery, properties);
    Source mockSource = mock(Source.class);
    when(mockSource.query(any(QueryRequest.class))).thenReturn(mockResponse);
    doNothing().when(cacheCommitPhaser).add(cacheArgs.capture());
    QueryResponse federateResponse = strategy.federate(Arrays.asList(mockSource), fedQueryRequest);
    assertThat(requestArgumentCaptor.getValue().getPropertyValue(QUERY_MODE), is(INDEX_QUERY_MODE));
    verify(mockSource).query(any(QueryRequest.class));
    verify(cache, times(0)).query(any(QueryRequest.class));
    // CacheCommitPhaser.add() is called
    verify(cacheCommitPhaser).add(cacheArgs.getValue());
    verifyCacheUpdated();
    assertThat(federateResponse.getRequest().getQuery(), is(requestArgumentCaptor.getValue().getQuery()));
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) QueryResponse(ddf.catalog.operation.QueryResponse) Source(ddf.catalog.source.Source) Test(org.junit.Test)

Example 57 with QueryRequest

use of ddf.catalog.operation.QueryRequest in project ddf by codice.

the class CachingFederationStrategyTest method testValidCollectionWithNullSource.

@Test(expected = IllegalArgumentException.class)
public void testValidCollectionWithNullSource() throws Exception {
    List<Source> sources = new ArrayList<>();
    sources.add(null);
    QueryRequest fedQueryRequest = mock(QueryRequest.class);
    when(fedQueryRequest.getQuery()).thenReturn(mockQuery);
    strategy.federate(sources, fedQueryRequest);
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) ArrayList(java.util.ArrayList) Source(ddf.catalog.source.Source) Test(org.junit.Test)

Example 58 with QueryRequest

use of ddf.catalog.operation.QueryRequest in project ddf by codice.

the class CachingFederationStrategyTest method testFederateDuplicateSources.

@Test
public void testFederateDuplicateSources() throws Exception {
    Query mockQ = new QueryImpl(mock(NullFilterImpl.class), 2, 2, mock(SortBy.class), true, LONG_TIMEOUT);
    QueryRequest fedQueryRequest = new QueryRequestImpl(mockQ, properties);
    List<Source> sources = new ArrayList<>();
    // Multiple sources needed for OffsetResultHandler to be used
    for (int i = 0; i < 2; i++) {
        Source mockSource = mock(Source.class);
        when(mockSource.getId()).thenReturn("mock source");
        sources.add(mockSource);
    }
    strategy.federate(sources, fedQueryRequest);
    verify(sources.get(0), atLeastOnce()).query(any(QueryRequest.class));
    verify(sources.get(1), times(0)).query(any(QueryRequest.class));
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) NullFilterImpl(org.geotools.filter.NullFilterImpl) Query(ddf.catalog.operation.Query) QueryRequest(ddf.catalog.operation.QueryRequest) SortBy(org.opengis.filter.sort.SortBy) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) ArrayList(java.util.ArrayList) Source(ddf.catalog.source.Source) Test(org.junit.Test)

Example 59 with QueryRequest

use of ddf.catalog.operation.QueryRequest in project ddf by codice.

the class CachingFederationStrategyTest method testCatalogProviderSource.

@Test
public void testCatalogProviderSource() throws Exception {
    CatalogProvider catalogProviderSource = mock(CatalogProvider.class);
    when(catalogProviderSource.getId()).thenReturn(SystemInfo.getSiteName());
    QueryRequest fedQueryRequest = new QueryRequestImpl(mockQuery, properties);
    strategy.federate(Arrays.asList(catalogProviderSource), fedQueryRequest);
    verify(validationQueryFactory).getQueryRequestWithValidationFilter(any(QueryRequest.class), any(Boolean.class), any(Boolean.class));
}
Also used : QueryRequest(ddf.catalog.operation.QueryRequest) CatalogProvider(ddf.catalog.source.CatalogProvider) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Test(org.junit.Test)

Example 60 with QueryRequest

use of ddf.catalog.operation.QueryRequest in project ddf by codice.

the class FederationAdminServiceImplTest method getRegistryObjectByRegistryIdThatDoesNotExist.

@Test(expected = FederationAdminException.class)
public void getRegistryObjectByRegistryIdThatDoesNotExist() throws Exception {
    QueryRequest request = getTestQueryRequest();
    QueryResponse response = getPopulatedTestQueryResponse(request);
    Metacard metacard = getTestMetacard();
    when(security.getSystemSubject()).thenReturn(subject);
    when(catalogFramework.query(any(QueryRequest.class))).thenReturn(response);
    when(registryTransformer.transform(any(InputStream.class))).thenReturn(metacard);
    federationAdminServiceImpl.getRegistryObjectByRegistryId("Not a metacard");
}
Also used : Metacard(ddf.catalog.data.Metacard) QueryRequest(ddf.catalog.operation.QueryRequest) InputStream(java.io.InputStream) QueryResponse(ddf.catalog.operation.QueryResponse) Test(org.junit.Test)

Aggregations

QueryRequest (ddf.catalog.operation.QueryRequest)153 Test (org.junit.Test)98 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)86 QueryImpl (ddf.catalog.operation.impl.QueryImpl)66 QueryResponse (ddf.catalog.operation.QueryResponse)57 ArrayList (java.util.ArrayList)41 SourceResponse (ddf.catalog.operation.SourceResponse)39 Metacard (ddf.catalog.data.Metacard)33 Result (ddf.catalog.data.Result)31 Filter (org.opengis.filter.Filter)31 UnsupportedQueryException (ddf.catalog.source.UnsupportedQueryException)30 Query (ddf.catalog.operation.Query)29 Source (ddf.catalog.source.Source)24 FederationException (ddf.catalog.federation.FederationException)20 QueryResponseImpl (ddf.catalog.operation.impl.QueryResponseImpl)15 InputStream (java.io.InputStream)15 SourceUnavailableException (ddf.catalog.source.SourceUnavailableException)14 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)13 SortByImpl (ddf.catalog.filter.impl.SortByImpl)11 HashMap (java.util.HashMap)11