Search in sources :

Example 51 with CswSourceConfiguration

use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration in project ddf by codice.

the class CswSourceTest method testRefreshWithNullConfiguration.

@Test
public void testRefreshWithNullConfiguration() throws SecurityServiceException {
    AbstractCswSource cswSource = getCswSource(null, null, "type", null, null, encryptionService, permissions);
    CswSourceConfiguration defaultCswSourceConfiguration = getStandardCswSourceConfiguration(null, null, null, encryptionService, permissions);
    // Assert that the default configuration is set
    assertDefaultCswSourceConfiguration(cswSource.cswSourceConfiguration, defaultCswSourceConfiguration);
    cswSource.refresh(null);
    // Assert that the configuration does not change with a null map
    assertDefaultCswSourceConfiguration(cswSource.cswSourceConfiguration, defaultCswSourceConfiguration);
}
Also used : CswSourceConfiguration(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration) Test(org.junit.Test)

Example 52 with CswSourceConfiguration

use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration in project ddf by codice.

the class CswSourceTest method testRefreshWithUnregisterForEvents.

@Test
public void testRefreshWithUnregisterForEvents() throws Exception {
    String subscriptionId = "subscriptionid";
    String eventEndpoint = "https://ddf/services/csw/subscriptions";
    CswSourceStub cswSource = (CswSourceStub) getCswSource(mockCsw, mockContext, "contentType");
    cswSource.filterlessSubscriptionId = subscriptionId;
    CswSubscribe client = mock(CswSubscribe.class);
    Response response = mock(Response.class);
    AcknowledgementType ack = mock(AcknowledgementType.class);
    when(client.createRecordsSubscription(any(GetRecordsType.class))).thenReturn(response);
    when(response.getStatus()).thenReturn(200);
    when(response.readEntity(any(Class.class))).thenReturn(ack);
    when(ack.getRequestId()).thenReturn(subscriptionId);
    when(cswSource.getSubscriberClientFactory().getClientForSubject(cswSource.getSubject())).thenReturn(client);
    when(cswSource.getSubscriberClientFactory().getClientForSystemSubject(cswSource.getSubject())).thenReturn(client);
    cswSource.cswSourceConfiguration.setRegisterForEvents(true);
    cswSource.cswSourceConfiguration.setEventServiceAddress(eventEndpoint);
    // Set Configuration Map
    Map<String, Object> configuration = getConfigurationMap(cswSource);
    configuration.put(cswSource.REGISTER_FOR_EVENTS, false);
    configuration.put(cswSource.EVENT_SERVICE_ADDRESS, eventEndpoint);
    // Call Refresh
    cswSource.refresh(configuration);
    // Get Configuration
    CswSourceConfiguration cswSourceConfiguration = cswSource.cswSourceConfiguration;
    // Assert Refresh Changes
    Assert.assertFalse(cswSourceConfiguration.isRegisterForEvents());
    Assert.assertEquals(cswSourceConfiguration.getEventServiceAddress(), eventEndpoint);
    verify(client).deleteRecordsSubscription(subscriptionId);
}
Also used : ResourceResponse(ddf.catalog.operation.ResourceResponse) Response(javax.ws.rs.core.Response) SourceResponse(ddf.catalog.operation.SourceResponse) CswSourceConfiguration(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration) CswSubscribe(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSubscribe) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) AcknowledgementType(net.opengis.cat.csw.v_2_0_2.AcknowledgementType) Test(org.junit.Test)

Example 53 with CswSourceConfiguration

use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration in project ddf by codice.

the class CswSourceTest method getCswSource.

