use of org.codice.ddf.cxf.SecureCxfClientFactory in project ddf by codice.
the class TestOpenSearchSource method givenSource.
private OpenSearchSource givenSource(Answer<BinaryContent> answer) throws IOException, ResourceNotFoundException, ResourceNotSupportedException {
WebClient client = mock(WebClient.class);
ResourceReader mockReader = mock(ResourceReader.class);
Response clientResponse = mock(Response.class);
when(clientResponse.getEntity()).thenReturn(getBinaryData());
when(clientResponse.getHeaderString(eq(OpenSearchSource.HEADER_ACCEPT_RANGES))).thenReturn(OpenSearchSource.BYTES);
when(client.get()).thenReturn(clientResponse);
SecureCxfClientFactory factory = getMockFactory(client);
when(mockReader.retrieveResource(any(URI.class), any(Map.class))).thenReturn(new ResourceResponseImpl(new ResourceImpl(getBinaryData(), "")));
MultivaluedMap<String, Object> headers = new MultivaluedHashMap<String, Object>();
headers.put(HttpHeaders.CONTENT_TYPE, Arrays.<Object>asList("application/octet-stream"));
when(clientResponse.getHeaders()).thenReturn(headers);
OverriddenOpenSearchSource source = new OverriddenOpenSearchSource(FILTER_ADAPTER, encryptionService);
source.setEndpointUrl("http://localhost:8181/services/catalog/query");
source.setParameters(DEFAULT_PARAMETERS);
source.init();
source.setLocalQueryOnly(true);
source.setInputTransformer(getMockInputTransformer());
source.factory = factory;
source.setResourceReader(mockReader);
return source;
}
use of org.codice.ddf.cxf.SecureCxfClientFactory in project ddf by codice.
the class TestOpenSearchSource method getMockFactory.
protected SecureCxfClientFactory getMockFactory(WebClient client) {
SecureCxfClientFactory factory = mock(SecureCxfClientFactory.class);
doReturn(client).when(factory).getClient();
doReturn(client).when(factory).getWebClientForSubject(any(org.apache.shiro.subject.Subject.class));
doReturn(client).when(factory).getWebClient();
return factory;
}
use of org.codice.ddf.cxf.SecureCxfClientFactory 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.codice.ddf.cxf.SecureCxfClientFactory 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.codice.ddf.cxf.SecureCxfClientFactory 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());
}
Aggregations