Search in sources :

Example 6 with SourceResponse

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

the class TestOpenSearchSource method testQueryBySearchPhraseContentTypeSetRss.

@Test
public void testQueryBySearchPhraseContentTypeSetRss() throws UnsupportedQueryException, URISyntaxException, IOException {
    WebClient client = mock(WebClient.class);
    Response clientResponse = mock(Response.class);
    when(client.get()).thenReturn(clientResponse);
    when(clientResponse.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
    when(clientResponse.getEntity()).thenReturn(getSampleRssStream());
    SecureCxfClientFactory factory = getMockFactory(client);
    OverriddenOpenSearchSource source = new OverriddenOpenSearchSource(FILTER_ADAPTER, encryptionService);
    InputTransformer inputTransformer = mock(InputTransformer.class);
    MetacardImpl generatedMetacard = new MetacardImpl();
    generatedMetacard.setMetadata(getSample());
    generatedMetacard.setId(SAMPLE_ID);
    generatedMetacard.setContentTypeName("myType");
    try {
        when(inputTransformer.transform(isA(InputStream.class))).thenReturn(generatedMetacard);
        when(inputTransformer.transform(isA(InputStream.class), isA(String.class))).thenReturn(generatedMetacard);
    } catch (IOException e) {
        fail();
    } catch (CatalogTransformerException e) {
        fail();
    }
    source.setInputTransformer(inputTransformer);
    source.setEndpointUrl("http://localhost:8181/services/catalog/query");
    source.init();
    source.setParameters(DEFAULT_PARAMETERS);
    source.factory = factory;
    Filter filter = filterBuilder.attribute(Metacard.METADATA).like().text(SAMPLE_SEARCH_PHRASE);
    SourceResponse response = source.query(new QueryRequestImpl(new QueryImpl(filter)));
    Assert.assertEquals(1, response.getHits());
    List<Result> results = response.getResults();
    Assert.assertTrue(results.size() == 1);
    Result result = results.get(0);
    Metacard metacard = result.getMetacard();
    Assert.assertNotNull(metacard);
    Assert.assertEquals("myType", metacard.getContentTypeName());
}
Also used : SourceResponse(ddf.catalog.operation.SourceResponse) SecureCxfClientFactory(org.codice.ddf.cxf.SecureCxfClientFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) Matchers.containsString(org.hamcrest.Matchers.containsString) IOException(java.io.IOException) InputTransformer(ddf.catalog.transform.InputTransformer) WebClient(org.apache.cxf.jaxrs.client.WebClient) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) Response(javax.ws.rs.core.Response) ResourceResponse(ddf.catalog.operation.ResourceResponse) SourceResponse(ddf.catalog.operation.SourceResponse) QueryImpl(ddf.catalog.operation.impl.QueryImpl) Metacard(ddf.catalog.data.Metacard) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Test(org.junit.Test)

Example 7 with SourceResponse

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

the class TestOpenSearchSource method testQueryAnyText.

@Test
public void testQueryAnyText() throws UnsupportedQueryException, URISyntaxException, IOException {
    Response clientResponse = mock(Response.class);
    doReturn(getSampleAtomStream()).when(clientResponse).getEntity();
    WebClient client = mock(WebClient.class);
    doReturn(Response.Status.OK.getStatusCode()).when(clientResponse).getStatus();
    doReturn(clientResponse).when(client).get();
    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.ANY_TEXT).like().text(SAMPLE_SEARCH_PHRASE);
    // when
    SourceResponse response = source.query(new QueryRequestImpl(new QueryImpl(filter)));
    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) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Example 8 with SourceResponse

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

the class TestOpenSearchSource method testQueryBySearchPhraseContentTypeSet.