private AbstractCswSource getCswSource(Csw csw, BundleContext context, String contentMapping, String queryTypeQName, String queryTypePrefix, EncryptionService encryptionService, Permissions permissions) {
    CswSourceConfiguration cswSourceConfiguration = getStandardCswSourceConfiguration(contentMapping, queryTypeQName, queryTypePrefix, encryptionService, permissions);
    cswSourceConfiguration.putMetacardCswMapping(Metacard.CONTENT_TYPE, contentMapping);
    SecureCxfClientFactory<Csw> mockFactory = mock(SecureCxfClientFactory.class);
    doReturn(csw).when(mockFactory).getClient();
    doReturn(csw).when(mockFactory).getClientForSubject(any(Subject.class));
    doReturn(csw).when(mockFactory).getClientForSystemSubject(any(Subject.class));
    ClientBuilderFactory clientBuilderFactory = mock(ClientBuilderFactory.class);
    ClientBuilder<Csw> clientBuilder = new ClientBuilderImpl<Csw>(mock(OAuthSecurity.class), mock(SamlSecurity.class), mock(SecurityLogger.class), mock(SecurityManager.class)) {

        @Override
        public SecureCxfClientFactory<Csw> build() {
            return mockFactory;
        }
    };
    when(clientBuilderFactory.<Csw>getClientBuilder()).thenReturn(clientBuilder);
    CswSourceStub cswSource = new CswSourceStub(mockContext, cswSourceConfiguration, mockProvider, clientBuilderFactory, encryptionService, new Security(), permissions);
    cswSource.setFilterAdapter(new GeotoolsFilterAdapterImpl());
    cswSource.setFilterBuilder(builder);
    cswSource.setContext(context);
    cswSource.setOutputSchema(CswConstants.CSW_OUTPUT_SCHEMA);
    cswSource.setAvailabilityTask(mockAvailabilityTask);
    cswSource.configureCswSource();
    return cswSource;
}
Also used : CswSourceConfiguration(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration) ClientBuilderImpl(org.codice.ddf.cxf.client.impl.ClientBuilderImpl) SecurityManager(ddf.security.service.SecurityManager) Csw(org.codice.ddf.spatial.ogc.csw.catalog.common.Csw) OAuthSecurity(org.codice.ddf.cxf.oauth.OAuthSecurity) ClientBuilderFactory(org.codice.ddf.cxf.client.ClientBuilderFactory) Security(org.codice.ddf.security.impl.Security) SamlSecurity(org.codice.ddf.security.jaxrs.SamlSecurity) OAuthSecurity(org.codice.ddf.cxf.oauth.OAuthSecurity) Subject(org.apache.shiro.subject.Subject) SamlSecurity(org.codice.ddf.security.jaxrs.SamlSecurity) GeotoolsFilterAdapterImpl(ddf.catalog.filter.proxy.adapter.GeotoolsFilterAdapterImpl) SecurityLogger(ddf.security.audit.SecurityLogger)

Example 54 with CswSourceConfiguration

use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration in project ddf by codice.

the class CswSourceTest method testRefreshWithUpdateRegisterForEvents.

@Test
public void testRefreshWithUpdateRegisterForEvents() throws Exception {
    String subscriptionId = "subscriptionid";
    String eventEndpoint = "https://ddf/services/csw/subscriptions";
    CswSourceStub cswSource = (CswSourceStub) getCswSource(mockCsw, mockContext, "contentType");
    cswSource.filterlessSubscriptionId = subscriptionId;
    CswSubscribe client = mock(CswSubscribe.class);
    Response response = mock(Response.class);
    AcknowledgementType ack = mock(AcknowledgementType.class);
    when(client.createRecordsSubscription(any(GetRecordsType.class))).thenReturn(response);
    when(response.getStatus()).thenReturn(200);
    when(response.readEntity(any(Class.class))).thenReturn(ack);
    when(ack.getRequestId()).thenReturn(subscriptionId);
    when(cswSource.getSubscriberClientFactory().getClientForSubject(cswSource.getSubject())).thenReturn(client);
    when(cswSource.getSubscriberClientFactory().getClientForSystemSubject(cswSource.getSubject())).thenReturn(client);
    cswSource.cswSourceConfiguration.setRegisterForEvents(true);
    cswSource.cswSourceConfiguration.setEventServiceAddress(eventEndpoint + "/original");
    // Set Configuration Map
    Map<String, Object> configuration = getConfigurationMap(cswSource);
    configuration.put(cswSource.REGISTER_FOR_EVENTS, true);
    configuration.put(cswSource.EVENT_SERVICE_ADDRESS, eventEndpoint);
    // Call Refresh
    cswSource.refresh(configuration);
    // Get Configuration
    CswSourceConfiguration cswSourceConfiguration = cswSource.cswSourceConfiguration;
    // Assert Refresh Changes
    Assert.assertTrue(cswSourceConfiguration.isRegisterForEvents());
    Assert.assertEquals(cswSourceConfiguration.getEventServiceAddress(), eventEndpoint);
    verify(client).deleteRecordsSubscription(subscriptionId);
    verify(ack).getRequestId();
}
Also used : ResourceResponse(ddf.catalog.operation.ResourceResponse) Response(javax.ws.rs.core.Response) SourceResponse(ddf.catalog.operation.SourceResponse) CswSourceConfiguration(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration) CswSubscribe(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSubscribe) GetRecordsType(net.opengis.cat.csw.v_2_0_2.GetRecordsType) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) AcknowledgementType(net.opengis.cat.csw.v_2_0_2.AcknowledgementType) Test(org.junit.Test)

