use of org.codice.ddf.cxf.SecureCxfClientFactory in project ddf by codice.
the class TestOpenSearchSource method testQueryBySearchPhraseRss.
@Test
public void testQueryBySearchPhraseRss() 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);
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());
}
use of org.codice.ddf.cxf.SecureCxfClientFactory in project ddf by codice.
the class TestOpenSearchSource method testQueryBadResponse.
@Test(expected = UnsupportedQueryException.class)
public void testQueryBadResponse() throws UnsupportedQueryException, IOException {
Response clientResponse = mock(Response.class);
WebClient client = mock(WebClient.class);
//ClientResponse
doReturn(clientResponse).when(client).get();
doReturn(Response.Status.INTERNAL_SERVER_ERROR.getStatusCode()).when(clientResponse).getStatus();
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);
source.query(new QueryRequestImpl(new QueryImpl(filter)));
}
use of org.codice.ddf.cxf.SecureCxfClientFactory in project ddf by codice.
the class TestCswSource method getCswSource.
private AbstractCswSource getCswSource(Csw csw, BundleContext context, String contentMapping, String queryTypeQName, String queryTypePrefix, EncryptionService encryptionService) {
CswSourceConfiguration cswSourceConfiguration = getStandardCswSourceConfiguration(contentMapping, queryTypeQName, queryTypePrefix, encryptionService);
cswSourceConfiguration.putMetacardCswMapping(Metacard.CONTENT_TYPE, contentMapping);
SecureCxfClientFactory mockFactory = mock(SecureCxfClientFactory.class);
doReturn(csw).when(mockFactory).getClient();
doReturn(csw).when(mockFactory).getClientForSubject(any(Subject.class));
CswSourceStub cswSource = new CswSourceStub(mockContext, cswSourceConfiguration, mockProvider, mockFactory, encryptionService);
setMetacardType(cswSource);
cswSource.setFilterAdapter(new GeotoolsFilterAdapterImpl());
cswSource.setFilterBuilder(builder);
cswSource.setContext(context);
cswSource.setOutputSchema(CswConstants.CSW_OUTPUT_SCHEMA);
cswSource.setAvailabilityTask(mockAvailabilityTask);
cswSource.setMetacardTypes(mockRegistry);
cswSource.configureCswSource();
return cswSource;
}
Aggregations