Search in sources :

Example 56 with CswSourceConfiguration

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

the class GetRecordsMessageBodyReaderTest method testReadProductData.

@Test
public void testReadProductData() 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"));
        MediaType mediaType = new MediaType("text", "plain");
        cswRecords = reader.readFrom(CswRecordCollection.class, null, null, mediaType, httpHeaders, dataInputStream);
    }
    Resource resource = cswRecords.getResource();
    assertThat(resource, notNullValue());
    assertThat(resource.getName(), is("ResourceName"));
    assertThat(resource.getMimeType().toString(), is(MediaType.TEXT_PLAIN));
    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)

Example 57 with CswSourceConfiguration

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

the class GetRecordsMessageBodyReaderTest method testConfigurationArguments.

@Test
public void testConfigurationArguments() throws Exception {
    CswSourceConfiguration config = new CswSourceConfiguration(encryptionService, permissions);
    config.setMetacardCswMappings(DefaultCswRecordMap.getCswToMetacardAttributeNames());
    config.setOutputSchema(CswConstants.CSW_OUTPUT_SCHEMA);
    config.setCswAxisOrder(CswAxisOrder.LAT_LON);
    config.putMetacardCswMapping(Core.THUMBNAIL, CswConstants.CSW_REFERENCES);
    config.putMetacardCswMapping(Core.RESOURCE_URI, CswConstants.CSW_SOURCE);
    GetRecordsMessageBodyReader reader = new GetRecordsMessageBodyReader(mockProvider, config);
    ArgumentCaptor<UnmarshallingContext> captor = ArgumentCaptor.forClass(UnmarshallingContext.class);
    try (InputStream is = GetRecordsMessageBodyReaderTest.class.getResourceAsStream("/getRecordsResponse.xml")) {
        MultivaluedMap<String, String> httpHeaders = new MultivaluedHashMap<>();
        reader.readFrom(CswRecordCollection.class, null, null, null, httpHeaders, is);
    }
    // Verify the context arguments were set correctly
    verify(mockProvider, times(1)).unmarshal(any(HierarchicalStreamReader.class), captor.capture());
    UnmarshallingContext context = captor.getValue();
    // Assert the properties needed for CswRecordConverter
    assertThat(context.get(CswConstants.CSW_MAPPING), notNullValue());
    Object cswMapping = context.get(CswConstants.CSW_MAPPING);
    assertThat(cswMapping, instanceOf(Map.class));
    assertThat(context.get(Core.RESOURCE_URI), instanceOf(String.class));
    assertThat(context.get(Core.RESOURCE_URI), is(CswConstants.CSW_SOURCE));
    assertThat(context.get(Core.THUMBNAIL), instanceOf(String.class));
    assertThat(context.get(Core.THUMBNAIL), is(CswConstants.CSW_REFERENCES));
    assertThat(context.get(CswConstants.AXIS_ORDER_PROPERTY), instanceOf(CswAxisOrder.class));
    assertThat(context.get(CswConstants.AXIS_ORDER_PROPERTY), is(CswAxisOrder.LAT_LON));
    // Assert the output Schema is set.
    assertThat(context.get(CswConstants.OUTPUT_SCHEMA_PARAMETER), instanceOf(String.class));
    assertThat(context.get(CswConstants.OUTPUT_SCHEMA_PARAMETER), is(CswConstants.CSW_OUTPUT_SCHEMA));
    assertThat(context.get(CswConstants.TRANSFORMER_LOOKUP_KEY), instanceOf(String.class));
    assertThat(context.get(CswConstants.TRANSFORMER_LOOKUP_KEY), is(TransformerManager.SCHEMA));
    assertThat(context.get(CswConstants.TRANSFORMER_LOOKUP_VALUE), instanceOf(String.class));
    assertThat(context.get(CswConstants.TRANSFORMER_LOOKUP_VALUE), is(CswConstants.CSW_OUTPUT_SCHEMA));
}
Also used : CswSourceConfiguration(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) CswAxisOrder(org.codice.ddf.spatial.ogc.csw.catalog.common.CswAxisOrder) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) HierarchicalStreamReader(com.thoughtworks.xstream.io.HierarchicalStreamReader) UnmarshallingContext(com.thoughtworks.xstream.converters.UnmarshallingContext) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) Map(java.util.Map) DefaultCswRecordMap(org.codice.ddf.spatial.ogc.csw.catalog.common.converter.DefaultCswRecordMap) HashMap(java.util.HashMap) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) MultivaluedMap(javax.ws.rs.core.MultivaluedMap) Test(org.junit.Test)

