Search in sources :

Example 26 with CswSourceConfiguration

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

the class TestGetRecordsMessageBodyReader method testPartialContentResponseHandling.

@Test
public void testPartialContentResponseHandling() throws Exception {
    CswSourceConfiguration config = new CswSourceConfiguration(encryptionService);
    config.setMetacardCswMappings(DefaultCswRecordMap.getCswToMetacardAttributeNames());
    config.setOutputSchema(CswConstants.CSW_OUTPUT_SCHEMA);
    GetRecordsMessageBodyReader reader = new GetRecordsMessageBodyReader(mockProvider, config);
    String sampleData = "SampleData";
    byte[] data = sampleData.getBytes();
    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");
    CswRecordCollection 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) Test(org.junit.Test)

Example 27 with CswSourceConfiguration

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

the class TestGetRecordsMessageBodyReader method testGetMultipleMetacardsWithForeignText.

// verifies UTF-8 encoding configured properly when XML includes foreign text with special characters
@Test
public void testGetMultipleMetacardsWithForeignText() throws Exception {
    List<Metacard> inputMetacards = new ArrayList<>();
    MetacardImpl metacard = new MetacardImpl(BasicTypes.BASIC_METACARD);
    inputMetacards.add(metacard);
    CswRecordCollection collection = new CswRecordCollection();
    collection.setCswRecords(inputMetacards);
    when(mockProvider.unmarshal(any(), any())).thenReturn(collection);
    CswSourceConfiguration config = new CswSourceConfiguration(encryptionService);
    config.setMetacardCswMappings(DefaultCswRecordMap.getCswToMetacardAttributeNames());
    config.setOutputSchema(CswConstants.CSW_OUTPUT_SCHEMA);
    GetRecordsMessageBodyReader reader = new GetRecordsMessageBodyReader(mockProvider, config);
    InputStream is = TestGetRecordsMessageBodyReader.class.getResourceAsStream("/geomaticsGetRecordsResponse.xml");
    MultivaluedMap<String, String> httpHeaders = new MultivaluedHashMap<>();
    CswRecordCollection cswRecords = reader.readFrom(CswRecordCollection.class, null, null, null, httpHeaders, is);
    List<Metacard> metacards = cswRecords.getCswRecords();
    assertThat(metacards, contains(metacard));
}
Also used : CswSourceConfiguration(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) Metacard(ddf.catalog.data.Metacard) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) ArrayList(java.util.ArrayList) CswRecordCollection(org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection) MetacardImpl(ddf.catalog.data.impl.MetacardImpl) Test(org.junit.Test)

Example 28 with CswSourceConfiguration

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

the class TestCswSource 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);
    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 : Response(javax.ws.rs.core.Response) ResourceResponse(ddf.catalog.operation.ResourceResponse) 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) Matchers.anyString(org.mockito.Matchers.anyString) AcknowledgementType(net.opengis.cat.csw.v_2_0_2.AcknowledgementType) Test(org.junit.Test)

Example 29 with CswSourceConfiguration

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

the class TestCswSource method testRefreshWithEmptyConfiguration.

@Test
public void testRefreshWithEmptyConfiguration() throws SecurityServiceException {
    AbstractCswSource cswSource = getCswSource(null, null, "type", null, null, encryptionService);
    CswSourceConfiguration defaultCswSourceConfiguration = getStandardCswSourceConfiguration(null, null, null, encryptionService);
    Map<String, Object> configuration = new HashMap<>();
    // Assert that the default configuration is set
    assertDefaultCswSourceConfiguration(cswSource.cswSourceConfiguration, defaultCswSourceConfiguration);
    cswSource.refresh(configuration);
    // Assert that the configuration does not change with an empty map
    assertDefaultCswSourceConfiguration(cswSource.cswSourceConfiguration, defaultCswSourceConfiguration);
}
Also used : CswSourceConfiguration(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration) HashMap(java.util.HashMap) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 30 with CswSourceConfiguration

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

the class TestCswSource method testRefreshWithNullConfiguration.

@Test
public void testRefreshWithNullConfiguration() throws SecurityServiceException {
    AbstractCswSource cswSource = getCswSource(null, null, "type", null, null, encryptionService);
    CswSourceConfiguration defaultCswSourceConfiguration = getStandardCswSourceConfiguration(null, null, null, encryptionService);
    // 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)

Aggregations

CswSourceConfiguration (org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration)34 Test (org.junit.Test)29 FilterType (net.opengis.filter.v_1_1_0.FilterType)12 DateTimeFormatter (org.joda.time.format.DateTimeFormatter)10 ByteArrayInputStream (java.io.ByteArrayInputStream)6 MultivaluedHashMap (javax.ws.rs.core.MultivaluedHashMap)6 CswRecordCollection (org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection)5 Matchers.anyString (org.mockito.Matchers.anyString)5 HashMap (java.util.HashMap)4 DateTime (org.joda.time.DateTime)4 ResourceResponse (ddf.catalog.operation.ResourceResponse)3 SourceResponse (ddf.catalog.operation.SourceResponse)3 Resource (ddf.catalog.resource.Resource)3 InputStream (java.io.InputStream)3 ArrayList (java.util.ArrayList)3 MediaType (javax.ws.rs.core.MediaType)3 Response (javax.ws.rs.core.Response)3 AcknowledgementType (net.opengis.cat.csw.v_2_0_2.AcknowledgementType)3 GetRecordsType (net.opengis.cat.csw.v_2_0_2.GetRecordsType)3 CswSubscribe (org.codice.ddf.spatial.ogc.csw.catalog.common.CswSubscribe)3