WPSClient { public Process getProcess( String id ) { return processIdSimpleToProcess.get( id ); } WPSClient( URL capabilitiesURL ); String getServiceVersion(); OWSCapabilities getMetadata(); Process[] getProcesses(); Process getProcess( String id ); Process getProcess( String id, String idCodeSpace ); URL getDescribeProcessURL( boolean post ); URL getExecuteURL( boolean post );  }
@Test public void testProcessDescription_1() throws OWSExceptionReport, IOException { String demoWPSURL = TestProperties.getProperty( "demo_wps_url" ); Assume.assumeNotNull( demoWPSURL ); WPSClient wpsClient = new WPSClient( new URL( demoWPSURL ) ); org.deegree.protocol.wps.client.process.Process p1 = wpsClient.getProcess( "Buffer" ); LiteralInputType literalInput = (LiteralInputType) p1.getInputTypes()[1]; Assert.assertEquals( "1", literalInput.getMinOccurs() ); Assert.assertEquals( "1", literalInput.getMaxOccurs() ); Assert.assertEquals( "double", literalInput.getDataType().getValue() ); Assert.assertEquals( "http: Assert.assertEquals( "unity", literalInput.getDefaultUom().getValue() ); Assert.assertEquals( "unity", literalInput.getSupportedUoms()[0].getValue() ); Assert.assertEquals( true, literalInput.isAnyValue() ); OutputType output = p1.getOutputTypes()[0]; ComplexOutputType complexData = (ComplexOutputType) output; Assert.assertEquals( "UTF-8", complexData.getDefaultFormat().getEncoding() ); Assert.assertEquals( "text/xml", complexData.getDefaultFormat().getMimeType() ); Assert.assertTrue( complexData.getDefaultFormat().getSchema().startsWith("http: Assert.assertEquals( "UTF-8", complexData.getSupportedFormats()[0].getEncoding() ); Assert.assertEquals( "text/xml", complexData.getSupportedFormats()[0].getMimeType() ); Assert.assertTrue( complexData.getSupportedFormats()[0].getSchema().startsWith("http: }
@Test public void testProcessDescription_2() throws OWSExceptionReport, IOException { String demoWPSURL = TestProperties.getProperty( "demo_wps_url" ); Assume.assumeNotNull( demoWPSURL ); WPSClient wpsClient = new WPSClient( new URL( demoWPSURL ) ); org.deegree.protocol.wps.client.process.Process p2 = wpsClient.getProcess( "Crosses", null ); InputType secondInput = p2.getInputTypes()[1]; Assert.assertEquals( "1", secondInput.getMinOccurs() ); Assert.assertEquals( "1", secondInput.getMaxOccurs() ); ComplexInputType complexData = (ComplexInputType) secondInput; Assert.assertEquals( "text/xml", complexData.getDefaultFormat().getMimeType() ); Assert.assertEquals( "UTF-8", complexData.getDefaultFormat().getEncoding() ); Assert.assertEquals( "http: complexData.getDefaultFormat().getSchema() ); Assert.assertEquals( "text/xml", complexData.getSupportedFormats()[0].getMimeType() ); Assert.assertEquals( "UTF-8", complexData.getSupportedFormats()[0].getEncoding() ); Assert.assertEquals( "http: complexData.getSupportedFormats()[0].getSchema() ); OutputType output = p2.getOutputTypes()[0]; LiteralOutputType literalOut = (LiteralOutputType) output; Assert.assertEquals( "boolean", literalOut.getDataType().getValue() ); Assert.assertEquals( "http: }
@Test public void testProcessDescription_3() throws OWSExceptionReport, IOException { String demoWPSURL = TestProperties.getProperty( "demo_wps_url" ); Assume.assumeNotNull( demoWPSURL ); WPSClient wpsClient = new WPSClient( new URL( demoWPSURL ) ); org.deegree.protocol.wps.client.process.Process p2 = wpsClient.getProcess( "ParameterDemoProcess", null ); InputType firstInput = p2.getInputTypes()[0]; LiteralInputType literalInput = (LiteralInputType) firstInput; Assert.assertEquals( "integer", literalInput.getDataType().getValue() ); Assert.assertEquals( "http: literalInput.getDataType().getRef().toString() ); Assert.assertEquals( "seconds", literalInput.getDefaultUom().getValue() ); Assert.assertEquals( "seconds", literalInput.getSupportedUoms()[0].getValue() ); Assert.assertEquals( "minutes", literalInput.getSupportedUoms()[1].getValue() ); InputType secondInput = p2.getInputTypes()[1]; Assert.assertEquals( "1", secondInput.getMinOccurs() ); Assert.assertEquals( "1", secondInput.getMaxOccurs() ); BBoxInputType bboxData = (BBoxInputType) secondInput; Assert.assertEquals( "EPSG:4326", bboxData.getDefaultCRS() ); Assert.assertEquals( "EPSG:4326", bboxData.getSupportedCrs()[0] ); InputType thirdInput = p2.getInputTypes()[2]; ComplexInputType xmlData = (ComplexInputType) thirdInput; Assert.assertEquals( "text/xml", xmlData.getDefaultFormat().getMimeType() ); Assert.assertEquals( "text/xml", xmlData.getSupportedFormats()[0].getMimeType() ); InputType fourthInput = p2.getInputTypes()[3]; ComplexInputType binaryData = (ComplexInputType) fourthInput; Assert.assertEquals( "image/png", binaryData.getDefaultFormat().getMimeType() ); Assert.assertEquals( "base64", binaryData.getDefaultFormat().getEncoding() ); Assert.assertEquals( "image/png", binaryData.getSupportedFormats()[0].getMimeType() ); Assert.assertEquals( "base64", binaryData.getSupportedFormats()[0].getEncoding() ); OutputType firstOutput = p2.getOutputTypes()[0]; Assert.assertEquals( "A literal output parameter", firstOutput.getTitle().getString() ); LiteralOutputType literalData = (LiteralOutputType) firstOutput; Assert.assertEquals( "integer", literalData.getDataType().getValue() ); Assert.assertEquals( "http: Assert.assertEquals( "seconds", literalData.getDefaultUom().getValue() ); Assert.assertEquals( "seconds", literalData.getSupportedUoms()[0].getValue() ); OutputType secondOutput = p2.getOutputTypes()[1]; BBoxOutputType bboxOutput = (BBoxOutputType) secondOutput; Assert.assertEquals( "EPSG:4326", bboxOutput.getDefaultCrs() ); Assert.assertEquals( "EPSG:4326", bboxOutput.getSupportedCrs()[0] ); OutputType thirdOutput = p2.getOutputTypes()[2]; ComplexOutputType xmlOutput = (ComplexOutputType) thirdOutput; Assert.assertEquals( "text/xml", xmlOutput.getDefaultFormat().getMimeType() ); Assert.assertEquals( "text/xml", xmlOutput.getSupportedFormats()[0].getMimeType() ); OutputType fourthOutput = p2.getOutputTypes()[3]; ComplexOutputType binaryOutput = (ComplexOutputType) fourthOutput; System.out.println( binaryOutput.getDefaultFormat() ); Assert.assertEquals( "text/xml", xmlOutput.getDefaultFormat().getMimeType() ); Assert.assertEquals( "text/xml", xmlOutput.getSupportedFormats()[0].getMimeType() ); }
@Test public void testGetProcess() throws OWSExceptionReport, IOException { String demoWPSURL = TestProperties.getProperty( "demo_wps_url" ); Assume.assumeNotNull( demoWPSURL ); WPSClient wpsClient = new WPSClient( new URL( demoWPSURL ) ); org.deegree.protocol.wps.client.process.Process p1 = wpsClient.getProcess( "Buffer", null ); Assert.assertNotNull( p1 ); org.deegree.protocol.wps.client.process.Process p2 = wpsClient.getProcess( "ParameterDemoProcess", null ); Assert.assertNotNull( p2 ); }
@Test public void testExecute_1() throws Exception { String demoWPSURL = TestProperties.getProperty( "demo_wps_url" ); Assume.assumeNotNull( demoWPSURL ); WPSClient wpsClient = new WPSClient( new URL( demoWPSURL ) ); org.deegree.protocol.wps.client.process.Process proc = wpsClient.getProcess( "Centroid", null ); ProcessExecution execution = proc.prepareExecution(); execution.addXMLInput( "GMLInput", null, CURVE_FILE.toURI(), false, "text/xml", null, null ); execution.addOutput( "Centroid", null, null, true, null, null, null ); ExecutionOutputs response = execution.execute(); assertEquals( ExecutionState.SUCCEEDED, execution.getState() ); ComplexOutput output = (ComplexOutput) response.get( 0 ); XMLStreamReader reader = output.getAsXMLStream(); XMLAdapter searchableXML = new XMLAdapter( reader ); NamespaceBindings nsContext = new NamespaceBindings(); nsContext.addNamespace( "wps", WPSConstants.WPS_100_NS ); nsContext.addNamespace( "gml", "http: XPath xpath = new XPath( "/gml:Point/gml:pos/text()", nsContext ); String pos = searchableXML.getRequiredNodeAsString( searchableXML.getRootElement(), xpath ); String[] pair = pos.split( "\\s" ); Assert.assertNotNull( Double.parseDouble( pair[0] ) ); Assert.assertNotNull( Double.parseDouble( pair[1] ) ); }
@Test public void testExecute_2() throws Exception { String demoWPSURL = TestProperties.getProperty( "demo_wps_url" ); Assume.assumeNotNull( demoWPSURL ); WPSClient wpsClient = new WPSClient( new URL( demoWPSURL ) ); org.deegree.protocol.wps.client.process.Process proc = wpsClient.getProcess( "Buffer", null ); ProcessExecution execution = proc.prepareExecution(); execution.addLiteralInput( "BufferDistance", null, "0.1", "double", "unity" ); execution.addXMLInput( "GMLInput", null, CURVE_FILE.toURI(), false, "text/xml", null, null ); execution.addOutput( "BufferedGeometry", null, null, false, null, null, null ); ExecutionOutputs outputs = execution.execute(); ComplexOutput complexOut = outputs.getComplex( "BufferedGeometry", null ); XMLAdapter searchableXML = new XMLAdapter( complexOut.getAsXMLStream() ); String xpathStr = "/gml:Polygon/gml:exterior/gml:LinearRing/gml:posList"; NamespaceBindings nsContext = new NamespaceBindings(); nsContext.addNamespace( GML_PREFIX, GML_NAMESPACE ); XPath xpath = new XPath( xpathStr, nsContext ); String pointList = searchableXML.getRequiredNodeAsString( searchableXML.getRootElement(), xpath ); Assert.assertEquals( 460, pointList.split( "\\s" ).length ); }
@Test public void testExecute_3() throws OWSExceptionReport, IOException, XMLStreamException { String demoWPSURL = TestProperties.getProperty( "demo_wps_url" ); Assume.assumeNotNull( demoWPSURL ); WPSClient wpsClient = new WPSClient( new URL( demoWPSURL ) ); org.deegree.protocol.wps.client.process.Process proc = wpsClient.getProcess( "ParameterDemoProcess" ); ProcessExecution execution = proc.prepareExecution(); execution.addLiteralInput( "LiteralInput", null, "0", "integer", "seconds" ); execution.addBBoxInput( "BBOXInput", null, new double[] { 0, 0 }, new double[] { 90, 180 }, "EPSG:4326" ); execution.addXMLInput( "XMLInput", null, CURVE_FILE.toURI(), false, "text/xml", null, null ); execution.addBinaryInput( "BinaryInput", null, BINARY_INPUT.toURI(), false, "image/png", null ); ExecutionOutputs outputs = execution.execute(); LiteralOutput out1 = (LiteralOutput) outputs.get( 0 ); Assert.assertEquals( "0", out1.getValue() ); Assert.assertEquals( "integer", out1.getDataType() ); Assert.assertEquals( "seconds", out1.getUom() ); BBoxOutput out2 = (BBoxOutput) outputs.get( 1 ); Assert.assertTrue( Arrays.equals( new double[] { 0.0, 0.0 }, out2.getLower() ) ); Assert.assertTrue( Arrays.equals( new double[] { 90.0, 180.0 }, out2.getUpper() ) ); Assert.assertEquals( "EPSG:4326", out2.getCrs() ); Assert.assertEquals( 2, out2.getDimension() ); }
@Test public void testExecute_4() throws OWSExceptionReport, IOException, XMLStreamException { String demoWPSURL = TestProperties.getProperty( "demo_wps_url" ); Assume.assumeNotNull( demoWPSURL ); WPSClient wpsClient = new WPSClient( new URL( demoWPSURL ) ); org.deegree.protocol.wps.client.process.Process proc = wpsClient.getProcess( "ParameterDemoProcess", null ); ProcessExecution execution = proc.prepareExecution(); execution.addLiteralInput( "LiteralInput", null, "0", "integer", "seconds" ); execution.addBBoxInput( "BBOXInput", null, new double[] { 0, 0 }, new double[] { 90, 180 }, "EPSG:4326" ); execution.addXMLInput( "XMLInput", null, CURVE_FILE.toURI(), false, "text/xml", null, null ); execution.addBinaryInput( "BinaryInput", null, BINARY_INPUT.toURI(), false, "image/png", null ); execution.addOutput( "BBOXOutput", null, null, false, null, null, null ); ExecutionOutputs outputs = execution.execute(); BBoxOutput bboxOut = outputs.getBoundingBox( "BBOXOutput", null ); Assert.assertTrue( Arrays.equals( new double[] { 0.0, 0.0 }, bboxOut.getLower() ) ); Assert.assertTrue( Arrays.equals( new double[] { 90.0, 180.0 }, bboxOut.getUpper() ) ); Assert.assertEquals( "EPSG:4326", bboxOut.getCrs() ); Assert.assertEquals( 2, bboxOut.getDimension() ); Assert.assertNull( outputs.getComplex( "XMLOutput", null ) ); Assert.assertNull( outputs.getComplex( "BinaryOutput", null ) ); Assert.assertNull( outputs.getLiteral( "LiteralOutput", null ) ); }
@Test public void testExecuteRawOutput() throws OWSExceptionReport, IOException, XMLStreamException { String demoWPSURL = TestProperties.getProperty( "demo_wps_url" ); Assume.assumeNotNull( demoWPSURL ); WPSClient wpsClient = new WPSClient( new URL( demoWPSURL ) ); org.deegree.protocol.wps.client.process.Process proc = wpsClient.getProcess( "ParameterDemoProcess", null ); RawProcessExecution execution = proc.prepareRawExecution(); execution.addLiteralInput( "LiteralInput", null, "0", "integer", "seconds" ); execution.addBBoxInput( "BBOXInput", null, new double[] { 0, 0 }, new double[] { 90, 180 }, "EPSG:4326" ); execution.addXMLInput( "XMLInput", null, CURVE_FILE.toURI(), false, "text/xml", null, null ); execution.addBinaryInput( "BinaryInput", null, BINARY_INPUT.toURI(), false, "image/png", null ); ComplexOutput out = execution.executeComplexOutput( "BinaryOutput", null, "image/png", null, null ); InputStream stream = out.getAsBinaryStream(); FileOutputStream fileStream = new FileOutputStream( File.createTempFile( "wpsBinaryOut", "" ) ); byte[] b = new byte[1024]; int read = -1; while ( ( read = stream.read( b ) ) != -1 ) { fileStream.write( b, 0, read ); } fileStream.close(); stream.close(); }
@Test public void testExecuteInputsByRef() throws OWSExceptionReport, IOException, XMLStreamException, URISyntaxException { String demoWPSURL = TestProperties.getProperty( "demo_wps_url" ); Assume.assumeNotNull( demoWPSURL ); WPSClient wpsClient = new WPSClient( new URL( demoWPSURL ) ); org.deegree.protocol.wps.client.process.Process proc = wpsClient.getProcess( "ParameterDemoProcess", null ); ProcessExecution execution = proc.prepareExecution(); execution.addLiteralInput( "LiteralInput", null, "0", "integer", "seconds" ); execution.addBBoxInput( "BBOXInput", null, new double[] { 0, 0 }, new double[] { 90, 180 }, "EPSG:4326" ); execution.addXMLInput( "XMLInput", null, new URI( demoWPSURL ), true, "text/xml", null, null ); execution.addBinaryInput( "BinaryInput", null, new URI( REMOTE_BINARY_INPUT ), true, "image/png", null ); ExecutionOutputs outputs = execution.execute(); LiteralOutput out1 = (LiteralOutput) outputs.get( 0 ); Assert.assertEquals( "0", out1.getValue() ); Assert.assertEquals( "integer", out1.getDataType() ); Assert.assertEquals( "seconds", out1.getUom() ); BBoxOutput out2 = (BBoxOutput) outputs.get( 1 ); Assert.assertTrue( Arrays.equals( new double[] { 0.0, 0.0 }, out2.getLower() ) ); Assert.assertTrue( Arrays.equals( new double[] { 90.0, 180.0 }, out2.getUpper() ) ); Assert.assertEquals( "EPSG:4326", out2.getCrs() ); Assert.assertEquals( 2, out2.getDimension() ); ComplexOutput output = (ComplexOutput) outputs.get( 2 ); XMLStreamReader reader = output.getAsXMLStream(); XMLAdapter searchableXML = new XMLAdapter( reader ); NamespaceBindings nsContext = new NamespaceBindings(); nsContext.addNamespace( "wps", WPS_NS ); nsContext.addNamespace( "ows", OWS_NS ); XPath xpath = new XPath( "/wps:Capabilities/ows:ServiceIdentification/ows:ServiceType", nsContext ); String pos = searchableXML.getRequiredNodeAsString( searchableXML.getRootElement(), xpath ); Assert.assertEquals( pos, "WPS" ); InputStream binaryStream = outputs.getComplex( "BinaryOutput", null ).getAsBinaryStream(); Assert.assertNotNull( binaryStream ); binaryStream.close(); }
@Test public void testExecuteAsync() throws OWSExceptionReport, IOException, XMLStreamException, InterruptedException { String demoWPSURL = TestProperties.getProperty( "demo_wps_url" ); Assume.assumeNotNull( demoWPSURL ); WPSClient wpsClient = new WPSClient( new URL( demoWPSURL ) ); org.deegree.protocol.wps.client.process.Process proc = wpsClient.getProcess( "ParameterDemoProcess", null ); ProcessExecution execution = proc.prepareExecution(); execution.addLiteralInput( "LiteralInput", null, "5", "integer", "seconds" ); execution.addBBoxInput( "BBOXInput", null, new double[] { 0, 0 }, new double[] { 90, 180 }, "EPSG:4326" ); execution.addXMLInput( "XMLInput", null, CURVE_FILE.toURI(), false, "text/xml", null, null ); execution.addBinaryInput( "BinaryInput", null, BINARY_INPUT.toURI(), false, "image/png", null ); execution.executeAsync(); Assert.assertNotSame( ExecutionState.SUCCEEDED, execution.getState() ); Assert.assertNotSame( ExecutionState.FAILED, execution.getState() ); while ( ( execution.getState() ) != ExecutionState.SUCCEEDED ) { System.out.println( execution.getPercentCompleted() ); Thread.sleep( 500 ); } ExecutionOutputs outputs = execution.getOutputs(); LiteralOutput out1 = (LiteralOutput) outputs.get( "LiteralOutput", null ); Assert.assertEquals( "5", out1.getValue() ); Assert.assertEquals( "integer", out1.getDataType() ); BBoxOutput out2 = (BBoxOutput) outputs.get( "BBOXOutput", null ); Assert.assertTrue( Arrays.equals( new double[] { 0.0, 0.0 }, out2.getLower() ) ); Assert.assertTrue( Arrays.equals( new double[] { 90.0, 180.0 }, out2.getUpper() ) ); Assert.assertEquals( "EPSG:4326", out2.getCrs() ); Assert.assertEquals( 2, out2.getDimension() ); }
@Test(expected = OWSExceptionReport.class) public void testFailedExecute() throws Exception { String demoWPSURL = TestProperties.getProperty( "demo_wps_url" ); Assume.assumeNotNull( demoWPSURL ); WPSClient wpsClient = new WPSClient( new URL( demoWPSURL ) ); Process proc = wpsClient.getProcess( "Centroid", null ); ProcessExecution execution = proc.prepareExecution(); execution.addOutput( "Centroid", null, null, true, null, null, null ); execution.execute(); Assert.assertTrue(execution.getState() != ExecutionState.SUCCEEDED); }
@Test(expected = OWSExceptionReport.class) public void testFailedExecute_2() throws Exception { String demoWPSURL = TestProperties.getProperty( "demo_wps_url" ); Assume.assumeNotNull( demoWPSURL ); WPSClient wpsClient = new WPSClient( new URL( demoWPSURL ) ); Process proc = wpsClient.getProcess( "Centroid" ); ProcessExecution execution = proc.prepareExecution(); execution.addLiteralInput( "ThisDoesNotExist", null, "5", "sortOfInteger", "reallyBigUnit" ); execution.executeAsync(); Assert.assertTrue(execution.getState() != ExecutionState.SUCCEEDED); }
@Test public void testURIInput() throws MalformedURLException, OWSExceptionReport, IOException, XMLStreamException, InterruptedException, URISyntaxException { String demoWPSURL = TestProperties.getProperty( "demo_wps_authentication_url" ); String demoWPSProcessName = TestProperties.getProperty( "demo_wps_authentication_process_name" ); String demoWPSInputParam = TestProperties.getProperty( "demo_wps_input_uri" ); Assume.assumeNotNull( demoWPSURL ); Assume.assumeNotNull( demoWPSProcessName ); Assume.assumeNotNull( demoWPSInputParam ); URL serviceUrl = new URL( demoWPSURL ); URI inputUri = new URI( demoWPSInputParam ); WPSClient wpsClient = new WPSClient( serviceUrl ); Process proc = wpsClient.getProcess( demoWPSProcessName, null ); ProcessExecution execution = proc.prepareExecution(); execution.addBinaryInput( "infile", null, inputUri, true, null, null ); execution.execute(); while ( execution.getState() != ExecutionState.SUCCEEDED && execution.getState() != ExecutionState.FAILED ) { System.out.println( String.format( "%s, %d, %s", execution.getState(), execution.getPercentCompleted(), execution.getStatusLocation() ) ); Thread.sleep( 500 ); } ExecutionOutputs outputs = execution.getOutputs(); Assert.assertTrue( outputs.getAll().length > 0 ); }