@Override public Object decode(String input) throws UnsupportedOperationException { return decode(new StringInputStream(input)); }
@Test public void testEncodePolygon() throws IOException { FeatureTypeInfo fti = getCatalog().getFeatureTypeByName(getLayerId(MockData.BASIC_POLYGONS)); SimpleFeatureCollection fc = (SimpleFeatureCollection) fti.getFeatureSource(null, null).getFeatures(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); try { ppio.encode(fc, bos); fail("Should have thrown an exception"); } catch (IOException e) { assert (e.getCause() instanceof IllegalArgumentException); } }
@Override protected void setUpInternal() throws Exception { GeoServer gs = getGeoServer(); GeoServerInfo global = gs.getGlobal(); SettingsInfo settings = global.getSettings(); ContactInfo contact = settings.getContact(); contact.setContactOrganization("GeoServer"); contact.setOnlineResource("http://www.geoserver.org"); gs.save(global); ppio = new GPXPPIO(gs); }
@Test public void testEncodePoints() throws Exception { FeatureTypeInfo fti = getCatalog().getFeatureTypeByName(getLayerId(MockData.POINTS)); SimpleFeatureCollection fc = (SimpleFeatureCollection) fti.getFeatureSource(null, null).getFeatures(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); ppio.encode(fc, bos); Document dom = dom(new ByteArrayInputStream(bos.toByteArray())); // print(dom); checkValidationErorrs(dom, "./src/test/resources/org/geoserver/wps/ppio/gpx.xsd"); assertEquals("GeoServer", xpath.evaluate("/gpx:gpx/@creator", dom)); assertEquals("GeoServer", xpath.evaluate("/gpx:gpx/gpx:metadata/gpx:link/gpx:text", dom)); assertEquals( "http://www.geoserver.org", xpath.evaluate("/gpx:gpx/gpx:metadata/gpx:link/@href", dom)); assertEquals(1, xpath.getMatchingNodes("/gpx:gpx/gpx:wpt", dom).getLength()); assertEquals("t0000", xpath.evaluate("/gpx:gpx/gpx:wpt[1]/gpx:extensions/att:id", dom)); } }
@Test public void testEncodeMultiLinestring() throws Exception { FeatureTypeInfo fti = getCatalog().getFeatureTypeByName(getLayerId(MockData.ROAD_SEGMENTS)); SimpleFeatureCollection fc = (SimpleFeatureCollection) fti.getFeatureSource(null, null).getFeatures(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); ppio.encode(fc, bos); Document dom = dom(new ByteArrayInputStream(bos.toByteArray())); // print(dom); checkValidationErorrs(dom, "./src/test/resources/org/geoserver/wps/ppio/gpx.xsd"); assertEquals("GeoServer", xpath.evaluate("/gpx:gpx/@creator", dom)); assertEquals("GeoServer", xpath.evaluate("/gpx:gpx/gpx:metadata/gpx:link/gpx:text", dom)); assertEquals( "http://www.geoserver.org", xpath.evaluate("/gpx:gpx/gpx:metadata/gpx:link/@href", dom)); assertEquals(5, xpath.getMatchingNodes("/gpx:gpx/gpx:trk", dom).getLength()); assertEquals("102", xpath.evaluate("/gpx:gpx/gpx:trk[1]/gpx:extensions/att:FID", dom)); assertEquals("Route 5", xpath.evaluate("/gpx:gpx/gpx:trk[1]/gpx:extensions/att:NAME", dom)); }
@Test public void testEncodeLinestring() throws Exception { FeatureTypeInfo fti = getCatalog().getFeatureTypeByName(getLayerId(MockData.LINES)); SimpleFeatureCollection fc = (SimpleFeatureCollection) fti.getFeatureSource(null, null).getFeatures(); ByteArrayOutputStream bos = new ByteArrayOutputStream(); ppio.encode(fc, bos); Document dom = dom(new ByteArrayInputStream(bos.toByteArray())); // print(dom); checkValidationErorrs(dom, "./src/test/resources/org/geoserver/wps/ppio/gpx.xsd"); assertEquals("GeoServer", xpath.evaluate("/gpx:gpx/@creator", dom)); assertEquals("GeoServer", xpath.evaluate("/gpx:gpx/gpx:metadata/gpx:link/gpx:text", dom)); assertEquals( "http://www.geoserver.org", xpath.evaluate("/gpx:gpx/gpx:metadata/gpx:link/@href", dom)); assertEquals(1, xpath.getMatchingNodes("/gpx:gpx/gpx:rte", dom).getLength()); assertEquals("t0001 ", xpath.evaluate("/gpx:gpx/gpx:rte[1]/gpx:extensions/att:id", dom)); // check the data was reprojected to wgs84 assertEquals("4.523789", xpath.evaluate("//gpx:rte/gpx:rtept[1]/@lat", dom)); assertEquals("-92.998873", xpath.evaluate("//gpx:rte/gpx:rtept[1]/@lon", dom)); assertEquals("4.524241", xpath.evaluate("//gpx:rte/gpx:rtept[2]/@lat", dom)); assertEquals("-92.998422", xpath.evaluate("//gpx:rte/gpx:rtept[2]/@lon", dom)); }