Example 58 with CswSourceConfiguration

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

the class GetRecordsMessageBodyReaderTest method testExceptionReport.

@Test(expected = WebApplicationException.class)
public void testExceptionReport() throws Exception {
    GetRecordsMessageBodyReader reader = new GetRecordsMessageBodyReader(mockProvider, new CswSourceConfiguration(encryptionService, permissions));
    try (InputStream is = GetRecordsMessageBodyReaderTest.class.getResourceAsStream("/exceptionReport.xml")) {
        MultivaluedMap<String, String> httpHeaders = new MultivaluedHashMap<>();
        reader.readFrom(CswRecordCollection.class, null, null, null, httpHeaders, is);
    }
}
Also used : CswSourceConfiguration(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration) MultivaluedHashMap(javax.ws.rs.core.MultivaluedHashMap) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Matchers.containsString(org.hamcrest.Matchers.containsString) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 59 with CswSourceConfiguration

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

the class GetRecordsMessageBodyReaderTest method testPartialContentNotSupportedHandling.

@Test
public void testPartialContentNotSupportedHandling() 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"));
        MediaType mediaType = new MediaType("text", "plain");
        cswRecords = reader.readFrom(CswRecordCollection.class, null, null, mediaType, httpHeaders, dataInputStream);
    }
    Resource resource = cswRecords.getResource();
    // assert that the CswRecordCollection property is not set if the server does not support
    // Partial Content responses
    assertThat(cswRecords.getResourceProperties().get(GetRecordsMessageBodyReader.BYTES_SKIPPED), nullValue());
    // 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)

Example 60 with CswSourceConfiguration

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

the class CswCqlFilterTest method testDuringAlteredEffectiveDateMapping.

@Test
public void testDuringAlteredEffectiveDateMapping() throws UnsupportedQueryException {
    DateTime startDate = new DateTime(2013, 5, 1, 0, 0, 0, 0);
    DateTime endDate = new DateTime(2013, 12, 31, 0, 0, 0, 0);
    String replacedTemporalProperty = "myEffectiveDate";
    CswSourceConfiguration cswSourceConfiguration = initCswSourceConfiguration(CswAxisOrder.LAT_LON, CswConstants.CSW_TYPE, replacedTemporalProperty, createdDateMapping, modifiedDateMapping, CswConstants.CSW_IDENTIFIER);
    CswFilterDelegate cswFilterDelegate = initDefaultCswFilterDelegate(cswSourceConfiguration);
    FilterType filterType = cswFilterDelegate.during(propertyNameEffective, startDate.toCalendar(null).getTime(), endDate.toCalendar(null).getTime());
    String cqlText = CswCqlTextFilter.getInstance().getCqlText(filterType);
    DateTimeFormatter fmt = ISODateTimeFormat.dateTime();
    String startDateStr = fmt.print(startDate);
    String endDateStr = fmt.print(endDate);
    String testResponse = during.replace(REPLACE_START_DATE, startDateStr).replace(REPLACE_END_DATE, endDateStr).replace(REPLACE_TEMPORAL_PROPERTY, replacedTemporalProperty);
    assertThat(cqlText, is(testResponse));
}
Also used : CswSourceConfiguration(org.codice.ddf.spatial.ogc.csw.catalog.common.CswSourceConfiguration) FilterType(net.opengis.filter.v_1_1_0.FilterType) DateTimeFormatter(org.joda.time.format.DateTimeFormatter) DateTime(org.joda.time.DateTime) 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