Search in sources :

Example 6 with SecureCxfClientFactory

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;
}
Also used : ResourceReader(ddf.catalog.resource.ResourceReader) SecureCxfClientFactory(org.codice.ddf.cxf.SecureCxfClientFactory) ResourceResponseImpl(ddf.catalog.operation.impl.ResourceResponseImpl) Matchers.containsString(org.hamcrest.Matchers.containsString) WebClient(org.apache.cxf.jaxrs.client.WebClient) URI(java.net.URI) Response(javax.ws.rs.core.Response) ResourceResponse(ddf.catalog.operation.ResourceResponse) SourceResponse(ddf.catalog.operation.SourceResponse) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) ResourceImpl(ddf.catalog.resource.impl.ResourceImpl) Map(java.util.Map) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) MultivaluedMap(javax.ws.rs.core.MultivaluedMap)

Example 7 with SecureCxfClientFactory

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;
}
Also used : SecureCxfClientFactory(org.codice.ddf.cxf.SecureCxfClientFactory) Subject(ddf.security.Subject)

Example 8 with SecureCxfClientFactory

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());
}
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 9 with SecureCxfClientFactory

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());
}
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 10 with SecureCxfClientFactory

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

Aggregations

SecureCxfClientFactory (org.codice.ddf.cxf.SecureCxfClientFactory)13 ResourceResponse (ddf.catalog.operation.ResourceResponse)10 SourceResponse (ddf.catalog.operation.SourceResponse)10 Response (javax.ws.rs.core.Response)10 WebClient (org.apache.cxf.jaxrs.client.WebClient)10 QueryImpl (ddf.catalog.operation.impl.QueryImpl)9 QueryRequestImpl (ddf.catalog.operation.impl.QueryRequestImpl)9 Test (org.junit.Test)9 Filter (org.opengis.filter.Filter)9 Matchers.containsString (org.hamcrest.Matchers.containsString)6 Metacard (ddf.catalog.data.Metacard)4 Result (ddf.catalog.data.Result)4 Subject (ddf.security.Subject)3 HashMap (java.util.HashMap)3 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)3 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)3 MetacardImpl (ddf.catalog.data.impl.MetacardImpl)2 CatalogTransformerException (ddf.catalog.transform.CatalogTransformerException)2 InputTransformer (ddf.catalog.transform.InputTransformer)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2