use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection in project ddf by codice.
the class CswEndpointTest method testRetrieveProductGetRecordByIdWithRange.
@Test
public void testRetrieveProductGetRecordByIdWithRange() throws IOException, ResourceNotFoundException, ResourceNotSupportedException, CswException {
final GetRecordByIdRequest getRecordByIdRequest = new GetRecordByIdRequest();
getRecordByIdRequest.setId("123");
getRecordByIdRequest.setOutputFormat(MediaType.APPLICATION_OCTET_STREAM);
getRecordByIdRequest.setOutputSchema(OCTET_STREAM_OUTPUT_SCHEMA);
setUpMocksForProductRetrieval(true);
CswRecordCollection cswRecordCollection = csw.getRecordById(getRecordByIdRequest, RANGE_VALUE);
assertThat(cswRecordCollection.getResource(), is(notNullValue()));
}
use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection in project ddf by codice.
the class GetRecordsResponseConverterTest method testUnmarshalGetRecordsResponseConversionWithEmptyBoundingBox.
@Test
public void testUnmarshalGetRecordsResponseConversionWithEmptyBoundingBox() {
XStream xstream = createXstream(new WstxDriver());
xstream.setClassLoader(this.getClass().getClassLoader());
GetRecordsResponseConverter grrc = new GetRecordsResponseConverter(mockProvider);
xstream.registerConverter(grrc);
xstream.alias("GetRecordsResponse", CswRecordCollection.class);
String xml = "<csw:GetRecordsResponse xmlns:csw=\"http://www.opengis.net/cat/csw\">\r\n" + " <csw:SearchStatus status=\"subset\" timestamp=\"2013-05-01T02:13:36+0200\"/>\r\n" + " <csw:SearchResults elementSet=\"full\" nextRecord=\"11\" numberOfRecordsMatched=\"479\" numberOfRecordsReturned=\"10\" recordSchema=\"csw:Record\">\r\n" + " <csw:Record xmlns:csw=\"http://www.opengis.net/cat/csw\">\r\n" + " <dc:identifier xmlns:dc=\"http://purl.org/dc/elements/1.1/\">{8C1F6297-EC96-4302-A01E-14988C9149FD}</dc:identifier>\r\n" + " <dc:title xmlns:dc=\"http://purl.org/dc/elements/1.1/\">title 1</dc:title>\r\n" + " <dct:modified xmlns:dct=\"http://purl.org/dc/terms/\">2008-12-15</dct:modified>\r\n" + " <dc:subject xmlns:dc=\"http://purl.org/dc/elements/1.1/\">subject 1</dc:subject>\r\n" + " <dc:subject xmlns:dc=\"http://purl.org/dc/elements/1.1/\">second subject</dc:subject>\r\n" + " <dct:abstract xmlns:dct=\"http://purl.org/dc/terms/\">abstract 1</dct:abstract>\r\n" + " <dc:rights xmlns:dc=\"http://purl.org/dc/elements/1.1/\">copyright 1</dc:rights>\r\n" + " <dc:rights xmlns:dc=\"http://purl.org/dc/elements/1.1/\">copyright 2</dc:rights>\r\n" + " <dc:language xmlns:dc=\"http://purl.org/dc/elements/1.1/\">english</dc:language> \r\n" + " <ows:BoundingBox xmlns:ows=\"http://www.opengis.net/ows\" crs=\"EPSG:RD_New (28992)\">\r\n" + " <ows:LowerCorner></ows:LowerCorner>\r\n" + " <ows:UpperCorner></ows:UpperCorner>\r\n" + " </ows:BoundingBox> \r\n" + " <dc:type xmlns:dc=\"http://purl.org/dc/elements/1.1/\">dataset</dc:type>\r\n" + " <dc:format xmlns:dc=\"http://purl.org/dc/elements/1.1/\">Shapefile</dc:format> \r\n" + " </csw:Record>\r\n" + " </csw:SearchResults>\r\n" + "</csw:GetRecordsResponse>";
InputStream inStream = IOUtils.toInputStream(xml);
CswRecordCollection cswRecords = (CswRecordCollection) xstream.fromXML(inStream);
IOUtils.closeQuietly(inStream);
assertThat(cswRecords.getNumberOfRecordsReturned(), is(10L));
assertThat(cswRecords.getNumberOfRecordsMatched(), is(479L));
List<Metacard> metacards = cswRecords.getCswRecords();
assertThat(metacards, not(nullValue()));
assertThat(metacards.size(), is(1));
}
use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection in project ddf by codice.
the class GetRecordsResponseConverterTest method testMarshalRecordCollectionHits.
@Ignore
@Test
public void testMarshalRecordCollectionHits() throws UnsupportedEncodingException, JAXBException {
final int totalResults = 5;
XStream xstream = createXStream(CswConstants.GET_RECORDS_RESPONSE);
GetRecordsType getRecords = new GetRecordsType();
QueryType query = new QueryType();
ElementSetNameType set = new ElementSetNameType();
set.setValue(ElementSetType.FULL);
query.setElementSetName(set);
ObjectFactory objectFactory = new ObjectFactory();
getRecords.setAbstractQuery(objectFactory.createAbstractQuery(query));
CswRecordCollection collection = createCswRecordCollection(getRecords, totalResults);
collection.setElementSetType(ElementSetType.FULL);
collection.setResultType(ResultType.HITS);
String xml = xstream.toXML(collection);
// Verify the context arguments were set correctly
verify(mockProvider, never()).marshal(any(Object.class), any(HierarchicalStreamWriter.class), any(MarshallingContext.class));
JAXBElement<GetRecordsResponseType> jaxb = (JAXBElement<GetRecordsResponseType>) getJaxBContext().createUnmarshaller().unmarshal(new ByteArrayInputStream(xml.getBytes("UTF-8")));
GetRecordsResponseType response = jaxb.getValue();
// Assert the GetRecordsResponse elements and attributes
assertThat(response, not(nullValue()));
SearchResultsType resultsType = response.getSearchResults();
assertThat(resultsType, not(nullValue()));
assertThat(resultsType.getElementSet(), is(ElementSetType.FULL));
assertThat(resultsType.getNumberOfRecordsMatched().intValue(), is(totalResults));
assertThat(resultsType.getNumberOfRecordsReturned().intValue(), is(0));
assertThat(resultsType.getRecordSchema(), is(CswConstants.CSW_OUTPUT_SCHEMA));
}
use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection in project ddf by codice.
the class GetRecordsResponseConverterTest method testUnmarshalGetRecordsResponseFull.
/**
* This test actually runs the full thread of calling the GetRecordsResponseConverter then calls
* the CswInputTransformer.
*/
@Test
public void testUnmarshalGetRecordsResponseFull() {
XStream xstream = createXstream(new WstxDriver());
xstream.setClassLoader(this.getClass().getClassLoader());
CswTransformProvider provider = new CswTransformProvider(null, mockInputManager);
when(mockInputManager.getTransformerBySchema(anyString())).thenReturn(new CswRecordConverter(CswRecordConverterTest.getCswMetacardType()));
xstream.registerConverter(new GetRecordsResponseConverter(provider));
xstream.alias("GetRecordsResponse", CswRecordCollection.class);
String xml = "<csw:GetRecordsResponse xmlns:csw=\"http://www.opengis.net/cat/csw\">\r\n" + " <csw:SearchStatus status=\"subset\" timestamp=\"2013-05-01T02:13:36+0200\"/>\r\n" + " <csw:SearchResults elementSet=\"full\" nextRecord=\"11\" numberOfRecordsMatched=\"479\" numberOfRecordsReturned=\"10\" recordSchema=\"csw:Record\">\r\n" + " <csw:Record xmlns:csw=\"http://www.opengis.net/cat/csw\">\r\n" + " <dc:identifier xmlns:dc=\"http://purl.org/dc/elements/1.1/\">{8C1F6297-EC96-4302-A01E-14988C9149FD}</dc:identifier>\r\n" + " <dc:title xmlns:dc=\"http://purl.org/dc/elements/1.1/\">title 1</dc:title>\r\n" + " <dct:modified xmlns:dct=\"http://purl.org/dc/terms/\">2008-12-15</dct:modified>\r\n" + " <dc:subject xmlns:dc=\"http://purl.org/dc/elements/1.1/\">subject 1</dc:subject>\r\n" + " <dc:subject xmlns:dc=\"http://purl.org/dc/elements/1.1/\">second subject</dc:subject>\r\n" + " <dct:abstract xmlns:dct=\"http://purl.org/dc/terms/\">abstract 1</dct:abstract>\r\n" + " <dc:rights xmlns:dc=\"http://purl.org/dc/elements/1.1/\">copyright 1</dc:rights>\r\n" + " <dc:rights xmlns:dc=\"http://purl.org/dc/elements/1.1/\">copyright 2</dc:rights>\r\n" + " <dc:language xmlns:dc=\"http://purl.org/dc/elements/1.1/\">english</dc:language> \r\n" + " <ows:BoundingBox xmlns:ows=\"http://www.opengis.net/ows\" crs=\"EPSG:RD_New (28992)\">\r\n" + " <ows:LowerCorner>5.121 52.139</ows:LowerCorner>\r\n" + " <ows:UpperCorner>4.468 52.517</ows:UpperCorner>\r\n" + " </ows:BoundingBox> \r\n" + " <dc:type xmlns:dc=\"http://purl.org/dc/elements/1.1/\">dataset</dc:type>\r\n" + " <dc:format xmlns:dc=\"http://purl.org/dc/elements/1.1/\">Shapefile</dc:format> \r\n" + " </csw:Record>\r\n" + " <csw:Record xmlns:csw=\"http://www.opengis.net/cat/csw\">\r\n" + " <dc:identifier xmlns:dc=\"http://purl.org/dc/elements/1.1/\">{23362852-F370-4369-B0B2-BE74B2859614}</dc:identifier>\r\n" + " <dc:title xmlns:dc=\"http://purl.org/dc/elements/1.1/\">mc2 title</dc:title>\r\n" + " <dct:modified xmlns:dct=\"http://purl.org/dc/terms/\">2010-12-15</dct:modified>\r\n" + " <dc:subject xmlns:dc=\"http://purl.org/dc/elements/1.1/\">first subject</dc:subject>\r\n" + " <dc:subject xmlns:dc=\"http://purl.org/dc/elements/1.1/\">subject 2</dc:subject>\r\n" + " <dct:abstract xmlns:dct=\"http://purl.org/dc/terms/\">mc2 abstract</dct:abstract>\r\n" + " <dc:rights xmlns:dc=\"http://purl.org/dc/elements/1.1/\">first copyright</dc:rights>\r\n" + " <dc:rights xmlns:dc=\"http://purl.org/dc/elements/1.1/\">second copyright</dc:rights>\r\n" + " <dc:language xmlns:dc=\"http://purl.org/dc/elements/1.1/\">english</dc:language>\r\n" + " <ows:BoundingBox xmlns:ows=\"http://www.opengis.net/ows\" crs=\"EPSG:RD_New (28992)\">\r\n" + " <ows:LowerCorner>6.121 53.139</ows:LowerCorner>\r\n" + " <ows:UpperCorner>5.468 53.517</ows:UpperCorner>\r\n" + " </ows:BoundingBox>\r\n" + " <dc:type xmlns:dc=\"http://purl.org/dc/elements/1.1/\">dataset 2</dc:type>\r\n" + " <dc:format xmlns:dc=\"http://purl.org/dc/elements/1.1/\">Shapefile 2</dc:format>\r\n" + " </csw:Record>\r\n" + " </csw:SearchResults>\r\n" + "</csw:GetRecordsResponse>";
InputStream inStream = IOUtils.toInputStream(xml);
CswRecordCollection cswRecords = (CswRecordCollection) xstream.fromXML(inStream);
IOUtils.closeQuietly(inStream);
List<Metacard> metacards = cswRecords.getCswRecords();
assertThat(metacards, not(nullValue()));
assertThat(metacards.size(), is(2));
// verify first metacard's values
Metacard mc = metacards.get(0);
assertThat(mc, not(nullValue()));
Map<String, Object> expectedValues = new HashMap<>();
expectedValues.put(Core.ID, "{8C1F6297-EC96-4302-A01E-14988C9149FD}");
expectedValues.put(Core.TITLE, "title 1");
String expectedModifiedDateStr = "2008-12-15";
DateTimeFormatter dateFormatter = ISODateTimeFormat.dateOptionalTimeParser();
Date expectedModifiedDate = dateFormatter.parseDateTime(expectedModifiedDateStr).toDate();
expectedValues.put(Core.MODIFIED, expectedModifiedDate);
expectedValues.put(Topic.CATEGORY, new String[] { "subject 1", "second subject" });
expectedValues.put(Core.DESCRIPTION, new String[] { "abstract 1" });
expectedValues.put(Core.LANGUAGE, new String[] { "english" });
expectedValues.put(Media.FORMAT, "Shapefile");
expectedValues.put(Metacard.CONTENT_TYPE, "dataset");
expectedValues.put(Core.LOCATION, "POLYGON ((5.121 52.139, 4.468 52.139, 4.468 52.517, 5.121 52.517, 5.121 52.139))");
assertMetacard(mc, expectedValues);
expectedValues.clear();
// verify second metacard's values
mc = metacards.get(1);
assertThat(mc, not(nullValue()));
expectedValues = new HashMap<>();
expectedValues.put(Core.ID, "{23362852-F370-4369-B0B2-BE74B2859614}");
expectedValues.put(Core.TITLE, "mc2 title");
expectedModifiedDateStr = "2010-12-15";
dateFormatter = ISODateTimeFormat.dateOptionalTimeParser();
expectedModifiedDate = dateFormatter.parseDateTime(expectedModifiedDateStr).toDate();
expectedValues.put(Core.MODIFIED, expectedModifiedDate);
expectedValues.put(Topic.CATEGORY, new String[] { "first subject", "subject 2" });
expectedValues.put(Core.DESCRIPTION, new String[] { "mc2 abstract" });
expectedValues.put(Core.LANGUAGE, new String[] { "english" });
expectedValues.put(Media.FORMAT, "Shapefile 2");
expectedValues.put(Metacard.CONTENT_TYPE, "dataset 2");
expectedValues.put(Core.LOCATION, "POLYGON ((6.121 53.139, 5.468 53.139, 5.468 53.517, 6.121 53.517, 6.121 53.139))");
assertMetacard(mc, expectedValues);
expectedValues.clear();
}
use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection in project ddf by codice.
the class GetRecordsResponseConverterTest method testMarshalRecordCollectionGetBrief.
@Ignore
@Test
public void testMarshalRecordCollectionGetBrief() throws UnsupportedEncodingException, JAXBException {
final int totalResults = 5;
XStream xstream = createXStream(CswConstants.GET_RECORDS_RESPONSE);
GetRecordsType getRecords = new GetRecordsType();
QueryType query = new QueryType();
ElementSetNameType set = new ElementSetNameType();
set.setValue(ElementSetType.BRIEF);
query.setElementSetName(set);
ObjectFactory objectFactory = new ObjectFactory();
getRecords.setAbstractQuery(objectFactory.createAbstractQuery(query));
CswRecordCollection collection = createCswRecordCollection(getRecords, totalResults);
collection.setElementSetType(ElementSetType.BRIEF);
ArgumentCaptor<MarshallingContext> captor = ArgumentCaptor.forClass(MarshallingContext.class);
String xml = xstream.toXML(collection);
// Verify the context arguments were set correctly
verify(mockProvider, times(totalResults)).marshal(any(Object.class), any(HierarchicalStreamWriter.class), captor.capture());
MarshallingContext context = captor.getValue();
assertThat(context, not(nullValue()));
assertThat(context.get(CswConstants.OUTPUT_SCHEMA_PARAMETER), is(CswConstants.CSW_OUTPUT_SCHEMA));
assertThat(context.get(CswConstants.ELEMENT_SET_TYPE), is(ElementSetType.BRIEF));
JAXBElement<GetRecordsResponseType> jaxb = (JAXBElement<GetRecordsResponseType>) getJaxBContext().createUnmarshaller().unmarshal(new ByteArrayInputStream(xml.getBytes("UTF-8")));
GetRecordsResponseType response = jaxb.getValue();
// Assert the GetRecordsResponse elements and attributes
assertThat(response, not(nullValue()));
SearchResultsType resultsType = response.getSearchResults();
assertThat(resultsType, not(nullValue()));
assertThat(resultsType.getElementSet(), is(ElementSetType.BRIEF));
assertThat(resultsType.getNumberOfRecordsMatched().intValue(), is(totalResults));
assertThat(resultsType.getNumberOfRecordsReturned().intValue(), is(totalResults));
assertThat(resultsType.getRecordSchema(), is(CswConstants.CSW_OUTPUT_SCHEMA));
}
Aggregations