use of com.thoughtworks.xstream.XStream in project ddf by codice.
the class TestCswRecordConverter method testUnmarshalCswRecordWithProductAndThumbnail.
@Test
public void testUnmarshalCswRecordWithProductAndThumbnail() throws URISyntaxException, IOException, JAXBException, ParserConfigurationException, SAXException {
XStream xstream = new XStream(new WstxDriver());
xstream.registerConverter(converter);
InputStream is = TestCswRecordConverter.class.getResourceAsStream("/Csw_Record.xml");
// get the URL to the thumbnail image and stick it in the xml string
// this makes the test filesystem independent
URL thumbnail = TestCswRecordConverter.class.getResource("/ddf_globe.png");
String xml = null;
if (thumbnail != null) {
StringWriter writer = new StringWriter();
IOUtils.copy(is, writer);
xml = writer.toString();
xml = xml.replace(THUMBNAIL_URL, thumbnail.toString());
}
xstream.alias("csw:Record", MetacardImpl.class);
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document doc = docBuilder.parse(IOUtils.toInputStream(xml));
HierarchicalStreamReader reader = new DomReader(doc);
DataHolder holder = xstream.newDataHolder();
Metacard mc = (Metacard) xstream.unmarshal(reader, null, holder);
assertThat(mc, notNullValue());
String productUrl = "http://example.com/product.pdf";
assertThat(mc.getAttribute(Core.RESOURCE_URI).getValue(), is(productUrl));
assertThat(mc.getThumbnail(), is(getThumbnailByteArray(thumbnail)));
}
use of com.thoughtworks.xstream.XStream in project ddf by codice.
the class TestCswRecordConverter method testUnmarshalNoNamespaceDeclaration.
@Test
public void testUnmarshalNoNamespaceDeclaration() throws IOException, SAXException {
XStream xstream = new XStream(new XppDriver());
xstream.registerConverter(converter);
xstream.alias("Record", MetacardImpl.class);
xstream.alias("csw:Record", MetacardImpl.class);
InputStream is = IOUtils.toInputStream(getRecordNoNamespaceDeclaration());
Metacard mc = (Metacard) xstream.fromXML(is);
Metacard expectedMetacard = getTestMetacard();
assertThat(mc, notNullValue());
assertThat(mc.getContentTypeName(), is(expectedMetacard.getContentTypeName()));
assertThat(mc.getCreatedDate(), is(expectedMetacard.getCreatedDate()));
assertThat(mc.getEffectiveDate(), is(expectedMetacard.getEffectiveDate()));
assertThat(mc.getId(), is(expectedMetacard.getId()));
assertThat(mc.getModifiedDate(), is(expectedMetacard.getModifiedDate()));
assertThat(mc.getTitle(), is(expectedMetacard.getTitle()));
assertThat(mc.getResourceURI(), is(expectedMetacard.getResourceURI()));
}
use of com.thoughtworks.xstream.XStream in project ddf by codice.
the class TestCswRecordConverter method testUnmarshalSingleCswRecordToMetacardContentTypeMapsToFormat.
@Test
public void testUnmarshalSingleCswRecordToMetacardContentTypeMapsToFormat() throws ParserConfigurationException, IOException, SAXException {
XStream xstream = new XStream(new WstxDriver());
xstream.registerConverter(converter);
xstream.alias("csw:Record", MetacardImpl.class);
DocumentBuilderFactory docFactory = DocumentBuilderFactory.newInstance();
DocumentBuilder docBuilder = docFactory.newDocumentBuilder();
Document doc = docBuilder.parse(TestCswRecordConverter.class.getResource("/Csw_Record.xml").getPath());
HierarchicalStreamReader reader = new DomReader(doc);
DataHolder holder = xstream.newDataHolder();
Metacard mc = (Metacard) xstream.unmarshal(reader, null, holder);
assertThat(mc, notNullValue());
assertThat(mc.getContentTypeName(), is("IMAGE-PRODUCT"));
assertThat(mc.getAttribute(Media.FORMAT).getValue(), is("PDF"));
}
use of com.thoughtworks.xstream.XStream in project ddf by codice.
the class TestCswRecordConverter method testUnmarshalCswRecordMultipleResourceUri.
@Test
public void testUnmarshalCswRecordMultipleResourceUri() {
XStream xstream = new XStream(new WstxDriver());
xstream.registerConverter(converter);
xstream.alias("Record", MetacardImpl.class);
InputStream is = TestCswRecordConverter.class.getResourceAsStream("/Csw_Record_MultiValueFields.xml");
Metacard mc = (Metacard) xstream.fromXML(is);
assertThat(mc.getResourceURI().toString(), is("http://example.com/product_supplement.pdf"));
}
use of com.thoughtworks.xstream.XStream in project ddf by codice.
the class TestGenericFeatureConverter method testUnmarshalMultiQueryFeatureCollectionXmlToObjectWithMetacardMapper.
/*
* This test will check is the MetacardMapper maps the feature value of 'states.STATE_NAME' to the metacard property 'title'.
*/
@Test
public void testUnmarshalMultiQueryFeatureCollectionXmlToObjectWithMetacardMapper() {
//Create Metacard Mapper
String featureProp = "ext.states.STATE_NAME";
String metacardAttr = "title";
MetacardMapper metacardMapper = mock(MetacardMapper.class);
when(metacardMapper.getMetacardAttribute(featureProp)).thenReturn(metacardAttr);
XStream xstream = new XStream(new WstxDriver());
FeatureCollectionConverterWfs20 fcConverter = new FeatureCollectionConverterWfs20();
Map<String, FeatureConverter> fcMap = new HashMap<String, FeatureConverter>();
GenericFeatureConverterWfs20 converter = new GenericFeatureConverterWfs20(metacardMapper);
fcMap.put("states", converter);
fcMap.put("streams", converter);
fcConverter.setFeatureConverterMap(fcMap);
xstream.registerConverter(fcConverter);
converter.setMetacardType(buildStatesMetacardType());
converter.setCoordinateOrder(GeospatialUtil.LAT_LON_ORDER);
xstream.registerConverter(converter);
xstream.alias("FeatureCollection", Wfs20FeatureCollection.class);
InputStream is = TestGenericFeatureConverter.class.getResourceAsStream("/geoserver_sample.xml");
Wfs20FeatureCollection wfc = (Wfs20FeatureCollection) xstream.fromXML(is);
assertEquals(7, wfc.getMembers().size());
Metacard mc = wfc.getMembers().get(0);
assertEquals(mc.getTitle(), "Missouri");
// Verifies that lat/lon was swapped to lon/lat order for the WKT conversion
// to set the metacard's location
assertTrue(mc.getLocation().startsWith("MULTIPOLYGON (((-89.104965 36.953869, -89.129585 36.86644, -89.166496 36.843422000000004,"));
}
Aggregations