diff --git a/src/main/java/org/opengis/cite/wps20/CommonFixture.java b/src/main/java/org/opengis/cite/wps20/CommonFixture.java index 9afe3bf..b42e958 100644 --- a/src/main/java/org/opengis/cite/wps20/CommonFixture.java +++ b/src/main/java/org/opengis/cite/wps20/CommonFixture.java @@ -7,9 +7,11 @@ import java.io.*; import java.net.HttpURLConnection; import java.net.URI; +import java.net.URISyntaxException; import java.net.URL; import java.net.URLEncoder; import java.nio.charset.Charset; +import java.util.LinkedHashMap; import java.util.Map; import javax.ws.rs.core.MediaType; import javax.xml.transform.OutputKeys; @@ -19,13 +21,18 @@ import javax.xml.parsers.DocumentBuilderFactory; import javax.xml.transform.*; +import org.opengis.cite.wps20.basictests.BasicTests; import org.opengis.cite.wps20.util.ClientUtils; +import org.opengis.cite.wps20.util.URIUtils; import org.testng.ITestContext; import org.testng.SkipException; import org.testng.annotations.BeforeClass; import org.testng.annotations.BeforeMethod; import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.NodeList; import org.xml.sax.InputSource; +import org.xml.sax.SAXException; /** * A supporting base class that sets up a common test fixture. These @@ -55,9 +62,24 @@ public class CommonFixture { /* Define Arguments */ protected String EchoProcessId; - //protected Document GcXmlUri; + protected String LITERAL_INPUT_ID; + protected String LITERAL_OUTPUT_ID; + protected String COMPLEX_INPUT_ID; + protected String COMPLEX_OUTPUT_ID; - //protected Document DpXmlUri; + protected String GET_CAPABILITIES_REQUEST_TEMPLATE_PATH = "/org/opengis/cite/wps20/examples/GetCapabilities.xml"; + protected String DESCRIBE_PROCESS_REQUEST_TEMPLATE_PATH = "/org/opengis/cite/wps20/examples/DescribeProcess.xml"; + protected String LITERAL_REQUEST_TEMPLATE_PATH = "/org/opengis/cite/wps20/examples/Echo_Process_Literal.xml"; + protected String COMPLEX_REQUEST_TEMPLATE_PATH = "/org/opengis/cite/wps20/examples/Echo_Process_Complex.xml"; + + + protected String INPUT_VALUE_TRANSMISSION_TEMPLATE_PATH = "/org/opengis/cite/wps20/examples/ValidInputValue.xml"; + protected String INPUT_REFERENCE_TRANSMISSION_TEMPLATE_PATH = "/org/opengis/cite/wps20/examples/ValidInputReference.xml"; + protected String OUTPUT_VALUE_TRANSMISSION_TEMPLATE_PATH = "/org/opengis/cite/wps20/examples/ValidOutputValue.xml"; + protected String OUTPUT_REFERENCE_TRANSMISSION_TEMPLATE_PATH = "/org/opengis/cite/wps20/examples/ValidOutputReference.xml"; + protected String UNIQUE_JOB_IDS_TEMPLATE_PATH = "/org/opengis/cite/wps20/examples/ValidUniqueJobIds.xml"; + protected String GET_STATUS_TEMPLATE_PATH = "/org/opengis/cite/wps20/examples/ValidGetStatus.xml"; + protected String GET_RESULT_TEMPLATE_PATH = "/org/opengis/cite/wps20/examples/ValidGetResult.xml"; /** * Initializes the common test fixture with a client component for @@ -67,7 +89,7 @@ public class CommonFixture { * a test run, including suite attributes. */ @BeforeClass - public void initCommonFixture(ITestContext testContext) { + public void initCommonFixture(ITestContext testContext) throws Exception { Object obj = testContext.getSuite().getAttribute(SuiteAttribute.CLIENT.getName()); if (null != obj) { this.client = Client.class.cast(obj); @@ -91,21 +113,7 @@ public void initCommonFixture(ITestContext testContext) { System.out.println("WPS 2.0 ECHO PROCESS ID: " + this.EchoProcessId.toString()); } - /* - //Define GC_XML_URI parameter - Object GcXmlUriObj = testContext.getSuite().getAttribute(SuiteAttribute.GC_XML_URI.getName()); - if((null != GcXmlUriObj) && Document.class.isAssignableFrom(GcXmlUriObj.getClass())) { - this.GcXmlUri = Document.class.cast(GcXmlUriObj); - System.out.println("WPS 2.0 GET CAPABILITIES POST/XML URL LOADED"); - } - - //Define DP_XML_URI parameter - Object DpXmlUriObj = testContext.getSuite().getAttribute(SuiteAttribute.DP_XML_URI.getName()); - if((null != DpXmlUriObj) && Document.class.isAssignableFrom(DpXmlUriObj.getClass())) { - this.DpXmlUri = Document.class.cast(DpXmlUriObj); - System.out.println("WPS 2.0 DESCRIBE PROCESS POST/XML URL LOADED"); - } - */ + GetEchoProcessInputIdAndOutputId(); } @BeforeMethod @@ -114,6 +122,74 @@ public void clearMessages() { this.response = null; } + public void GetEchoProcessInputIdAndOutputId() throws URISyntaxException, SAXException, IOException { + String SERVICE_URL = this.ServiceUrl.toString(); + // Get the processid from user and replace the processid in the template xml + // request file + String ECHO_PROCESS_ID = this.EchoProcessId; + + + // Parse the input id and output id in DescribeProcess + Map DP_Parameters = new LinkedHashMap<>(); + DP_Parameters.put("Service", "WPS"); + DP_Parameters.put("Version", "2.0.0"); + DP_Parameters.put("Request", "DescribeProcess"); + DP_Parameters.put("Identifier", ECHO_PROCESS_ID); + String responseDescribeProcess = GetContentFromGETKVPRequest(SERVICE_URL, DP_Parameters); + Document responseDescribeProcessDocument = TransformXMLStringToXMLDocument(responseDescribeProcess); + + // get input id + NodeList inputList = responseDescribeProcessDocument.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", + "Input"); + String literalInputId = "", literalOutputId = "", complexInputId = "", complexOutputId = ""; + for (int i = 0; i < inputList.getLength(); i++) { + Element element = (Element) inputList.item(i); + Element literalInputElement = (Element) element + .getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "LiteralData").item(0); + Element dataTypeInputElement = (Element) element + .getElementsByTagNameNS("http://www.opengis.net/ows/2.0", "DataType").item(0); + Element complexInputElement = (Element) element + .getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "ComplexData").item(0); + String Id = element.getElementsByTagNameNS("http://www.opengis.net/ows/2.0", "Identifier").item(0) + .getTextContent(); + if (literalInputElement != null && dataTypeInputElement != null) { + //check if DataType accepts string + if (dataTypeInputElement.getTextContent().toLowerCase().equals("string")) + literalInputId = Id; + + } else if (complexInputElement != null) { + complexInputId = Id; + } + } + + // get output id + NodeList outputList = responseDescribeProcessDocument.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", + "Output"); + for (int i = 0; i < outputList.getLength(); i++) { + Element element = (Element) outputList.item(i); + Element literalOutputElement = (Element) element + .getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "LiteralData").item(0); + Element dataTypeOutputElement = (Element) element + .getElementsByTagNameNS("http://www.opengis.net/ows/2.0", "DataType").item(0); + Element complexOutputElement = (Element) element + .getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "ComplexData").item(0); + String Id = element.getElementsByTagNameNS("http://www.opengis.net/ows/2.0", "Identifier").item(0) + .getTextContent(); + if (literalOutputElement != null && dataTypeOutputElement != null) { + //check if DataType accepts string + if (dataTypeOutputElement.getTextContent().toLowerCase().equals("string")) + literalOutputId = Id; + } else if (complexOutputElement != null) { + complexOutputId = Id; + } + } + + LITERAL_INPUT_ID = literalInputId; + LITERAL_OUTPUT_ID = literalOutputId; + COMPLEX_INPUT_ID = complexInputId; + COMPLEX_OUTPUT_ID = complexOutputId; + } + /** * Obtains the (XML) response entity as a DOM Document. This convenience * method wraps a static method call to facilitate unit testing (Mockito @@ -159,7 +235,10 @@ public String GetContentFromPOSTXMLRequest(String any_url, Document xml_doc) { StringBuilder sb = new StringBuilder(); HttpURLConnection urlConn = null; InputStreamReader in = null; + String xml = ""; try { + xml = TransformXMLDocumentToXMLString(xml_doc); + System.out.println(xml); Transformer tf = TransformerFactory.newInstance().newTransformer(); tf.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); tf.setOutputProperty(OutputKeys.INDENT, "yes"); @@ -188,7 +267,11 @@ public String GetContentFromPOSTXMLRequest(String any_url, Document xml_doc) { } } in.close(); + //System.out.println(xml); + } catch (Exception e) { + System.out.println(e.toString()); + e.printStackTrace(); throw new RuntimeException("Exception while calling URL:" + any_url, e); } return sb.toString(); @@ -295,5 +378,21 @@ public void prettyPrint(Document xmlDoc) throws Exception { public HttpURLConnection GetConnection(String serviceURL) throws IOException { URL urlObj = new URL(serviceURL); return (HttpURLConnection) urlObj.openConnection(); - } + } + + public Document GetDocumentTemplate(String templatePath, String processId, String inputId, String outputId) throws URISyntaxException, SAXException, IOException { + URI uriLiteralRequestTemplate = BasicTests.class.getResource(templatePath).toURI(); + Document SEPDocument = URIUtils.parseURI(uriLiteralRequestTemplate); + Element requestInputElement = (Element) SEPDocument + .getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "Input").item(0); + Element requestOutputElement = (Element) SEPDocument + .getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "Output").item(0); + Element requestIdElement = (Element) SEPDocument + .getElementsByTagNameNS("http://www.opengis.net/ows/2.0", "Identifier").item(0); + // replace id + requestIdElement.setTextContent(processId); + requestInputElement.setAttribute("id", inputId); + requestOutputElement.setAttribute("id", outputId); + return SEPDocument; + } } diff --git a/src/main/java/org/opengis/cite/wps20/asynchronous/AsyncTests.java b/src/main/java/org/opengis/cite/wps20/asynchronous/AsyncTests.java index 29606cc..90ae21f 100644 --- a/src/main/java/org/opengis/cite/wps20/asynchronous/AsyncTests.java +++ b/src/main/java/org/opengis/cite/wps20/asynchronous/AsyncTests.java @@ -63,19 +63,6 @@ import org.opengis.cite.wps20.util.*; public class AsyncTests extends CommonFixture { - String GET_CAPABILITIES_REQUEST_TEMPLATE_PATH = "/org/opengis/cite/wps20/examples/GetCapabilities.xml"; - String DESCRIBE_PROCESS_REQUEST_TEMPLATE_PATH = "/org/opengis/cite/wps20/examples/DescribeProcess.xml"; - String LITERAL_REQUEST_TEMPLATE_PATH = "/org/opengis/cite/wps20/examples/Echo_Process_Literal.xml"; - String COMPLEX_REQUEST_TEMPLATE_PATH = "/org/opengis/cite/wps20/examples/Echo_Process_Complex.xml"; - - - String INPUT_VALUE_TRANSMISSION_TEMPLATE_PATH = "/org/opengis/cite/wps20/examples/ValidInputValue.xml"; - String INPUT_REFERENCE_TRANSMISSION_TEMPLATE_PATH = "/org/opengis/cite/wps20/examples/ValidInputReference.xml"; - String OUTPUT_VALUE_TRANSMISSION_TEMPLATE_PATH = "/org/opengis/cite/wps20/examples/ValidOutputValue.xml"; - String OUTPUT_REFERENCE_TRANSMISSION_TEMPLATE_PATH = "/org/opengis/cite/wps20/examples/ValidOutputReference.xml"; - String UNIQUE_JOB_IDS_TEMPLATE_PATH = "/org/opengis/cite/wps20/examples/ValidUniqueJobIds.xml"; - String GET_STATUS_TEMPLATE_PATH = "/org/opengis/cite/wps20/examples/ValidGetStatus.xml"; - String GET_RESULT_TEMPLATE_PATH = "/org/opengis/cite/wps20/examples/ValidGetResult.xml"; /** * A.5.14. Verify that the server can handle GetStatus requests via POST/XML. @@ -90,10 +77,7 @@ public class AsyncTests extends CommonFixture { @Test(enabled = true, groups = "A.5. Basic Tests", description = "A.5.14. Verify that the server can handle GetStatus requests via POST/XML.") public void ValidGetStatusViaPOSTXML() throws Exception { String SERVICE_URL = this.ServiceUrl.toString(); - - URI uriLiteralRequestTemplate = BasicTests.class.getResource(LITERAL_REQUEST_TEMPLATE_PATH).toURI(); - Document literalDocument = URIUtils.parseURI(uriLiteralRequestTemplate); - ProcessEchoProcessLiteralDataRequest(SERVICE_URL, literalDocument); + Document literalDocument = GetDocumentTemplate(LITERAL_REQUEST_TEMPLATE_PATH, this.EchoProcessId, LITERAL_INPUT_ID, LITERAL_OUTPUT_ID); Element executeElement = (Element) literalDocument .getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "Execute").item(0); executeElement.setAttribute("mode", "async"); @@ -144,10 +128,7 @@ public void ValidGetStatusViaPOSTXML() throws Exception { @Test(enabled = true, groups = "A.5. Basic Tests", description = "A.5.15. Verify that the server can handle GetResult requests via POST/XML.") public void ValidGetResultViaPOSTXML() throws Exception { String SERVICE_URL = this.ServiceUrl.toString(); - - URI uriLiteralRequestTemplate = BasicTests.class.getResource(LITERAL_REQUEST_TEMPLATE_PATH).toURI(); - Document literalDocument = URIUtils.parseURI(uriLiteralRequestTemplate); - ProcessEchoProcessLiteralDataRequest(SERVICE_URL, literalDocument); + Document literalDocument = GetDocumentTemplate(LITERAL_REQUEST_TEMPLATE_PATH, this.EchoProcessId, LITERAL_INPUT_ID, LITERAL_OUTPUT_ID); Element executeElement = (Element) literalDocument .getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "Execute").item(0); executeElement.setAttribute("mode", "async"); @@ -216,10 +197,7 @@ public void ValidGetResultViaPOSTXML() throws Exception { @Test(enabled = true, groups = "A.5. Basic Tests", description = "A.5.18. Verify that the server can handle GetStatus requests via GET/KVP.") private void ValidGetStatusViaGETKVP() throws IOException, URISyntaxException, SAXException { String SERVICE_URL = this.ServiceUrl.toString(); - - URI uriLiteralRequestTemplate = BasicTests.class.getResource(LITERAL_REQUEST_TEMPLATE_PATH).toURI(); - Document literalDocument = URIUtils.parseURI(uriLiteralRequestTemplate); - ProcessEchoProcessLiteralDataRequest(SERVICE_URL, literalDocument); + Document literalDocument = GetDocumentTemplate(LITERAL_REQUEST_TEMPLATE_PATH, this.EchoProcessId, LITERAL_INPUT_ID, LITERAL_OUTPUT_ID); Element executeElement = (Element) literalDocument .getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "Execute").item(0); executeElement.setAttribute("mode", "async"); @@ -283,10 +261,7 @@ private void ValidGetStatusViaGETKVP() throws IOException, URISyntaxException, S @Test(enabled = true, groups = "A.5. Basic Tests", description = "A.5.19. Verify that the server can handle GetResult requests via GET/KVP.") private void ValidGetResultViaGETKVP() throws IOException, URISyntaxException, SAXException { String SERVICE_URL = this.ServiceUrl.toString(); - - URI uriLiteralRequestTemplate = BasicTests.class.getResource(LITERAL_REQUEST_TEMPLATE_PATH).toURI(); - Document literalDocument = URIUtils.parseURI(uriLiteralRequestTemplate); - ProcessEchoProcessLiteralDataRequest(SERVICE_URL, literalDocument); + Document literalDocument = GetDocumentTemplate(LITERAL_REQUEST_TEMPLATE_PATH, this.EchoProcessId, LITERAL_INPUT_ID, LITERAL_OUTPUT_ID); Element executeElement = (Element) literalDocument .getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "Execute").item(0); executeElement.setAttribute("mode", "async"); @@ -298,6 +273,7 @@ private void ValidGetResultViaGETKVP() throws IOException, URISyntaxException, S executeElement.setAttribute("response", "raw"); String VAEXmlString2 = GetContentFromPOSTXMLRequest(SERVICE_URL, literalDocument); + System.out.println(VAEXmlString2); Document VAEDocument2 = TransformXMLStringToXMLDocument(VAEXmlString2); Boolean VAE_Flag2 = (VAEDocument2.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "StatusInfo").getLength() > 0) ? true : false; @@ -374,69 +350,4 @@ public void CheckGetStatus(String SERVICE_URL, String jobID) { } } - - public void ProcessEchoProcessLiteralDataRequest(String SERVICE_URL, Document SEPDocument) { - // Get the processid from user and replace the processid in the template xml - // request file - String ECHO_PROCESS_ID = this.EchoProcessId; - - // Parse the input id and output id in DescribeProcess - Map DP_Parameters = new LinkedHashMap<>(); - DP_Parameters.put("Service", "WPS"); - DP_Parameters.put("Version", "2.0.0"); - DP_Parameters.put("Request", "DescribeProcess"); - DP_Parameters.put("Identifier", ECHO_PROCESS_ID); - String responseDescribeProcess = GetContentFromGETKVPRequest(SERVICE_URL, DP_Parameters); - Document responseDescribeProcessDocument = TransformXMLStringToXMLDocument(responseDescribeProcess); - - // get input id - NodeList inputList = responseDescribeProcessDocument.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", - "Input"); - String literalInputId = "", literalOutputId = "", complexInputId = "", complexOutputId = ""; - for (int i = 0; i < inputList.getLength(); i++) { - Element element = (Element) inputList.item(i); - Element literalInputElement = (Element) element - .getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "LiteralData").item(0); - Element complexInputElement = (Element) element - .getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "ComplexData").item(0); - String Id = element.getElementsByTagNameNS("http://www.opengis.net/ows/2.0", "Identifier").item(0) - .getTextContent(); - if (literalInputElement != null) { - literalInputId = Id; - } else if (complexInputElement != null) { - complexInputId = Id; - } - } - - // get output id - NodeList outputList = responseDescribeProcessDocument.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", - "Output"); - for (int i = 0; i < outputList.getLength(); i++) { - Element element = (Element) outputList.item(i); - Element literalOutputElement = (Element) element - .getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "LiteralData").item(0); - Element complexOutputElement = (Element) element - .getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "ComplexData").item(0); - String Id = element.getElementsByTagNameNS("http://www.opengis.net/ows/2.0", "Identifier").item(0) - .getTextContent(); - if (literalOutputElement != null) { - literalOutputId = Id; - } else if (complexOutputElement != null) { - complexOutputId = Id; - } - } - - // Test LiteralData - Element requestInputElement = (Element) SEPDocument - .getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "Input").item(0); - Element requestOutputElement = (Element) SEPDocument - .getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "Output").item(0); - Element requestIdElement = (Element) SEPDocument - .getElementsByTagNameNS("http://www.opengis.net/ows/2.0", "Identifier").item(0); - // replace id - requestIdElement.setTextContent(ECHO_PROCESS_ID); - requestInputElement.setAttribute("id", literalInputId); - requestOutputElement.setAttribute("id", literalOutputId); - } - } diff --git a/src/main/java/org/opengis/cite/wps20/basictests/BasicTests.java b/src/main/java/org/opengis/cite/wps20/basictests/BasicTests.java index ae6a496..e2f9f8f 100644 --- a/src/main/java/org/opengis/cite/wps20/basictests/BasicTests.java +++ b/src/main/java/org/opengis/cite/wps20/basictests/BasicTests.java @@ -63,86 +63,7 @@ import org.opengis.cite.wps20.util.*; public class BasicTests extends CommonFixture { - - String GET_CAPABILITIES_REQUEST_TEMPLATE_PATH = "/org/opengis/cite/wps20/examples/GetCapabilities.xml"; - String DESCRIBE_PROCESS_REQUEST_TEMPLATE_PATH = "/org/opengis/cite/wps20/examples/DescribeProcess.xml"; - String LITERAL_REQUEST_TEMPLATE_PATH = "/org/opengis/cite/wps20/examples/Echo_Process_Literal.xml"; - String COMPLEX_REQUEST_TEMPLATE_PATH = "/org/opengis/cite/wps20/examples/Echo_Process_Complex.xml"; - - - String INPUT_VALUE_TRANSMISSION_TEMPLATE_PATH = "/org/opengis/cite/wps20/examples/ValidInputValue.xml"; - String INPUT_REFERENCE_TRANSMISSION_TEMPLATE_PATH = "/org/opengis/cite/wps20/examples/ValidInputReference.xml"; - String OUTPUT_VALUE_TRANSMISSION_TEMPLATE_PATH = "/org/opengis/cite/wps20/examples/ValidOutputValue.xml"; - String OUTPUT_REFERENCE_TRANSMISSION_TEMPLATE_PATH = "/org/opengis/cite/wps20/examples/ValidOutputReference.xml"; - String UNIQUE_JOB_IDS_TEMPLATE_PATH = "/org/opengis/cite/wps20/examples/ValidUniqueJobIds.xml"; - String GET_STATUS_TEMPLATE_PATH = "/org/opengis/cite/wps20/examples/ValidGetStatus.xml"; - String GET_RESULT_TEMPLATE_PATH = "/org/opengis/cite/wps20/examples/ValidGetResult.xml"; - String LITERAL_INPUT_ID = ""; - String LITERAL_OUTPUT_ID = ""; - String COMPLEX_INPUT_ID = ""; - String COMPLEX_OUTPUT_ID = ""; - - @BeforeClass - public void GetEchoProcessInputIdAndOutputId() throws URISyntaxException, SAXException, IOException { - String SERVICE_URL = this.ServiceUrl.toString(); - // Get the processid from user and replace the processid in the template xml - // request file - String ECHO_PROCESS_ID = this.EchoProcessId; - - - // Parse the input id and output id in DescribeProcess - Map DP_Parameters = new LinkedHashMap<>(); - DP_Parameters.put("Service", "WPS"); - DP_Parameters.put("Version", "2.0.0"); - DP_Parameters.put("Request", "DescribeProcess"); - DP_Parameters.put("Identifier", ECHO_PROCESS_ID); - String responseDescribeProcess = GetContentFromGETKVPRequest(SERVICE_URL, DP_Parameters); - Document responseDescribeProcessDocument = TransformXMLStringToXMLDocument(responseDescribeProcess); - - // get input id - NodeList inputList = responseDescribeProcessDocument.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", - "Input"); - String literalInputId = "", literalOutputId = "", complexInputId = "", complexOutputId = ""; - for (int i = 0; i < inputList.getLength(); i++) { - Element element = (Element) inputList.item(i); - Element literalInputElement = (Element) element - .getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "LiteralData").item(0); - Element complexInputElement = (Element) element - .getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "ComplexData").item(0); - String Id = element.getElementsByTagNameNS("http://www.opengis.net/ows/2.0", "Identifier").item(0) - .getTextContent(); - if (literalInputElement != null) { - literalInputId = Id; - } else if (complexInputElement != null) { - complexInputId = Id; - } - } - - // get output id - NodeList outputList = responseDescribeProcessDocument.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", - "Output"); - for (int i = 0; i < outputList.getLength(); i++) { - Element element = (Element) outputList.item(i); - Element literalOutputElement = (Element) element - .getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "LiteralData").item(0); - Element complexOutputElement = (Element) element - .getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "ComplexData").item(0); - String Id = element.getElementsByTagNameNS("http://www.opengis.net/ows/2.0", "Identifier").item(0) - .getTextContent(); - if (literalOutputElement != null) { - literalOutputId = Id; - } else if (complexOutputElement != null) { - complexOutputId = Id; - } - } - - LITERAL_INPUT_ID = literalInputId; - LITERAL_OUTPUT_ID = literalOutputId; - COMPLEX_INPUT_ID = complexInputId; - COMPLEX_OUTPUT_ID = complexOutputId; - } - /** * A.4.1. Verify that a given process description is in compliance with the Process XML encoding. Verify that the tested document fulfils all requirements listed in @@ -398,6 +319,7 @@ private void ValidInputDataTranmissionByReference() throws Exception { Document InputReferenceDocument = GetDocumentTemplate(INPUT_REFERENCE_TRANSMISSION_TEMPLATE_PATH, this.EchoProcessId, LITERAL_INPUT_ID, LITERAL_OUTPUT_ID); String InputReferenceResponse = GetContentFromPOSTXMLRequest(SERVICE_URL, InputReferenceDocument); + System.out.println(InputReferenceResponse); Document InputReferenceResponseDocument = TransformXMLStringToXMLDocument(InputReferenceResponse); NodeList IRRD_List = InputReferenceResponseDocument.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "Result"); @@ -463,6 +385,7 @@ private void ValidOutDataTranmissionByReference() throws Exception { Document OutputReferenceDocument = GetDocumentTemplate(OUTPUT_REFERENCE_TRANSMISSION_TEMPLATE_PATH, this.EchoProcessId, LITERAL_INPUT_ID, LITERAL_OUTPUT_ID); String OutputReferenceResponse = GetContentFromPOSTXMLRequest(SERVICE_URL, OutputReferenceDocument); + System.out.println(OutputReferenceResponse); Document OutputReferenceResponseDocument = TransformXMLStringToXMLDocument(OutputReferenceResponse); NodeList ORRD_List = OutputReferenceResponseDocument.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "Reference"); @@ -625,71 +548,6 @@ public void ValidDescribeProcessViaPOSTXML() throws IOException, URISyntaxExcept } } - - public void ProcessEchoProcessLiteralDataRequest(String SERVICE_URL, Document SEPDocument) { - // Get the processid from user and replace the processid in the template xml - // request file - String ECHO_PROCESS_ID = this.EchoProcessId; - - // Parse the input id and output id in DescribeProcess - Map DP_Parameters = new LinkedHashMap<>(); - DP_Parameters.put("Service", "WPS"); - DP_Parameters.put("Version", "2.0.0"); - DP_Parameters.put("Request", "DescribeProcess"); - DP_Parameters.put("Identifier", ECHO_PROCESS_ID); - String responseDescribeProcess = GetContentFromGETKVPRequest(SERVICE_URL, DP_Parameters); - Document responseDescribeProcessDocument = TransformXMLStringToXMLDocument(responseDescribeProcess); - - // get input id - NodeList inputList = responseDescribeProcessDocument.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", - "Input"); - String literalInputId = "", literalOutputId = "", complexInputId = "", complexOutputId = ""; - for (int i = 0; i < inputList.getLength(); i++) { - Element element = (Element) inputList.item(i); - Element literalInputElement = (Element) element - .getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "LiteralData").item(0); - Element complexInputElement = (Element) element - .getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "ComplexData").item(0); - String Id = element.getElementsByTagNameNS("http://www.opengis.net/ows/2.0", "Identifier").item(0) - .getTextContent(); - if (literalInputElement != null) { - literalInputId = Id; - } else if (complexInputElement != null) { - complexInputId = Id; - } - } - - // get output id - NodeList outputList = responseDescribeProcessDocument.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", - "Output"); - for (int i = 0; i < outputList.getLength(); i++) { - Element element = (Element) outputList.item(i); - Element literalOutputElement = (Element) element - .getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "LiteralData").item(0); - Element complexOutputElement = (Element) element - .getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "ComplexData").item(0); - String Id = element.getElementsByTagNameNS("http://www.opengis.net/ows/2.0", "Identifier").item(0) - .getTextContent(); - if (literalOutputElement != null) { - literalOutputId = Id; - } else if (complexOutputElement != null) { - complexOutputId = Id; - } - } - - // Test LiteralData - Element requestInputElement = (Element) SEPDocument - .getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "Input").item(0); - Element requestOutputElement = (Element) SEPDocument - .getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "Output").item(0); - Element requestIdElement = (Element) SEPDocument - .getElementsByTagNameNS("http://www.opengis.net/ows/2.0", "Identifier").item(0); - // replace id - requestIdElement.setTextContent(ECHO_PROCESS_ID); - requestInputElement.setAttribute("id", literalInputId); - requestOutputElement.setAttribute("id", literalOutputId); - } - /** * A.5.12. Verify that the server can handle the execution mode 'asynchronous' * requested via POST/XML Flow of Test Description: Flow of Test Description: @@ -701,12 +559,7 @@ public void ProcessEchoProcessLiteralDataRequest(String SERVICE_URL, Document SE @Test(enabled = true, groups = "A.5. Basic Tests", description = "A.5.12. Verify that the server can handle the execution mode 'asynchronous' requested via POST/XML.") public void ValidAsyncExcecuteViaPOSTXML() throws Exception { String SERVICE_URL = this.ServiceUrl.toString(); - - URI uriLiteralRequestTemplate = BasicTests.class.getResource(LITERAL_REQUEST_TEMPLATE_PATH).toURI(); - Document literalDocument = URIUtils.parseURI(uriLiteralRequestTemplate); - - // Process Literal Request - ProcessEchoProcessLiteralDataRequest(SERVICE_URL, literalDocument); + Document literalDocument = GetDocumentTemplate(LITERAL_REQUEST_TEMPLATE_PATH, this.EchoProcessId, LITERAL_INPUT_ID, LITERAL_OUTPUT_ID); // Response document Element executeElement = (Element) literalDocument @@ -714,10 +567,7 @@ public void ValidAsyncExcecuteViaPOSTXML() throws Exception { executeElement.setAttribute("mode", "async"); executeElement.setAttribute("response", "document"); - /* - * try { prettyPrint(literalDocument); } catch (Exception e) { // TODO - * Auto-generated catch block e.printStackTrace(); } - */ + prettyPrint(literalDocument); String VAEXmlString = GetContentFromPOSTXMLRequest(SERVICE_URL, literalDocument); Document VAEDocument = TransformXMLStringToXMLDocument(VAEXmlString); @@ -770,15 +620,12 @@ public void ValidAsyncExcecuteViaPOSTXML() throws Exception { @Test(enabled = true, groups = "A.5. Basic Tests", description = "A.5.13. Verify that the server can handle the execution mode 'auto' requested via POST/XML.") public void ValidAutoExcecuteViaPOSTXML() throws Exception { String SERVICE_URL = this.ServiceUrl.toString(); - - URI uriLiteralRequestTemplate = BasicTests.class.getResource(LITERAL_REQUEST_TEMPLATE_PATH).toURI(); - Document literalDocument = URIUtils.parseURI(uriLiteralRequestTemplate); - // Process Literal Request - ProcessEchoProcessLiteralDataRequest(SERVICE_URL, literalDocument); - + // Get the processid from user and replace the processid in the template xml // request file String ECHO_PROCESS_ID = this.EchoProcessId; + Document literalDocument = GetDocumentTemplate(LITERAL_REQUEST_TEMPLATE_PATH, ECHO_PROCESS_ID, LITERAL_INPUT_ID, LITERAL_OUTPUT_ID); + prettyPrint(literalDocument); // Parse the input id and output id in DescribeProcess Map DP_Parameters = new LinkedHashMap<>(); diff --git a/src/main/java/org/opengis/cite/wps20/synchronous/SyncTests.java b/src/main/java/org/opengis/cite/wps20/synchronous/SyncTests.java index 4c465f7..8b730cf 100644 --- a/src/main/java/org/opengis/cite/wps20/synchronous/SyncTests.java +++ b/src/main/java/org/opengis/cite/wps20/synchronous/SyncTests.java @@ -63,21 +63,7 @@ import org.opengis.cite.wps20.util.*; public class SyncTests extends CommonFixture { - - String GET_CAPABILITIES_REQUEST_TEMPLATE_PATH = "/org/opengis/cite/wps20/examples/GetCapabilities.xml"; - String DESCRIBE_PROCESS_REQUEST_TEMPLATE_PATH = "/org/opengis/cite/wps20/examples/DescribeProcess.xml"; - String LITERAL_REQUEST_TEMPLATE_PATH = "/org/opengis/cite/wps20/examples/Echo_Process_Literal.xml"; - String COMPLEX_REQUEST_TEMPLATE_PATH = "/org/opengis/cite/wps20/examples/Echo_Process_Complex.xml"; - - String INPUT_VALUE_TRANSMISSION_TEMPLATE_PATH = "/org/opengis/cite/wps20/examples/ValidInputValue.xml"; - String INPUT_REFERENCE_TRANSMISSION_TEMPLATE_PATH = "/org/opengis/cite/wps20/examples/ValidInputReference.xml"; - String OUTPUT_VALUE_TRANSMISSION_TEMPLATE_PATH = "/org/opengis/cite/wps20/examples/ValidOutputValue.xml"; - String OUTPUT_REFERENCE_TRANSMISSION_TEMPLATE_PATH = "/org/opengis/cite/wps20/examples/ValidOutputReference.xml"; - String UNIQUE_JOB_IDS_TEMPLATE_PATH = "/org/opengis/cite/wps20/examples/ValidUniqueJobIds.xml"; - String GET_STATUS_TEMPLATE_PATH = "/org/opengis/cite/wps20/examples/ValidGetStatus.xml"; - String GET_RESULT_TEMPLATE_PATH = "/org/opengis/cite/wps20/examples/ValidGetResult.xml"; - /** * A.5.11. Verify that the server can handle the execution mode 'synchronous' * requested via POST/XML Flow of Test Description: Send a valid XML Execute @@ -89,12 +75,7 @@ public class SyncTests extends CommonFixture { @Test(enabled = true, groups = "A.5. Basic Tests", description = "A.5.11. Verify that the server can handle the execution mode 'synchronous' requested via POST/XML.") public void ValidSyncExcecuteViaPOSTXML() throws Exception { String SERVICE_URL = this.ServiceUrl.toString(); - - URI uriLiteralRequestTemplate = BasicTests.class.getResource(LITERAL_REQUEST_TEMPLATE_PATH).toURI(); - Document literalDocument = URIUtils.parseURI(uriLiteralRequestTemplate); - - // Process Literal Request - ProcessEchoProcessLiteralDataRequest(SERVICE_URL, literalDocument); + Document literalDocument = GetDocumentTemplate(LITERAL_REQUEST_TEMPLATE_PATH, this.EchoProcessId, LITERAL_INPUT_ID, LITERAL_OUTPUT_ID); // Response document Element executeElement = (Element) literalDocument @@ -159,68 +140,4 @@ public void ValidSyncExcecuteViaPOSTXML() throws Exception { */ } - public void ProcessEchoProcessLiteralDataRequest(String SERVICE_URL, Document SEPDocument) { - // Get the processid from user and replace the processid in the template xml - // request file - String ECHO_PROCESS_ID = this.EchoProcessId; - - // Parse the input id and output id in DescribeProcess - Map DP_Parameters = new LinkedHashMap<>(); - DP_Parameters.put("Service", "WPS"); - DP_Parameters.put("Version", "2.0.0"); - DP_Parameters.put("Request", "DescribeProcess"); - DP_Parameters.put("Identifier", ECHO_PROCESS_ID); - String responseDescribeProcess = GetContentFromGETKVPRequest(SERVICE_URL, DP_Parameters); - Document responseDescribeProcessDocument = TransformXMLStringToXMLDocument(responseDescribeProcess); - - // get input id - NodeList inputList = responseDescribeProcessDocument.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", - "Input"); - String literalInputId = "", literalOutputId = "", complexInputId = "", complexOutputId = ""; - for (int i = 0; i < inputList.getLength(); i++) { - Element element = (Element) inputList.item(i); - Element literalInputElement = (Element) element - .getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "LiteralData").item(0); - Element complexInputElement = (Element) element - .getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "ComplexData").item(0); - String Id = element.getElementsByTagNameNS("http://www.opengis.net/ows/2.0", "Identifier").item(0) - .getTextContent(); - if (literalInputElement != null) { - literalInputId = Id; - } else if (complexInputElement != null) { - complexInputId = Id; - } - } - - // get output id - NodeList outputList = responseDescribeProcessDocument.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", - "Output"); - for (int i = 0; i < outputList.getLength(); i++) { - Element element = (Element) outputList.item(i); - Element literalOutputElement = (Element) element - .getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "LiteralData").item(0); - Element complexOutputElement = (Element) element - .getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "ComplexData").item(0); - String Id = element.getElementsByTagNameNS("http://www.opengis.net/ows/2.0", "Identifier").item(0) - .getTextContent(); - if (literalOutputElement != null) { - literalOutputId = Id; - } else if (complexOutputElement != null) { - complexOutputId = Id; - } - } - - // Test LiteralData - Element requestInputElement = (Element) SEPDocument - .getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "Input").item(0); - Element requestOutputElement = (Element) SEPDocument - .getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "Output").item(0); - Element requestIdElement = (Element) SEPDocument - .getElementsByTagNameNS("http://www.opengis.net/ows/2.0", "Identifier").item(0); - // replace id - requestIdElement.setTextContent(ECHO_PROCESS_ID); - requestInputElement.setAttribute("id", literalInputId); - requestOutputElement.setAttribute("id", literalOutputId); - } - }