use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection in project ddf by codice.
the class GetRecordsResponseConverterTest method testMarshalRecordCollectionGetElements.
@Ignore
@Test
public void testMarshalRecordCollectionGetElements() throws UnsupportedEncodingException, JAXBException {
final int totalResults = 5;
XStream xstream = createXStream(CswConstants.GET_RECORDS_RESPONSE);
GetRecordsType getRecords = new GetRecordsType();
QueryType query = new QueryType();
List<QName> elements = new LinkedList<>();
elements.add(CswConstants.CSW_TITLE_QNAME);
elements.add(CswConstants.CSW_SOURCE_QNAME);
query.setElementName(elements);
ObjectFactory objectFactory = new ObjectFactory();
getRecords.setAbstractQuery(objectFactory.createAbstractQuery(query));
CswRecordCollection collection = createCswRecordCollection(getRecords, totalResults);
collection.setElementName(elements);
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(nullValue()));
assertThat(context.get(CswConstants.ELEMENT_NAMES), is(notNullValue()));
List<QName> qnames = (List<QName>) context.get(CswConstants.ELEMENT_NAMES);
assertThat(qnames.contains(CswConstants.CSW_TITLE_QNAME), is(true));
assertThat(qnames.contains(CswConstants.CSW_SOURCE_QNAME), is(true));
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(nullValue()));
assertThat(resultsType.getNumberOfRecordsMatched().intValue(), is(totalResults));
assertThat(resultsType.getNumberOfRecordsReturned().intValue(), is(totalResults));
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 TestCswEndpoint method testPostGetRecordsValidate.
@Test
public void testPostGetRecordsValidate() throws CswException, UnsupportedQueryException, SourceUnavailableException, FederationException {
GetRecordsType grr = createDefaultPostRecordsRequest();
grr.setResultType(ResultType.VALIDATE);
QueryType query = new QueryType();
List<QName> typeNames = new ArrayList<>();
typeNames.add(new QName(CswConstants.CSW_OUTPUT_SCHEMA, VALID_TYPE, VALID_PREFIX));
query.setTypeNames(typeNames);
QueryConstraintType constraint = new QueryConstraintType();
constraint.setCqlText(CQL_CONTEXTUAL_LIKE_QUERY);
query.setConstraint(constraint);
JAXBElement<QueryType> jaxbQuery = new JAXBElement<>(cswQnameOutPutSchema, QueryType.class, query);
grr.setAbstractQuery(jaxbQuery);
when(catalogFramework.query(argument.capture())).thenReturn(getQueryResponse());
CswRecordCollection collection = csw.getRecords(grr);
assertThat(collection.getCswRecords(), is(empty()));
assertThat(collection.getNumberOfRecordsMatched(), is(0L));
assertThat(collection.getNumberOfRecordsReturned(), is(0L));
}
use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection in project ddf by codice.
the class TestCswEndpoint method testPostGetRecordsResults.
@Test
public void testPostGetRecordsResults() throws CswException, UnsupportedQueryException, SourceUnavailableException, FederationException {
GetRecordsType grr = createDefaultPostRecordsRequest();
grr.setResultType(ResultType.RESULTS);
QueryType query = new QueryType();
List<QName> typeNames = new ArrayList<>();
typeNames.add(new QName(CswConstants.CSW_OUTPUT_SCHEMA, VALID_TYPE, VALID_PREFIX));
query.setTypeNames(typeNames);
QueryConstraintType constraint = new QueryConstraintType();
constraint.setCqlText(CQL_CONTEXTUAL_LIKE_QUERY);
query.setConstraint(constraint);
ElementSetNameType esnt = new ElementSetNameType();
esnt.setValue(ElementSetType.SUMMARY);
query.setElementSetName(esnt);
JAXBElement<QueryType> jaxbQuery = new JAXBElement<>(cswQnameOutPutSchema, QueryType.class, query);
grr.setAbstractQuery(jaxbQuery);
final String exampleSchema = CswConstants.CSW_OUTPUT_SCHEMA;
grr.setOutputSchema(exampleSchema);
final String exampleMime = "application/xml";
grr.setOutputFormat(exampleMime);
CswRecordCollection collection = csw.getRecords(grr);
assertThat(collection.getMimeType(), is(exampleMime));
assertThat(collection.getOutputSchema(), is(exampleSchema));
assertThat(collection.getSourceResponse(), notNullValue());
assertThat(collection.getResultType(), is(ResultType.RESULTS));
assertThat(collection.getElementSetType(), is(ElementSetType.SUMMARY));
}
use of org.codice.ddf.spatial.ogc.csw.catalog.common.CswRecordCollection in project ddf by codice.
the class TestCswEndpoint method testPostRetrieveProductGetRecordByIdWithRange.
@Test
public void testPostRetrieveProductGetRecordByIdWithRange() throws IOException, ResourceNotFoundException, ResourceNotSupportedException, CswException {
final GetRecordByIdType getRecordByIdType = new GetRecordByIdType();
getRecordByIdType.setOutputFormat(MediaType.APPLICATION_OCTET_STREAM);
getRecordByIdType.setOutputSchema(OCTET_STREAM_OUTPUT_SCHEMA);
getRecordByIdType.setId(Collections.singletonList("123"));
setUpMocksForProductRetrieval(true);
CswRecordCollection cswRecordCollection = csw.getRecordById(getRecordByIdType, 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 TestGetRecordsResponseConverter method testUnmarshalGetRecordsResponseFull.
/**
* This test actually runs the full thread of calling the GetRecordsResponseConverter then calls the CswInputTransformer.
*/
@Test
public void testUnmarshalGetRecordsResponseFull() {
XStream xstream = new XStream(new WstxDriver());
xstream.setClassLoader(this.getClass().getClassLoader());
CswTransformProvider provider = new CswTransformProvider(null, mockInputManager);
when(mockInputManager.getTransformerBySchema(anyString())).thenReturn(new CswRecordConverter(TestCswRecordConverter.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();
}
Aggregations