Example 55 with CswSourceConfiguration

use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration in project ddf by codice.

the class GetRecordsMessageBodyReaderTest method testPartialContentResponseHandling.

@Test
public void testPartialContentResponseHandling() throws Exception {
    CswSourceConfiguration config = new CswSourceConfiguration(encryptionService, permissions);
    config.setMetacardCswMappings(DefaultCswRecordMap.getCswToMetacardAttributeNames());
    config.setOutputSchema(CswConstants.CSW_OUTPUT_SCHEMA);
    GetRecordsMessageBodyReader reader = new GetRecordsMessageBodyReader(mockProvider, config);
    String sampleData = "SampleData";
    byte[] data = sampleData.getBytes();
    CswRecordCollection cswRecords = null;
    try (ByteArrayInputStream dataInputStream = new ByteArrayInputStream(data)) {
        MultivaluedMap<String, String> httpHeaders = new MultivaluedHashMap<>();
        httpHeaders.add(CswConstants.PRODUCT_RETRIEVAL_HTTP_HEADER, "TRUE");
        httpHeaders.add(HttpHeaders.CONTENT_DISPOSITION, String.format("inline; filename=ResourceName"));
        httpHeaders.add(HttpHeaders.CONTENT_RANGE, String.format("bytes 1-%d/%d", sampleData.length() - 1, sampleData.length()));
        MediaType mediaType = new MediaType("text", "plain");
        cswRecords = reader.readFrom(CswRecordCollection.class, null, null, mediaType, httpHeaders, dataInputStream);
    }
    Resource resource = cswRecords.getResource();
    // assert that the CswRecordCollection properly extracted the bytes skipped from the Partial
    // Content response
    assertThat(cswRecords.getResourceProperties().get(GetRecordsMessageBodyReader.BYTES_SKIPPED), is(1L));
    // assert that the input stream has not been skipped at this stage. Since AbstractCswSource has
    // the number
    // of bytes that was attempted to be skipped, the stream must be aligned there instead.
    assertThat(resource.getByteArray(), is(data));
}
Also used : CswSourceConfiguration(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) Resource(ddf.catalog.resource.Resource) MediaType(javax.ws.rs.core.MediaType) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Aggregations

CswSourceConfiguration (org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration)70 Test (org.junit.Test)60 FilterType (net.opengis.filter.v_1_1_0.FilterType)24 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)20 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)15 ByteArrayInputStream (java.io.ByteArrayInputStream)14 Matchers.anyString (org.mockito.Matchers.anyString)14 CswRecordCollection (org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection)11 Matchers.containsString (org.hamcrest.Matchers.containsString)9 InputStream (java.io.InputStream)8 HashMap (java.util.HashMap)8 DateTime (org.joda.time.DateTime)8 ResourceResponse (ddf.catalog.operation.ResourceResponse)6 SourceResponse (ddf.catalog.operation.SourceResponse)6 Resource (ddf.catalog.resource.Resource)6 MediaType (javax.ws.rs.core.MediaType)6 Response (javax.ws.rs.core.Response)6 AcknowledgementType (net.opengis.cat.csw.v_2_0_2.AcknowledgementType)6 GetRecordsType (net.opengis.cat.csw.v_2_0_2.GetRecordsType)6 CswSubscribe (org.codice.ddf.spatial.ogc.csw.catalog.common.CswSubscribe)6