@Test
public void testQueryBySearchPhraseContentTypeSet() throws UnsupportedQueryException, URISyntaxException, IOException {
    WebClient client = mock(WebClient.class);
    Response clientResponse = mock(Response.class);
    when(client.get()).thenReturn(clientResponse);
    when(clientResponse.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
    when(clientResponse.getEntity()).thenReturn(getSampleAtomStream());
    SecureCxfClientFactory factory = getMockFactory(client);
    OverriddenOpenSearchSource source = new OverriddenOpenSearchSource(FILTER_ADAPTER, encryptionService);
    InputTransformer inputTransformer = mock(InputTransformer.class);
    MetacardImpl generatedMetacard = new MetacardImpl();
    generatedMetacard.setMetadata(getSample());
    generatedMetacard.setId(SAMPLE_ID);
    generatedMetacard.setContentTypeName("myType");
    try {
        when(inputTransformer.transform(isA(InputStream.class))).thenReturn(generatedMetacard);
        when(inputTransformer.transform(isA(InputStream.class), isA(String.class))).thenReturn(generatedMetacard);
    } catch (IOException e) {
        fail();
    } catch (CatalogTransformerException e) {
        fail();
    }
    source.setInputTransformer(inputTransformer);
    source.setEndpointUrl("http://localhost:8181/services/catalog/query");
    source.init();
    source.setParameters(DEFAULT_PARAMETERS);
    source.factory = factory;
    Filter filter = filterBuilder.attribute(Metacard.METADATA).like().text(SAMPLE_SEARCH_PHRASE);
    SourceResponse response = source.query(new QueryRequestImpl(new QueryImpl(filter)));
    Assert.assertEquals(1, response.getHits());
    List<Result> results = response.getResults();
    Assert.assertTrue(results.size() == 1);
    Result result = results.get(0);
    Metacard metacard = result.getMetacard();
    Assert.assertNotNull(metacard);
    Assert.assertEquals("myType", metacard.getContentTypeName());
}
Also used : SourceResponse(ddf.catalog.operation.SourceResponse) SecureCxfClientFactory(org.codice.ddf.cxf.SecureCxfClientFactory) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) CatalogTransformerException(ddf.catalog.transform.CatalogTransformerException) Matchers.containsString(org.hamcrest.Matchers.containsString) IOException(java.io.IOException) InputTransformer(ddf.catalog.transform.InputTransformer) WebClient(org.apache.cxf.jaxrs.client.WebClient) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Result(ddf.catalog.data.Result) Response(javax.ws.rs.core.Response) ResourceResponse(ddf.catalog.operation.ResourceResponse) SourceResponse(ddf.catalog.operation.SourceResponse) QueryImpl(ddf.catalog.operation.impl.QueryImpl) Metacard(ddf.catalog.data.Metacard) Filter(org.opengis.filter.Filter) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Test(org.junit.Test)

Example 9 with SourceResponse

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

the class AbstractCswStore method transactionQuery.

private List<Metacard> transactionQuery(List<Filter> idFilters, Subject subject) throws UnsupportedQueryException {
    Filter createFilter = filterBuilder.allOf(filterBuilder.anyOf(filterBuilder.attribute(Core.METACARD_TAGS).is().like().text(FilterDelegate.WILDCARD_CHAR), filterBuilder.attribute(Core.METACARD_TAGS).empty()), filterBuilder.anyOf(idFilters));
    Query query = new QueryImpl(createFilter);
    Map<String, Serializable> properties = new HashMap<>();
    properties.put(SecurityConstants.SECURITY_SUBJECT, subject);
    QueryRequest queryRequest = new QueryRequestImpl(query, properties);
    SourceResponse sourceResponse = query(queryRequest);
    List<Result> results = sourceResponse.getResults();
    return results.stream().map(Result::getMetacard).collect(Collectors.toList());
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) Serializable(java.io.Serializable) Query(ddf.catalog.operation.Query) QueryRequest(ddf.catalog.operation.QueryRequest) SourceResponse(ddf.catalog.operation.SourceResponse) Filter(org.opengis.filter.Filter) HashMap(java.util.HashMap) QueryRequestImpl(ddf.catalog.operation.impl.QueryRequestImpl) Result(ddf.catalog.data.Result)

Example 10 with SourceResponse

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

the class TestCswQueryResponseTransformer method testMarshalAcknowledgement.

@Test
public void testMarshalAcknowledgement() throws WebApplicationException, IOException, JAXBException, CatalogTransformerException {
    GetRecordsType query = new GetRecordsType();
    query.setResultType(ResultType.VALIDATE);
    query.setMaxRecords(BigInteger.valueOf(6));
    query.setStartPosition(BigInteger.valueOf(4));
    SourceResponse sourceResponse = createSourceResponse(query, 22);
    Map<String, Serializable> args = new HashMap<>();
    args.put(CswConstants.RESULT_TYPE_PARAMETER, ResultType.VALIDATE);
    args.put(CswConstants.GET_RECORDS, query);
    BinaryContent content = transformer.transform(sourceResponse, args);
    String xml = new String(content.getByteArray());
    JAXBElement<?> jaxb = (JAXBElement<?>) getJaxBContext().createUnmarshaller().unmarshal(new ByteArrayInputStream(xml.getBytes("UTF-8")));
    assertThat(jaxb.getValue(), is(instanceOf(AcknowledgementType.class)));
    AcknowledgementType response = (AcknowledgementType) jaxb.getValue();
    assertThat(response.getEchoedRequest().getAny(), is(instanceOf(JAXBElement.class)));
    JAXBElement<?> jaxB = (JAXBElement<?>) response.getEchoedRequest().getAny();
    assertThat(jaxB.getValue(), is(instanceOf(GetRecordsType.class)));
}
Also used : Serializable(java.io.Serializable) SourceResponse(ddf.catalog.operation.SourceResponse) HashMap(java.util.HashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) JAXBElement(javax.xml.bind.JAXBElement) BinaryContent(ddf.catalog.data.BinaryContent) AcknowledgementType(net.opengis.cat.csw.v_2_0_2.AcknowledgementType) 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