use of com.thoughtworks.xstream.io.xml.WstxDriver 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.io.xml.WstxDriver 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.io.xml.WstxDriver 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,"));
}
use of com.thoughtworks.xstream.io.xml.WstxDriver in project ddf by codice.
the class TestGenericFeatureConverter method testReadCdata.
@Test
//DDF-733
@Ignore
public void testReadCdata() {
XStream xstream = new XStream(new WstxDriver());
String contents = "<tag>my cdata contents</tag>";
String xml = "<string><![CDATA[" + contents + "]]></string>";
String results = (String) xstream.fromXML(xml);
assertThat(contents, is(results));
}
use of com.thoughtworks.xstream.io.xml.WstxDriver in project ddf by codice.
the class TestGenericFeatureConverter method testUnmarshalNoMetacardTypeRegisteredInConverter.
@Test(expected = IllegalArgumentException.class)
public void testUnmarshalNoMetacardTypeRegisteredInConverter() throws Throwable {
XStream xstream = new XStream(new WstxDriver());
xstream.registerConverter(new GenericFeatureConverter());
xstream.registerConverter(new GmlGeometryConverter());
xstream.alias(FEATURE_TYPE, Metacard.class);
InputStream is = TestGenericFeatureConverter.class.getResourceAsStream("/video_data_set_1.xml");
try {
xstream.fromXML(is);
} catch (Exception e) {
throw e.getCause();
}
}
Aggregations