Search in sources :

Example 21 with WstxDriver

use of com.thoughtworks.xstream.io.xml.WstxDriver in project ddf by codice.

the class TestGenericFeatureConverter method testGeoServerLatLonSwappingForPoint.

@Test
public void testGeoServerLatLonSwappingForPoint() {
    XStream xstream = new XStream(new WstxDriver());
    FeatureCollectionConverterWfs20 fcConverter = new FeatureCollectionConverterWfs20();
    Map<String, FeatureConverter> fcMap = new HashMap<String, FeatureConverter>();
    GenericFeatureConverterWfs20 converter = new GenericFeatureConverterWfs20();
    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_point.xml");
    Wfs20FeatureCollection wfc = (Wfs20FeatureCollection) xstream.fromXML(is);
    assertEquals(1, wfc.getMembers().size());
    Metacard mc = wfc.getMembers().get(0);
    assertEquals(mc.getId(), "states.10");
    // Verifies that lat/lon was swapped to lon/lat order for the WKT conversion
    // to set the metacard's location
    assertTrue(mc.getLocation().startsWith("POINT (-123.26 49.41)"));
}
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) Test(org.junit.Test)

Example 22 with WstxDriver

use of com.thoughtworks.xstream.io.xml.WstxDriver in project ddf by codice.

the class TestGenericFeatureConverter method testUnmarshalSingleFeatureXmlToObject.

@Test
//DDF-733
@Ignore
public void testUnmarshalSingleFeatureXmlToObject() {
    XStream xstream = new XStream(new WstxDriver());
    MetacardType metacardType = buildMetacardType();
    GenericFeatureConverterWfs20 converter = new GenericFeatureConverterWfs20();
    converter.setMetacardType(buildMetacardType());
    converter.setSourceId(SOURCE_ID);
    converter.setCoordinateOrder(GeospatialUtil.LAT_LON_ORDER);
    xstream.registerConverter(converter);
    xstream.registerConverter(new GmlGeometryConverter());
    xstream.alias(FEATURE_TYPE, MetacardImpl.class);
    InputStream is = TestGenericFeatureConverter.class.getResourceAsStream("/video_data_set.xml");
    Metacard mc = (Metacard) xstream.fromXML(is);
    assertEquals("video_data_set.2", mc.getId());
    assertEquals(FEATURE_TYPE, mc.getContentTypeName());
    assertEquals(metacardType.getName(), mc.getMetacardType().getName());
    assertEquals(SOURCE_ID, mc.getSourceId());
    assertEquals("video_data_set.2", mc.getTitle());
    assertEquals(2L, mc.getAttribute(PROPERTY_PREFIX + ID_ELEMENT).getValue());
    assertEquals(Long.valueOf(1L), mc.getAttribute(PROPERTY_PREFIX + VERSION_ELEMENT).getValue());
    assertEquals(DatatypeConverter.parseDateTime("2005-04-07T09:54:38.983").getTime(), mc.getAttribute(PROPERTY_PREFIX + END_DATE_ELEMENT).getValue());
    assertEquals("/data/test_suite/video/video/videoFile.mpg", mc.getAttribute(PROPERTY_PREFIX + FILENAME_ELEMENT).getValue());
    assertEquals(720L, mc.getAttribute(PROPERTY_PREFIX + HEIGHT_ELEMENT).getValue());
    assertEquals("a8a55092f0afae881099637ef7746cd8d7066270d9af4cf0f52c41dab53c4005", mc.getAttribute(PROPERTY_PREFIX + INDEX_ID_ELEMENT).getValue());
    assertEquals(getOtherTagsXml(), mc.getAttribute(PROPERTY_PREFIX + OTHER_TAGS_XML_ELEMENT).getValue());
    assertEquals(26L, mc.getAttribute(PROPERTY_PREFIX + REPOSITORY_ID_ELEMENT).getValue());
    assertEquals(DatatypeConverter.parseDateTime("2005-04-07T09:53:39.000").getTime(), mc.getAttribute(PROPERTY_PREFIX + START_DATE_ELEMENT).getValue());
    assertEquals(1280L, mc.getAttribute(PROPERTY_PREFIX + WIDTH_ELEMENT).getValue());
    assertEquals(getLocation(), mc.getLocation());
    assertEquals(mc.getLocation(), mc.getAttribute(PROPERTY_PREFIX + GROUND_GEOM_ELEMENT).getValue());
    assertNotNull(mc.getCreatedDate());
    assertNotNull(mc.getEffectiveDate());
    assertNotNull(mc.getModifiedDate());
    assertNotNull(mc.getContentTypeNamespace());
    assertEquals(mc.getContentTypeNamespace().toString(), Wfs20Constants.NAMESPACE_URN_ROOT + metacardType.getName());
}
Also used : WstxDriver(com.thoughtworks.xstream.io.xml.WstxDriver) Metacard(ddf.catalog.data.Metacard) GmlGeometryConverter(org.codice.ddf.spatial.ogc.wfs.catalog.converter.impl.GmlGeometryConverter) XStream(com.thoughtworks.xstream.XStream) InputStream(java.io.InputStream) MetacardType(ddf.catalog.data.MetacardType) FeatureMetacardType(org.codice.ddf.spatial.ogc.wfs.catalog.common.FeatureMetacardType) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 23 with WstxDriver

