Search in sources :

Example 6 with WstxDriver

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"));
}
Also used : WstxDriver(com.thoughtworks.xstream.io.xml.WstxDriver) Metacard(ddf.catalog.data.Metacard) DocumentBuilderFactory(javax.xml.parsers.DocumentBuilderFactory) DomReader(com.thoughtworks.xstream.io.xml.DomReader) DocumentBuilder(javax.xml.parsers.DocumentBuilder) XStream(com.thoughtworks.xstream.XStream) DataHolder(com.thoughtworks.xstream.converters.DataHolder) HierarchicalStreamReader(com.thoughtworks.xstream.io.HierarchicalStreamReader) Document(org.w3c.dom.Document) Test(org.junit.Test)

Example 7 with WstxDriver

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"));
}
Also used : WstxDriver(com.thoughtworks.xstream.io.xml.WstxDriver) Metacard(ddf.catalog.data.Metacard) XStream(com.thoughtworks.xstream.XStream) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 8 with WstxDriver

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,"));
}
Also used : WstxDriver(com.thoughtworks.xstream.io.xml.WstxDriver) Metacard(ddf.catalog.data.Metacard) HashMap(java.util.HashMap) XStream(com.thoughtworks.xstream.XStream) InputStream(java.io.InputStream) Wfs20FeatureCollection(org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.common.Wfs20FeatureCollection) FeatureConverter(org.codice.ddf.spatial.ogc.wfs.catalog.converter.FeatureConverter) MetacardMapper(org.codice.ddf.spatial.ogc.wfs.catalog.mapper.MetacardMapper) Test(org.junit.Test)

Example 9 with WstxDriver

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));
}
Also used : WstxDriver(com.thoughtworks.xstream.io.xml.WstxDriver) XStream(com.thoughtworks.xstream.XStream) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 10 with WstxDriver

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();
    }
}
Also used : WstxDriver(com.thoughtworks.xstream.io.xml.WstxDriver) GmlGeometryConverter(org.codice.ddf.spatial.ogc.wfs.catalog.converter.impl.GmlGeometryConverter) GenericFeatureConverter(org.codice.ddf.spatial.ogc.wfs.catalog.converter.impl.GenericFeatureConverter) XStream(com.thoughtworks.xstream.XStream) InputStream(java.io.InputStream) Test(org.junit.Test)

Aggregations

WstxDriver (com.thoughtworks.xstream.io.xml.WstxDriver)29 Test (org.junit.Test)28 XStream (com.thoughtworks.xstream.XStream)22 Metacard (ddf.catalog.data.Metacard)19 InputStream (java.io.InputStream)19 HashMap (java.util.HashMap)12 FeatureConverter (org.codice.ddf.spatial.ogc.wfs.catalog.converter.FeatureConverter)8 GmlGeometryConverter (org.codice.ddf.spatial.ogc.wfs.catalog.converter.impl.GmlGeometryConverter)8 HierarchicalStreamReader (com.thoughtworks.xstream.io.HierarchicalStreamReader)6 Wfs20FeatureCollection (org.codice.ddf.spatial.ogc.wfs.v2_0_0.catalog.common.Wfs20FeatureCollection)6 Matchers.anyString (org.mockito.Matchers.anyString)6 GenericFeatureConverter (org.codice.ddf.spatial.ogc.wfs.catalog.converter.impl.GenericFeatureConverter)5 UnmarshallingContext (com.thoughtworks.xstream.converters.UnmarshallingContext)4 ByteArrayInputStream (java.io.ByteArrayInputStream)4 StringWriter (java.io.StringWriter)4 Ignore (org.junit.Ignore)4 MarshallingContext (com.thoughtworks.xstream.converters.MarshallingContext)3 TreeMarshaller (com.thoughtworks.xstream.core.TreeMarshaller)3 TreeUnmarshaller (com.thoughtworks.xstream.core.TreeUnmarshaller)3 HierarchicalStreamWriter (com.thoughtworks.xstream.io.HierarchicalStreamWriter)3