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