Search in sources :

Example 11 with SecureCxfClientFactory

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());
}
Also used : Serializable(java.io.Serializable) SourceResponse(ddf.catalog.operation.SourceResponse) SecureCxfClientFactory(org.codice.ddf.cxf.SecureCxfClientFactory) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) HashMap(java.util.HashMap) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) Matchers.containsString(org.hamcrest.Matchers.containsString) WebClient(org.apache.cxf.jaxrs.client.WebClient) Subject(ddf.security.Subject) 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 12 with SecureCxfClientFactory

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)));
}
Also used : Response(javax.ws.rs.core.Response) ResourceResponse(ddf.catalog.operation.ResourceResponse) SourceResponse(ddf.catalog.operation.SourceResponse) QueryImpl(ddf.catalog.operation.impl.QueryImpl) 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 13 with SecureCxfClientFactory

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;
}
Also used : CswSourceConfiguration(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration) SecureCxfClientFactory(org.codice.ddf.cxf.SecureCxfClientFactory) GeotoolsFilterAdapterImpl(ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl) Subject(org.apache.shiro.subject.Subject)

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