public void testWKTInlineKVPRawOutput() throws Exception { String request = "wps?service=WPS&version=1.0.0&request=Execute&Identifier=gt:buffer" + "&DataInputs=" + urlEncode( "geom1=POLYGON((1 1, 2 1, 2 2, 1 2, 1 1))@mimetype=application/wkt;buffer=1") + "&RawDataOutput=" + urlEncode("result=@mimetype=application/wkt"); MockHttpServletResponse response = getAsServletResponse(request); // System.out.println(response.getOutputStreamContent()); assertEquals("application/wkt", response.getContentType()); Geometry g = new WKTReader().read(response.getOutputStreamContent()); assertTrue(g instanceof Polygon); }
public void testProcessChaining() throws Exception { // chain two JTS processes String xml = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<wps:Execute version=\"1.0.0\" service=\"WPS\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns=\"http://www.opengis.net/wps/1.0.0\" xmlns:wfs=\"http://www.opengis.net/wfs\" xmlns:wps=\"http://www.opengis.net/wps/1.0.0\" xmlns:ows=\"http://www.opengis.net/ows/1.1\" xmlns:gml=\"http://www.opengis.net/gml\" xmlns:ogc=\"http://www.opengis.net/ogc\" xmlns:wcs=\"http://www.opengis.net/wcs/1.1.1\" xmlns:xlink=\"http://www.w3.org/1999/xlink\" xsi:schemaLocation=\"http://www.opengis.net/wps/1.0.0 http://schemas.opengis.net/wps/1.0.0/wpsAll.xsd\">\n" + " <ows:Identifier>JTS:area</ows:Identifier>\n" + " <wps:DataInputs>\n" + " <wps:Input>\n" + " <ows:Identifier>geom</ows:Identifier>\n" + " <wps:Reference mimeType=\"text/xml; subtype=gml/3.1.1\" xlink:href=\"http://geoserver/wps\" method=\"POST\">\n" + " <wps:Execute>\n" + " <ows:Identifier>JTS:buffer</ows:Identifier>\n" + " <wps:DataInputs>\n" + " <wps:Input>\n" + " <ows:Identifier>geom</ows:Identifier>\n" + " <wps:Data>\n" + " <wps:ComplexData mimeType=\"application/wkt\"><![CDATA[POINT(0 0)]]></wps:ComplexData>\n" + " </wps:Data>\n" + " </wps:Input>\n" + " <wps:Input>\n" + " <ows:Identifier>distance</ows:Identifier>\n" + " <wps:Data>\n" + " <wps:LiteralData>10</wps:LiteralData>\n" + " </wps:Data>\n" + " </wps:Input>\n" + " </wps:DataInputs>\n" + " <wps:ResponseForm>\n" + " <wps:RawDataOutput mimeType=\"text/xml; subtype=gml/3.1.1\">\n" + " <ows:Identifier>result</ows:Identifier>\n" + " </wps:RawDataOutput>\n" + " </wps:ResponseForm>\n" + " </wps:Execute>\n" + " </wps:Reference>\n" + " </wps:Input>\n" + " </wps:DataInputs>\n" + " <wps:ResponseForm>\n" + " <wps:RawDataOutput>\n" + " <ows:Identifier>result</ows:Identifier>\n" + " </wps:RawDataOutput>\n" + " </wps:ResponseForm>\n" + "</wps:Execute>"; MockHttpServletResponse resp = postAsServletResponse(root(), xml); assertEquals("text/plain", resp.getContentType()); // the result is inaccurate since the buffer is just a poor approximation of a circle assertTrue(resp.getOutputStreamContent().matches("312\\..*")); }
ReferencedEnvelope toEnvelope(String xml) throws Exception { Parser p = new Parser(new OWSConfiguration()); Object parsed = p.parse(new ByteArrayInputStream(xml.getBytes())); assertTrue(parsed instanceof BoundingBoxType); BoundingBoxType box = (BoundingBoxType) parsed; ReferencedEnvelope re; if (box.getCrs() != null) { re = new ReferencedEnvelope(CRS.decode(box.getCrs())); } else { re = new ReferencedEnvelope(); } re.expandToInclude((Double) box.getLowerCorner().get(0), (Double) box.getLowerCorner().get(1)); re.expandToInclude((Double) box.getUpperCorner().get(0), (Double) box.getUpperCorner().get(1)); return re; }
public void testProcessChainingKVP() throws Exception { String nested = "http://geoserver/wps?service=WPS&version=1.0.0&request=Execute&Identifier=JTS:buffer" + "&DataInputs=" + urlEncode("geom=POINT(0 0)@mimetype=application/wkt;distance=10") + "&RawDataOutput=result"; String request = "wps?service=WPS&version=1.0.0&request=Execute&Identifier=JTS:area" + "&DataInputs=" + urlEncode("geom=@href=" + nested) + "&RawDataOutput=result"; MockHttpServletResponse resp = getAsServletResponse(request); assertEquals("text/plain", resp.getContentType()); // the result is inaccurate since the buffer is just a poor approximation of a circle assertTrue(resp.getOutputStreamContent().matches("312\\..*")); }
private void checkShapefileIntegrity(String[] typeNames, final InputStream in) throws IOException { ZipInputStream zis = new ZipInputStream(in); ZipEntry entry = null; final String[] extensions = new String[] {".shp", ".shx", ".dbf", ".prj", ".cst"}; Set names = new HashSet(); for (String name : typeNames) { for (String extension : extensions) { names.add(name + extension); } } while ((entry = zis.getNextEntry()) != null) { final String name = entry.getName(); assertTrue("Missing " + name, names.contains(name)); names.remove(name); zis.closeEntry(); } zis.close(); }
public void testWKTInlineRawOutput() throws Exception { // Standard Test A.4.4.3 String xml = "<wps:Execute service='WPS' version='1.0.0' xmlns:wps='http://www.opengis.net/wps/1.0.0' " + "xmlns:ows='http://www.opengis.net/ows/1.1'>" + "<ows:Identifier>gt:buffer</ows:Identifier>" + "<wps:DataInputs>" + "<wps:Input>" + "<ows:Identifier>geom1</ows:Identifier>" + "<wps:Data>" + "<wps:ComplexData mimeType=\"application/wkt\">" + "<![CDATA[POLYGON((1 1, 2 1, 2 2, 1 2, 1 1))]]>" + "</wps:ComplexData>" + "</wps:Data>" + "</wps:Input>" + "<wps:Input>" + "<ows:Identifier>buffer</ows:Identifier>" + "<wps:Data>" + "<wps:LiteralData>1</wps:LiteralData>" + "</wps:Data>" + "</wps:Input>" + "</wps:DataInputs>" + "<wps:ResponseForm>" + " <wps:RawDataOutput mimeType=\"application/wkt\">" + " <ows:Identifier>result</ows:Identifier>" + " </wps:RawDataOutput>" + " </wps:ResponseForm>" + "</wps:Execute>"; // print(dom(new StringInputStream("<?xml version=\"1.0\" encoding=\"UTF-16\"?>\n" + xml))); MockHttpServletResponse response = postAsServletResponse("wps", xml); System.out.println(response.getOutputStreamContent()); assertEquals("application/wkt", response.getContentType()); Geometry g = new WKTReader().read(response.getOutputStreamContent()); assertTrue(g instanceof Polygon); }