Search in sources :

Example 56 with SourceResponse

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

the class TestWfsSource method testPaging.

// Simulates query by ID (which is analogous to clicking on link in search
// results to
// view associated metacard in XML)
@Test
public void testPaging() throws WfsException, SecurityServiceException, TransformerConfigurationException, UnsupportedQueryException {
    int pageSize = 4;
    int startIndex = 1;
    int numFeatures = 1;
    setUp(ONE_TEXT_PROPERTY_SCHEMA, null, null, numFeatures, null);
    SourceResponse response = executeQuery(startIndex, pageSize);
    List<Result> results = response.getResults();
    assertThat(results.size(), is(1));
    assertThat(response.getHits(), equalTo(new Long(numFeatures)));
}
Also used : SourceResponse(ddf.catalog.operation.SourceResponse) Result(ddf.catalog.data.Result) Test(org.junit.Test)

Example 57 with SourceResponse

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

the class CatalogFrameworkImplTest method testQueryTransformWithTransformException.

@Test(expected = CatalogTransformerException.class)
public void testQueryTransformWithTransformException() throws Exception {
    BundleContext context = mock(BundleContext.class);
    QueryResponseTransformer transformer = mock(QueryResponseTransformer.class);
    ServiceReference reference = mock(ServiceReference.class);
    ServiceReference[] serviceReferences = new ServiceReference[] { reference };
    when(context.getServiceReferences(anyString(), anyString())).thenReturn(serviceReferences);
    when(context.getService(isA(ServiceReference.class))).thenReturn(transformer);
    when(transformer.transform(isA(SourceResponse.class), isA(Map.class))).thenThrow(new CatalogTransformerException("Could not transform"));
    CatalogFramework framework = this.createDummyCatalogFramework(provider, storageProvider, context, eventAdmin, true);
    SourceResponse response = new SourceResponseImpl(null, null);
    framework.transform(response, "NONE", new HashMap<String, Serializable>());
}
Also used : Serializable(java.io.Serializable) SourceResponse(ddf.catalog.operation.SourceResponse) QueryResponseTransformer(ddf.catalog.transform.QueryResponseTransformer) SourceResponseImpl(ddf.catalog.operation.impl.SourceResponseImpl) CatalogFramework(ddf.catalog.CatalogFramework) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) Matchers.anyString(org.mockito.Matchers.anyString) Map(java.util.Map) Matchers.anyMap(org.mockito.Matchers.anyMap) HashMap(java.util.HashMap) BundleContext(org.osgi.framework.BundleContext) ServiceReference(org.osgi.framework.ServiceReference) Test(org.junit.Test)

Example 58 with SourceResponse

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

the class TestOpenSearchSource method testQueryQueryByMetacardIdFollowedByAnyTextQuery.

