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());
}
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());
}
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);
}
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);
}
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);
}
Aggregations