use of com.thoughtworks.xstream.io.xml.WstxDriver in project ddf by codice.

the class TestGenericFeatureConverter method testUnmarshalFeatureCollectionXmlToObject.

@Test
public void testUnmarshalFeatureCollectionXmlToObject() {
    XStream xstream = new XStream(new WstxDriver());
    FeatureCollectionConverterWfs20 fcConverter = new FeatureCollectionConverterWfs20();
    Map<String, FeatureConverter> fcMap = new HashMap<String, FeatureConverter>();
    GenericFeatureConverterWfs20 converter = new GenericFeatureConverterWfs20();
    fcMap.put("video_data_set", converter);
    fcConverter.setFeatureConverterMap(fcMap);
    xstream.registerConverter(fcConverter);
    converter.setMetacardType(buildMetacardType());
    converter.setCoordinateOrder(GeospatialUtil.LAT_LON_ORDER);
    xstream.registerConverter(converter);
    xstream.registerConverter(new GmlGeometryConverter());
    xstream.alias("FeatureCollection", Wfs20FeatureCollection.class);
    InputStream is = TestGenericFeatureConverter.class.getResourceAsStream("/video_data_set_collection.xml");
    Wfs20FeatureCollection wfc = (Wfs20FeatureCollection) xstream.fromXML(is);
    assertEquals(4, wfc.getMembers().size());
    Metacard mc = wfc.getMembers().get(0);
    assertEquals(mc.getId(), "video_data_set.1");
}
Also used : WstxDriver(com.thoughtworks.xstream.io.xml.WstxDriver) Metacard(ddf.catalog.data.Metacard) GmlGeometryConverter(org.codice.ddf.spatial.ogc.wfs.catalog.converter.impl.GmlGeometryConverter) 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) Test(org.junit.Test)

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

Example 25 with WstxDriver

use of com.thoughtworks.xstream.io.xml.WstxDriver in project ddf by codice.

the class TestGenericFeatureConverter method testGeoServerLatLonSwappingForMultiPolygon.

@Test
public void testGeoServerLatLonSwappingForMultiPolygon() {
    XStream xstream = new XStream(new WstxDriver());
    FeatureCollectionConverterWfs20 fcConverter = new FeatureCollectionConverterWfs20();
    Map<String, FeatureConverter> fcMap = new HashMap<String, FeatureConverter>();
    GenericFeatureConverterWfs20 converter = new GenericFeatureConverterWfs20();
    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_polygon.xml");
    Wfs20FeatureCollection wfc = (Wfs20FeatureCollection) xstream.fromXML(is);
    assertEquals(1, wfc.getMembers().size());
    Metacard mc = wfc.getMembers().get(0);
    assertEquals(mc.getId(), "states.10");
    // 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.1 36.1, -89.1 37.1, -88.1 37.1, -88.1 36.1, -89.1 36.1"));
}
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) 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