// DDF-161
@Test
public void testQueryQueryByMetacardIdFollowedByAnyTextQuery() throws Exception {
    WebClient client = mock(WebClient.class);
    Response clientResponse = mock(Response.class);
    when(clientResponse.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
    when(client.get()).thenReturn(clientResponse);
    when(clientResponse.getEntity()).thenReturn(getSampleXmlStream()).thenReturn(getSampleAtomStream());
    SecureCxfClientFactory factory = getMockFactory(client);
    OverriddenOpenSearchSource source = new OverriddenOpenSearchSource(FILTER_ADAPTER, encryptionService);
    source.setLocalQueryOnly(true);
    source.setInputTransformer(getMockInputTransformer());
    source.setEndpointUrl("http://localhost:8181/services/catalog/query");
    source.init();
    source.setParameters(DEFAULT_PARAMETERS);
    source.factory = factory;
    // Metacard ID filter
    Filter idFilter = filterBuilder.attribute(Metacard.ID).equalTo().text(SAMPLE_ID);
    // Any text filter
    Filter anyTextFilter = filterBuilder.attribute(Metacard.ANY_TEXT).like().text(SAMPLE_SEARCH_PHRASE);
    // Perform Test (Query by ID followed by Any Text Query)
    SourceResponse response1 = source.query(new QueryRequestImpl(new QueryImpl(idFilter)));
    SourceResponse response2 = source.query(new QueryRequestImpl(new QueryImpl(anyTextFilter)));
    // Verification - Verify that we don't see any exceptions when
    // processing the input stream from the endpoint.
    // Verify 1 metacard is in the results
    assertThat(response1.getResults().size(), is(1));
    // Verify that the atom feed is converted into 1 metacard result
    assertThat(response2.getResults().size(), is(1));
}
Also used : Response(javax.ws.rs.core.Response) ResourceResponse(ddf.catalog.operation.ResourceResponse) SourceResponse(ddf.catalog.operation.SourceResponse) QueryImpl(ddf.catalog.operation.impl.QueryImpl) SourceResponse(ddf.catalog.operation.SourceResponse) SecureCxfClientFactory(org.codice.ddf.cxf.SecureCxfClientFactory) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Example 59 with SourceResponse

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

the class TestOpenSearchSource method testQueryQueryByMetacardIdFollowedByAnyTextQueryRss.

// DDF-161
@Test
public void testQueryQueryByMetacardIdFollowedByAnyTextQueryRss() throws Exception {
    WebClient client = mock(WebClient.class);
    Response clientResponse = mock(Response.class);
    when(clientResponse.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
    when(clientResponse.getEntity()).thenReturn(getSampleXmlStream()).thenReturn(getSampleRssStream());
    when(client.get()).thenReturn(clientResponse);
    SecureCxfClientFactory factory = getMockFactory(client);
    OverriddenOpenSearchSource source = new OverriddenOpenSearchSource(FILTER_ADAPTER, encryptionService);
    source.setLocalQueryOnly(true);
    source.setInputTransformer(getMockInputTransformer());
    source.setEndpointUrl("http://localhost:8181/services/catalog/query");
    source.init();
    source.setParameters(DEFAULT_PARAMETERS);
    source.factory = factory;
    // Metacard ID filter
    Filter idFilter = filterBuilder.attribute(Metacard.ID).equalTo().text(SAMPLE_ID);
    // Any text filter
    Filter anyTextFilter = filterBuilder.attribute(Metacard.ANY_TEXT).like().text(SAMPLE_SEARCH_PHRASE);
    // Perform Test (Query by ID followed by Any Text Query)
    SourceResponse response1 = source.query(new QueryRequestImpl(new QueryImpl(idFilter)));
    SourceResponse response2 = source.query(new QueryRequestImpl(new QueryImpl(anyTextFilter)));
    // Verification - Verify that we don't see any exceptions when
    // processing the input stream from the endpoint.
    // Verify 1 metacard is in the results
    assertThat(response1.getResults().size(), is(1));
    // Verify that the atom feed is converted into 1 metacard result
    assertThat(response2.getResults().size(), is(1));
}
Also used : Response(javax.ws.rs.core.Response) ResourceResponse(ddf.catalog.operation.ResourceResponse) SourceResponse(ddf.catalog.operation.SourceResponse) QueryImpl(ddf.catalog.operation.impl.QueryImpl) SourceResponse(ddf.catalog.operation.SourceResponse) SecureCxfClientFactory(org.codice.ddf.cxf.SecureCxfClientFactory) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Example 60 with SourceResponse

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

the class TestOpenSearchSource method testQueryById.

/**
     * Tests the proper query is sent to the remote source for query by id.
     *
     * @throws UnsupportedQueryException
     * @throws IOException
     * @throws MalformedURLException
     */
@Test
public void testQueryById() throws UnsupportedQueryException, IOException {
    Response clientResponse = mock(Response.class);
    WebClient client = mock(WebClient.class);
    //ClientResponse
    doReturn(clientResponse).when(client).get();
    doReturn(Response.Status.OK.getStatusCode()).when(clientResponse).getStatus();
    //Client functions
    doReturn(getSampleXmlStream()).when(clientResponse).getEntity();
    when(clientResponse.getHeaderString(eq(OpenSearchSource.HEADER_ACCEPT_RANGES))).thenReturn(OpenSearchSource.BYTES);
    when(client.replaceQueryParam(any(String.class), any(Object.class))).thenReturn(client);
    SecureCxfClientFactory factory = getMockFactory(client);
    OverriddenOpenSearchSource source = new OverriddenOpenSearchSource(FILTER_ADAPTER, encryptionService);
    source.setInputTransformer(getMockInputTransformer());
    source.setEndpointUrl("http://localhost:8181/services/catalog/query");
    source.init();
    source.setParameters(DEFAULT_PARAMETERS);
    source.factory = factory;
    Filter filter = filterBuilder.attribute(Metacard.ID).equalTo().text(SAMPLE_ID);
    // when
    SourceResponse response = source.query(new QueryRequestImpl(new QueryImpl(filter)));
    // then
    Assert.assertEquals(1, response.getHits());
}
Also used : Response(javax.ws.rs.core.Response) ResourceResponse(ddf.catalog.operation.ResourceResponse) SourceResponse(ddf.catalog.operation.SourceResponse) QueryImpl(ddf.catalog.operation.impl.QueryImpl) SourceResponse(ddf.catalog.operation.SourceResponse) SecureCxfClientFactory(org.codice.ddf.cxf.SecureCxfClientFactory) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Matchers.containsString(org.hamcrest.Matchers.containsString) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Aggregations

SourceResponse (ddf.catalog.operation.SourceResponse)199 Test (org.junit.Test)146 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)99 QueryImpl (ddf.catalog.operation.impl.QueryImpl)95 Result (ddf.catalog.data.Result)79 Metacard (ddf.catalog.data.Metacard)73 Filter (org.opengis.filter.Filter)58 QueryRequest (ddf.catalog.operation.QueryRequest)52 BinaryContent (ddf.catalog.data.BinaryContent)40 ResultImpl (ddf.catalog.data.impl.ResultImpl)29 SourceResponseImpl (ddf.catalog.operation.impl.SourceResponseImpl)25 ArrayList (java.util.ArrayList)25 HashMap (java.util.HashMap)24 Matchers.containsString (org.hamcrest.Matchers.containsString)24 Matchers.anyString (org.mockito.Matchers.anyString)21 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)20 Serializable (java.io.Serializable)20 MetacardTransformer (ddf.catalog.transform.MetacardTransformer)19 SortByImpl (ddf.catalog.filter.impl.SortByImpl)18 Map (java.util.Map)16