use of org.codice.ddf.cxf.SecureCxfClientFactory in project ddf by codice.
the class WfsSource method setWfsUrl.
public void setWfsUrl(String wfsUrl) throws SecurityServiceException {
this.wfsUrl = wfsUrl;
factory = new SecureCxfClientFactory(wfsUrl, Wfs.class);
}
use of org.codice.ddf.cxf.SecureCxfClientFactory 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));
}
use of org.codice.ddf.cxf.SecureCxfClientFactory 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));
}
use of org.codice.ddf.cxf.SecureCxfClientFactory 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());
}
use of org.codice.ddf.cxf.SecureCxfClientFactory in project ddf by codice.
the class TestOpenSearchSource method testQueryBySearchPhrase.
@Test
public void testQueryBySearchPhrase() throws UnsupportedQueryException, URISyntaxException, IOException {
Response clientResponse = mock(Response.class);
when(clientResponse.getStatus()).thenReturn(Response.Status.OK.getStatusCode());
when(clientResponse.getEntity()).thenReturn(getSampleAtomStream());
WebClient client = mock(WebClient.class);
when(client.get()).thenReturn(clientResponse);
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.METADATA).like().text(SAMPLE_SEARCH_PHRASE);
// when
QueryRequestImpl queryRequest = new QueryRequestImpl(new QueryImpl(filter));
Map<String, Serializable> properties = new HashMap<>();
properties.put(SecurityConstants.SECURITY_SUBJECT, mock(Subject.class));
queryRequest.setProperties(properties);
SourceResponse response = source.query(queryRequest);
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("Resource", metacard.getContentTypeName());
}
Aggregations