Search in sources :

Example 21 with WebClient

use of org.apache.cxf.jaxrs.client.WebClient 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 22 with WebClient

use of org.apache.cxf.jaxrs.client.WebClient 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 23 with WebClient

use of org.apache.cxf.jaxrs.client.WebClient in project ddf by codice.

the class TestOpenSearchSiteUtil method populateNullSearchOptions.

/**
     * Verify that passing in null will still remove the parameters from the URL.
     */
@Test
public void populateNullSearchOptions() {
    WebClient webClient = WebClient.create(url.toString());
    OpenSearchSiteUtil.populateSearchOptions(webClient, null, null, Arrays.asList("q,src,mr,start,count,mt,dn,lat,lon,radius,bbox,polygon,dtstart,dtend,dateName,filter,sort".split(",")));
    String urlStr = webClient.getCurrentURI().toString();
    assertTrue(urlStr.indexOf(OpenSearchSiteUtil.COUNT) == -1);
    assertTrue(urlStr.indexOf(OpenSearchSiteUtil.MAX_RESULTS) == -1);
    assertTrue(urlStr.indexOf(OpenSearchSiteUtil.SRC) == -1);
    assertTrue(urlStr.indexOf(OpenSearchSiteUtil.USER_DN) == -1);
    assertTrue(urlStr.indexOf(OpenSearchSiteUtil.MAX_TIMEOUT) == -1);
    assertTrue(urlStr.indexOf(OpenSearchSiteUtil.FILTER) == -1);
    assertTrue(urlStr.indexOf(OpenSearchSiteUtil.SORT) == -1);
}
Also used : Matchers.containsString(org.hamcrest.Matchers.containsString) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Example 24 with WebClient

use of org.apache.cxf.jaxrs.client.WebClient in project ddf by codice.

the class TestOpenSearchSiteUtil method populateSearchOptions.

@Test
public void populateSearchOptions() throws UnsupportedEncodingException {
    String maxResults = "2000";
    String timeout = "30000";
    //this wasn't url encoded in the previous test, should have been
    String sort = "date%3Adesc";
    SortBy sortBy = new SortByImpl(Result.TEMPORAL, SortOrder.DESCENDING);
    Filter filter = mock(Filter.class);
    Query query = new QueryImpl(filter, 0, 2000, sortBy, true, 30000);
    WebClient webClient = WebClient.create(url.toString());
    OpenSearchSiteUtil.populateSearchOptions(webClient, query, null, Arrays.asList("q,src,mr,start,count,mt,dn,lat,lon,radius,bbox,polygon,dtstart,dtend,dateName,filter,sort".split(",")));
    String urlStr = webClient.getCurrentURI().toString();
    assertTrue(urlStr.indexOf(maxResults) != -1);
    assertTrue(urlStr.indexOf(timeout) != -1);
    assertThat(urlStr, containsString(sort));
    assertTrue(urlStr.indexOf(OpenSearchSiteUtil.COUNT) != -1);
    assertTrue(urlStr.indexOf(OpenSearchSiteUtil.MAX_RESULTS) != -1);
    //src is handled when the params are added to the url
    //        assertTrue(urlStr.indexOf(OpenSearchSiteUtil.SRC) != -1);
    //        assertTrue(urlStr.indexOf(OpenSearchSiteUtil.USER_DN) != -1);
    assertTrue(urlStr.indexOf(OpenSearchSiteUtil.MAX_TIMEOUT) != -1);
    //filter isn't even used, removed from test
    //        assertTrue(urlStr.indexOf(OpenSearchSiteUtil.FILTER) != -1);
    assertTrue(urlStr.indexOf(OpenSearchSiteUtil.SORT) != -1);
}
Also used : QueryImpl(ddf.catalog.operation.impl.QueryImpl) Query(ddf.catalog.operation.Query) SortByImpl(ddf.catalog.filter.impl.SortByImpl) SpatialFilter(ddf.catalog.impl.filter.SpatialFilter) TemporalFilter(ddf.catalog.impl.filter.TemporalFilter) SpatialDistanceFilter(ddf.catalog.impl.filter.SpatialDistanceFilter) Filter(org.opengis.filter.Filter) SortBy(org.opengis.filter.sort.SortBy) Matchers.containsString(org.hamcrest.Matchers.containsString) WebClient(org.apache.cxf.jaxrs.client.WebClient) Test(org.junit.Test)

Example 25 with WebClient

use of org.apache.cxf.jaxrs.client.WebClient in project ddf by codice.

the class TestOpenSearchSiteUtil method populateNullGeospatial.

/**
     * Verify that passing in null will still remove the parameters from the URL.
     */
@Test
public void populateNullGeospatial() throws Exception {
    SpatialDistanceFilter spatial = null;
    WebClient webClient = WebClient.create(url.toString());
    OpenSearchSiteUtil.populateGeospatial(webClient, spatial, true, Arrays.asList("q,src,mr,start,count,mt,dn,lat,lon,radius,bbox,polygon,dtstart,dtend,dateName,filter,sort".split(",")));
    URI urlStr = webClient.getCurrentURI();
    assertTrue(urlStr.toString().indexOf(OpenSearchSiteUtil.GEO_LAT) == -1);
    assertTrue(urlStr.toString().indexOf(OpenSearchSiteUtil.GEO_LON) == -1);
    assertTrue(urlStr.toString().indexOf(OpenSearchSiteUtil.GEO_RADIUS) == -1);
}
Also used : SpatialDistanceFilter(ddf.catalog.impl.filter.SpatialDistanceFilter) WebClient(org.apache.cxf.jaxrs.client.WebClient) URI(java.net.URI) Test(org.junit.Test)

Aggregations

WebClient (org.apache.cxf.jaxrs.client.WebClient)723 Test (org.junit.Test)400 Response (javax.ws.rs.core.Response)351 URL (java.net.URL)198 HashMap (java.util.HashMap)100 Book (org.apache.cxf.systest.jaxrs.security.Book)94 ArrayList (java.util.ArrayList)88 JacksonJsonProvider (com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider)87 CloseableHttpResponse (org.apache.http.client.methods.CloseableHttpResponse)77 ClientAccessToken (org.apache.cxf.rs.security.oauth2.common.ClientAccessToken)60 Bus (org.apache.cxf.Bus)48 SpringBusFactory (org.apache.cxf.bus.spring.SpringBusFactory)46 Test (org.testng.annotations.Test)46 Form (javax.ws.rs.core.Form)44 JwtToken (org.apache.cxf.rs.security.jose.jwt.JwtToken)42 JwtClaims (org.apache.cxf.rs.security.jose.jwt.JwtClaims)40 JwtAuthenticationClientFilter (org.apache.cxf.rs.security.jose.jaxrs.JwtAuthenticationClientFilter)32 InputStream (java.io.InputStream)28 ResponseProcessingException (javax.ws.rs.client.ResponseProcessingException)28 Document (org.w3c.dom.Document)27