From 7e8ca8c7854ed8fa3ff801ebb627b4e9ef57231a Mon Sep 17 00:00:00 2001 From: Gobe Hobona Date: Thu, 15 Dec 2022 12:18:21 +0000 Subject: [PATCH 1/2] refactored the tests to separate sync and async conf classes --- .gitignore | 1 + .../org/opengis/cite/wps20/CommonFixture.java | 161 ++++++ .../cite/wps20/asynchronous/AsyncTests.java | 442 +++++++++++++++ .../{level1 => basictests}/BasicTests.java | 525 +----------------- .../cite/wps20/level1/Capability1Tests.java | 95 ---- .../cite/wps20/level1/package-info.java | 14 - .../cite/wps20/synchronous/SyncTests.java | 226 ++++++++ .../org/opengis/cite/wps20/testng.xml | 19 +- .../wps20/level1/VerifyCapability1Tests.java | 72 --- 9 files changed, 844 insertions(+), 711 deletions(-) create mode 100644 src/main/java/org/opengis/cite/wps20/asynchronous/AsyncTests.java rename src/main/java/org/opengis/cite/wps20/{level1 => basictests}/BasicTests.java (64%) delete mode 100644 src/main/java/org/opengis/cite/wps20/level1/Capability1Tests.java delete mode 100644 src/main/java/org/opengis/cite/wps20/level1/package-info.java create mode 100644 src/main/java/org/opengis/cite/wps20/synchronous/SyncTests.java delete mode 100644 src/test/java/org/opengis/cite/wps20/level1/VerifyCapability1Tests.java diff --git a/.gitignore b/.gitignore index e43b0f9..a44d20e 100644 --- a/.gitignore +++ b/.gitignore @@ -1 +1,2 @@ .DS_Store +/target/ diff --git a/src/main/java/org/opengis/cite/wps20/CommonFixture.java b/src/main/java/org/opengis/cite/wps20/CommonFixture.java index 87dc127..c141a1d 100644 --- a/src/main/java/org/opengis/cite/wps20/CommonFixture.java +++ b/src/main/java/org/opengis/cite/wps20/CommonFixture.java @@ -3,15 +3,29 @@ import com.sun.jersey.api.client.Client; import com.sun.jersey.api.client.ClientRequest; import com.sun.jersey.api.client.ClientResponse; + +import java.io.*; +import java.net.HttpURLConnection; import java.net.URI; +import java.net.URL; +import java.net.URLEncoder; +import java.nio.charset.Charset; import java.util.Map; import javax.ws.rs.core.MediaType; +import javax.xml.transform.OutputKeys; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.*; + import org.opengis.cite.wps20.util.ClientUtils; 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.xml.sax.InputSource; /** * A supporting base class that sets up a common test fixture. These @@ -134,5 +148,152 @@ public ClientRequest buildGetRequest(URI endpoint, Map qryParams, MediaType... mediaTypes) { return ClientUtils.buildGetRequest(endpoint, qryParams, mediaTypes); } + /** + * Description: Send POST request with parameters and return Response as String + * + * @param any_url + * @param xml_doc + * @return + */ + public String GetContentFromPOSTXMLRequest(String any_url, Document xml_doc) { + StringBuilder sb = new StringBuilder(); + HttpURLConnection urlConn = null; + InputStreamReader in = null; + try { + Transformer tf = TransformerFactory.newInstance().newTransformer(); + tf.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); + tf.setOutputProperty(OutputKeys.INDENT, "yes"); + Writer out = new StringWriter(); + tf.transform(new DOMSource(xml_doc), new StreamResult(out)); + byte[] postDataBytes = out.toString().getBytes("UTF-8"); + + URL url = new URL(any_url); + urlConn = (HttpURLConnection) url.openConnection(); + urlConn.setRequestMethod("POST"); + urlConn.setRequestProperty("Content-Type", "application/xml"); + urlConn.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length)); + urlConn.setDoOutput(true); + urlConn.getOutputStream().write(postDataBytes); + if (urlConn != null) + urlConn.setReadTimeout(60 * 1000); + if (urlConn != null && urlConn.getInputStream() != null) { + in = new InputStreamReader(urlConn.getInputStream(), Charset.defaultCharset()); + BufferedReader bufferedReader = new BufferedReader(in); + if (bufferedReader != null) { + int cp; + while ((cp = bufferedReader.read()) != -1) { + sb.append((char) cp); + } + bufferedReader.close(); + } + } + in.close(); + } catch (Exception e) { + throw new RuntimeException("Exception while calling URL:" + any_url, e); + } + return sb.toString(); + } + /** + * @param xmlString + * @return + */ + public Document TransformXMLStringToXMLDocument(String xmlString) { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setNamespaceAware(true); + DocumentBuilder builder = null; + try { + builder = factory.newDocumentBuilder(); + Document doc = builder.parse(new InputSource(new StringReader(xmlString))); + return doc; + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + /** + * Description: Send GET request with parameters and return Response as String + * + * @param any_url + * @param params + * @return + */ + public String GetContentFromGETKVPRequest(String any_url, Map params) { + StringBuilder sb = new StringBuilder(); + HttpURLConnection urlConn = null; + InputStreamReader in = null; + try { + StringBuilder Data = new StringBuilder(); + for (Map.Entry param : params.entrySet()) { + if (Data.length() != 0) + Data.append('&'); + Data.append(URLEncoder.encode(param.getKey(), "UTF-8")); + Data.append('='); + Data.append(URLEncoder.encode(String.valueOf(param.getValue()), "UTF-8")); + } + + URL url = new URL(any_url + "?" + Data.toString()); + urlConn = (HttpURLConnection) url.openConnection(); + urlConn.setRequestMethod("GET"); + urlConn.setDoOutput(true); + if (urlConn != null) + urlConn.setReadTimeout(60 * 1000); + if (urlConn != null && urlConn.getInputStream() != null) { + in = new InputStreamReader(urlConn.getInputStream(), Charset.defaultCharset()); + BufferedReader bufferedReader = new BufferedReader(in); + if (bufferedReader != null) { + int cp; + while ((cp = bufferedReader.read()) != -1) { + sb.append((char) cp); + } + bufferedReader.close(); + } + } + in.close(); + } catch (Exception e) { + throw new RuntimeException("Exception while calling URL:" + any_url, e); + } + return sb.toString(); + } + /** + * @param URI + * @return + */ + public Document TransformXMLFileToXMLDocument(String URI) { + DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); + factory.setNamespaceAware(true); + DocumentBuilder builder = null; + try { + builder = factory.newDocumentBuilder(); + Document doc = builder.parse(new File(URI)); + return doc; + } catch (Exception e) { + e.printStackTrace(); + } + return null; + } + /** + * @param xmlDoc + * @throws Exception + */ + public String TransformXMLDocumentToXMLString(Document xmlDoc) throws Exception { + Transformer tf = TransformerFactory.newInstance().newTransformer(); + tf.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); + tf.setOutputProperty(OutputKeys.INDENT, "yes"); + Writer out = new StringWriter(); + tf.transform(new DOMSource(xmlDoc), new StreamResult(out)); + return out.toString(); + } + /** + * @param xmlDoc + * @throws Exception + */ + public void prettyPrint(Document xmlDoc) throws Exception { + String str = TransformXMLDocumentToXMLString(xmlDoc); + System.out.println(str); + } + public HttpURLConnection GetConnection(String serviceURL) throws IOException { + URL urlObj = new URL(serviceURL); + return (HttpURLConnection) urlObj.openConnection(); + } } diff --git a/src/main/java/org/opengis/cite/wps20/asynchronous/AsyncTests.java b/src/main/java/org/opengis/cite/wps20/asynchronous/AsyncTests.java new file mode 100644 index 0000000..29606cc --- /dev/null +++ b/src/main/java/org/opengis/cite/wps20/asynchronous/AsyncTests.java @@ -0,0 +1,442 @@ +package org.opengis.cite.wps20.asynchronous; + +import static org.testng.Assert.assertTrue; + +import java.io.BufferedReader; +import java.io.DataOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.StringReader; +import java.io.StringWriter; +import java.io.Writer; +import java.net.HttpURLConnection; +import java.net.URI; +//import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +//import java.net.URLConnection; +import java.net.URLEncoder; +import java.nio.charset.Charset; +//import java.util.ArrayList; +//import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashMap; +//import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.Random; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.OutputKeys; +//import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; +import javax.xml.validation.Schema; +import javax.xml.validation.Validator; + +//import org.opengis.cite.wps20.Namespaces; +//import org.opengis.cite.wps20.SuiteAttribute; +import org.opengis.cite.wps20.CommonFixture; +import org.opengis.cite.wps20.basictests.BasicTests; +import org.testng.Assert; +import org.testng.annotations.Test; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +//import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +/*import net.sf.saxon.s9api.Processor; +import net.sf.saxon.s9api.SaxonApiException; +import net.sf.saxon.s9api.XPathCompiler; +import net.sf.saxon.s9api.XPathSelector; +import net.sf.saxon.s9api.XdmNode; +import net.sf.saxon.s9api.XdmValue;*/ + +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. + * Flow of Test Description: Send a valid XML Execute request to the server under test, + * setting the “mode” attribute to “async”. Verify that a valid wps:StatusInfo document + * is returned. Extract the wps:JobID. Send a valid XML GetStatus request to the server + * under test using the extracted JobID. Test passes if a valid wps:StatusInfo document + * is returned. + * + * @throws Exception + */ + @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); + Element executeElement = (Element) literalDocument + .getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "Execute").item(0); + executeElement.setAttribute("mode", "async"); + executeElement.setAttribute("response", "document"); + + String VAEXmlString = GetContentFromPOSTXMLRequest(SERVICE_URL, literalDocument); + Document VAEDocument = TransformXMLStringToXMLDocument(VAEXmlString); + + Boolean VAE_Flag = (VAEDocument.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "StatusInfo").getLength() > 0) ? true : false; + + if (VAE_Flag) { + Element JobIDElement1 = (Element) VAEDocument + .getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "JobID").item(0); + + URI URIGetStatusTemplate = BasicTests.class.getResource(GET_STATUS_TEMPLATE_PATH).toURI(); + Document GetStatusDocument = URIUtils.parseURI(URIGetStatusTemplate); + Element JobIDElement2 = (Element) GetStatusDocument + .getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "JobID").item(0); + JobIDElement2.setTextContent(JobIDElement1.getTextContent()); + + String VGSXmlString = GetContentFromPOSTXMLRequest(SERVICE_URL, GetStatusDocument); + Document VGSDocument = TransformXMLStringToXMLDocument(VGSXmlString); + + Boolean VGS_Flag = (VGSDocument.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "Status").getLength() > 0) ? true : false; + + if (VGS_Flag) { + String msg = "Valid GetStatus via POST/XML for WPS 2.0"; + Assert.assertTrue(VGS_Flag, msg); + } else { + String msg = "Invalid GetStatus via POST/XML for WPS 2.0"; + Assert.assertTrue(VGS_Flag, msg); + } + } else { + String msg = "Invalid Execute via POST/XML for WPS 2.0"; + Assert.assertTrue(VAE_Flag, msg); + } + } + + /** + * A.5.15. VSend a valid XML Execute request to the server under test, setting the “mode” + * attribute to “async”. Modulate the “response” parameter. Verify that a valid wps:StatusInfo + * document is returned. Extract the wps:JobID. Check the status of the job. If the job + * succeeded, send a valid XML GetResult request to the server under test using the extracted + * JobID. Depending on the value of the “response” parameter of the above Execute request. + * + * @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); + Element executeElement = (Element) literalDocument + .getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "Execute").item(0); + executeElement.setAttribute("mode", "async"); + executeElement.setAttribute("response", "raw"); + String VAEXmlString1 = GetContentFromPOSTXMLRequest(SERVICE_URL, literalDocument); + Document VAEDocument1 = TransformXMLStringToXMLDocument(VAEXmlString1); + Boolean VAE_Flag1 = (VAEDocument1.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "StatusInfo").getLength() > 0) ? true : false; + + executeElement.setAttribute("response", "document"); + String VAEXmlString2 = GetContentFromPOSTXMLRequest(SERVICE_URL, literalDocument); + Document VAEDocument2 = TransformXMLStringToXMLDocument(VAEXmlString2); + Boolean VAE_Flag2 = (VAEDocument2.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "StatusInfo").getLength() > 0) ? true : false; + + Boolean VAE_Flag = VAE_Flag1 && VAE_Flag2; + + if (VAE_Flag) { + URI URIGetResultTemplate1 = BasicTests.class.getResource(GET_RESULT_TEMPLATE_PATH).toURI(); + Element JobIDElement1 = (Element) VAEDocument1.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "JobID").item(0); + Document GetResultDocument1 = URIUtils.parseURI(URIGetResultTemplate1); + Element JobIDElement2 = (Element) GetResultDocument1.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "JobID").item(0); + JobIDElement2.setTextContent(JobIDElement1.getTextContent()); + String VGRXmlString1 = GetContentFromPOSTXMLRequest(SERVICE_URL, GetResultDocument1); + Document VGRDocument1 = TransformXMLStringToXMLDocument(VGRXmlString1); + Boolean VGR_Flag1 = (VGRDocument1.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "LiteralValue").getLength() > 0) ? true : false; + + URI URIGetResultTemplate2 = BasicTests.class.getResource(GET_RESULT_TEMPLATE_PATH).toURI(); + Element JobIDElement3 = (Element) VAEDocument2.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "JobID").item(0); + Document GetResultDocument2 = URIUtils.parseURI(URIGetResultTemplate2); + Element JobIDElement4 = (Element) GetResultDocument2.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "JobID").item(0); + JobIDElement4.setTextContent(JobIDElement3.getTextContent()); + String VGRXmlString2 = GetContentFromPOSTXMLRequest(SERVICE_URL, GetResultDocument2); + + Boolean VGR_Flag2 = VGRXmlString2.contains("LiteralValue") ? true : false; + +// Document VGRDocument2 = TransformXMLStringToXMLDocument(VGRXmlString2); +// Boolean VGR_Flag2 = (VGRDocument2.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "Result").getLength() > 0) ? true : false; + + Boolean VGR_Flag = VGR_Flag1 && VGR_Flag2; + + if (VGR_Flag) { + String msg = "Valid GetResult via POST/XML for WPS 2.0"; + Assert.assertTrue(VGR_Flag, msg); + } else { + String msg = "Invalid GetResult via POST/XML for WPS 2.0"; + Assert.assertTrue(VGR_Flag, msg); + } + } else { + String msg = "Invalid Execute via POST/XML for WPS 2.0"; + Assert.assertTrue(VAE_Flag, msg); + } + } + + + + /** + * A.5.18. Verify that the server can handle GetStatus requests via GET/KVP. + * Send a valid XML Execute request to the server under test, setting the “mode” attribute + * to “async”. Verify that a valid wps:StatusInfo document is returned. Extract the + * wps:JobID. Send a valid KVP GetStatus request to the server under test, using the + * extracted JobID and modulating upper and lower case of the parameter names. Test passes + * if a valid document of the type wps:StatusInfo is returned. + * @throws IOException + * @throws URISyntaxException + * @throws SAXException + */ + @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); + Element executeElement = (Element) literalDocument + .getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "Execute").item(0); + executeElement.setAttribute("mode", "async"); + executeElement.setAttribute("response", "document"); + + String VAEXmlString = GetContentFromPOSTXMLRequest(SERVICE_URL, literalDocument); + Document VAEDocument = TransformXMLStringToXMLDocument(VAEXmlString); + + Boolean VAE_Flag = (VAEDocument.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "StatusInfo").getLength() > 0) ? true : false; + + if (VAE_Flag) { + Element JobIDElement1 = (Element) VAEDocument + .getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "JobID").item(0); + + Map GSU_Parameters = new LinkedHashMap<>(); + GSU_Parameters.put("Service".toUpperCase(), "WPS"); + GSU_Parameters.put("Version".toUpperCase(), "2.0.0"); + GSU_Parameters.put("Request".toUpperCase(), "GetStatus"); + GSU_Parameters.put("JobID".toUpperCase(), JobIDElement1.getTextContent()); + String GSU_XmlString = GetContentFromGETKVPRequest(SERVICE_URL, GSU_Parameters); + Document GSU_Document = TransformXMLStringToXMLDocument(GSU_XmlString); + + Map GSL_Parameters = new LinkedHashMap<>(); + GSL_Parameters.put("Service".toLowerCase(), "WPS"); + GSL_Parameters.put("Version".toLowerCase(), "2.0.0"); + GSL_Parameters.put("Request".toLowerCase(), "GetStatus"); + GSL_Parameters.put("JobID".toLowerCase(), JobIDElement1.getTextContent()); + String GSL_XmlString = GetContentFromGETKVPRequest(SERVICE_URL, GSL_Parameters); + Document GSL_Document = TransformXMLStringToXMLDocument(GSL_XmlString); + + Boolean GS_KVP_Flag = (GSU_Document.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "Status").getLength() > 0 + && GSL_Document.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "Status").getLength() > 0) ? true : false; + + if (GS_KVP_Flag) { + String msg = "Valid GetStatus via GET/KVP for WPS 2.0"; + Assert.assertTrue(GS_KVP_Flag, msg); + } else { + String msg = "Invalid GetStatus via GET/KVP for WPS 2.0"; + Assert.assertTrue(GS_KVP_Flag, msg); + } + } else { + String msg = "Invalid Execute via POST/XML for WPS 2.0"; + Assert.assertTrue(VAE_Flag, msg); + } + } + + /** + * A.5.19. Verify that the server can handle GetResult requests via GET/KVP. + * Send a valid XML Execute request to the server under test, setting the “mode” attribute + * to “async”. Modulate the “response” parameter. Verify that a valid wps:StatusInfo + * document is returned. Extract the wps:JobID. Check the status of the job. If the job + * succeeded, send a valid KVP GetResult request to the server under test using the + * extracted JobID and modulating upper and lower case of the parameter names. Depending + * on the value of the “response” parameter of the above Execute request: + * - Parameter value equal “document”. Verify that a valid Execute wps:Result document is returned. + * - Parameter equal to “raw”. Verify that raw is returned. + * @throws IOException + * @throws URISyntaxException + * @throws SAXException + */ + @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); + Element executeElement = (Element) literalDocument + .getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "Execute").item(0); + executeElement.setAttribute("mode", "async"); + + executeElement.setAttribute("response", "document"); + String VAEXmlString1 = GetContentFromPOSTXMLRequest(SERVICE_URL, literalDocument); + Document VAEDocument1 = TransformXMLStringToXMLDocument(VAEXmlString1); + Boolean VAE_Flag1 = (VAEDocument1.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "StatusInfo").getLength() > 0) ? true : false; + + executeElement.setAttribute("response", "raw"); + String VAEXmlString2 = GetContentFromPOSTXMLRequest(SERVICE_URL, literalDocument); + Document VAEDocument2 = TransformXMLStringToXMLDocument(VAEXmlString2); + Boolean VAE_Flag2 = (VAEDocument2.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "StatusInfo").getLength() > 0) ? true : false; + + Boolean VAE_Flag = VAE_Flag1 && VAE_Flag2; + + if (VAE_Flag) { + Element JobIDElement1 = (Element) VAEDocument1 + .getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "JobID").item(0); + CheckGetStatus(SERVICE_URL, JobIDElement1.getTextContent()); + Map GR_Parameters1 = new LinkedHashMap<>(); + GR_Parameters1.put("Service", "WPS"); + GR_Parameters1.put("Version", "2.0.0"); + GR_Parameters1.put("Request", "GetResult"); + GR_Parameters1.put("JobID", JobIDElement1.getTextContent()); + String GR_XmlString1 = GetContentFromGETKVPRequest(SERVICE_URL, GR_Parameters1); + Document GR_Document1 = TransformXMLStringToXMLDocument(GR_XmlString1); + + Boolean VGR_Flag1 = (GR_Document1.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "Result").getLength() > 0) ? true : false; + + Element JobIDElement2 = (Element) VAEDocument2 + .getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "JobID").item(0); + CheckGetStatus(SERVICE_URL, JobIDElement2.getTextContent()); + Map GR_Parameters2 = new LinkedHashMap<>(); + GR_Parameters2.put("Service", "WPS"); + GR_Parameters2.put("Version", "2.0.0"); + GR_Parameters2.put("Request", "GetResult"); + GR_Parameters2.put("JobID", JobIDElement2.getTextContent()); + String GR_XmlString2 = GetContentFromGETKVPRequest(SERVICE_URL, GR_Parameters2); +// System.out.println(GR_XmlString2); +// System.out.println(JobIDElement2.getTextContent()); + +// Boolean VGR_Flag2 = GR_XmlString2.contains("wps:LiteralValue") ? true : false; + + Document GR_Document2 = TransformXMLStringToXMLDocument(GR_XmlString2); + Boolean VGR_Flag2 = (GR_Document2.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "LiteralValue").getLength() > 0) ? true : false; + + Boolean VGR_Flag = VGR_Flag1 && VGR_Flag2; + + if (VGR_Flag) { + String msg = "Valid GetResult via GET/KVP for WPS 2.0"; + Assert.assertTrue(VGR_Flag, msg); + } else { + String msg = "Invalid GetResult via GET/KVP for WPS 2.0"; + Assert.assertTrue(VGR_Flag, msg); + } + } else { + String msg = "Invalid Execute via POST/XML for WPS 2.0"; + Assert.assertTrue(VAE_Flag, msg); + } + } + + public void CheckGetStatus(String SERVICE_URL, String jobID) { + Map GR_Parameters1 = new LinkedHashMap<>(); + GR_Parameters1.put("Service", "WPS"); + GR_Parameters1.put("Version", "2.0.0"); + GR_Parameters1.put("Request", "GetStatus"); + GR_Parameters1.put("JobID", jobID); + + String GR_XmlString1 = GetContentFromGETKVPRequest(SERVICE_URL, GR_Parameters1); + Document docGetStatus = TransformXMLStringToXMLDocument(GR_XmlString1); + Boolean statusFlag = (docGetStatus.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "Status").getLength() > 0) ? true : false; + String msg = "Invalid GetStatus via GET/KVP for WPS 2.0"; + if (!statusFlag) + Assert.assertTrue(false, msg); + else { + Element statusElement = (Element) docGetStatus.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "Status").item(0); + String status = statusElement.getTextContent(); + if (status.toLowerCase().equals("succeeded")) { + return; + } + else { + Assert.assertTrue(false, msg); + } + } + } + + + 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/level1/BasicTests.java b/src/main/java/org/opengis/cite/wps20/basictests/BasicTests.java similarity index 64% rename from src/main/java/org/opengis/cite/wps20/level1/BasicTests.java rename to src/main/java/org/opengis/cite/wps20/basictests/BasicTests.java index d628a94..171ff5d 100644 --- a/src/main/java/org/opengis/cite/wps20/level1/BasicTests.java +++ b/src/main/java/org/opengis/cite/wps20/basictests/BasicTests.java @@ -1,4 +1,4 @@ -package org.opengis.cite.wps20.level1; +package org.opengis.cite.wps20.basictests; import static org.testng.Assert.assertTrue; @@ -629,86 +629,6 @@ public void ValidDescribeProcessViaPOSTXML() throws IOException, URISyntaxExcept } } - /** - * 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 - * request to the server under test, setting the “mode” attribute to “sync”. - * Verify that a valid Execute wps:Result is returned. - * - * @throws Exception - */ - @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); - - // Response document - Element executeElement = (Element) literalDocument - .getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "Execute").item(0); - executeElement.setAttribute("mode", "sync"); - executeElement.setAttribute("response", "document"); - - /* - * try { prettyPrint(literalDocument); } catch (Exception e) { // TODO - * Auto-generated catch block e.printStackTrace(); } - */ - - - /* - * // Code by Aries //status code is 200 response validation HttpURLConnection - * conn = GetConnection(SERVICE_URL); conn.setRequestMethod("POST"); - * conn.setRequestProperty("Content-Type", "application/xml"); - * conn.setDoOutput(true); - * - * DataOutputStream outputStream = new DataOutputStream(conn.getOutputStream()); - * String xml = TransformXMLDocumentToXMLString(literalDocument); - * outputStream.writeBytes(xml); outputStream.flush(); outputStream.close(); - * - * int responseCode = conn.getResponseCode(); boolean respDocFlag = - * (responseCode == HttpURLConnection.HTTP_OK); - */ - - String respDocResult = GetContentFromPOSTXMLRequest(SERVICE_URL, literalDocument); - Document respDocResultDocument = TransformXMLStringToXMLDocument(respDocResult); - boolean respDocFlag = respDocResultDocument.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "Result").getLength() > 0; - String msg = "Invalid SyncExecute via POST/XML for WPS 2.0"; - assertTrue(respDocFlag, msg); - - // Raw data output - executeElement.setAttribute("response", "raw"); - - /* - * try { prettyPrint(literalDocument); } catch (Exception e) { // TODO - * Auto-generated catch block e.printStackTrace(); } - */ - - String respRawResult = GetContentFromPOSTXMLRequest(SERVICE_URL, literalDocument); - boolean VSE_Flag = respRawResult.contains("hello_literal"); - - if (VSE_Flag) { - String msg1 = "Valid SyncExecute via POST/XML for WPS 2.0"; - Assert.assertTrue(VSE_Flag, msg1); - } else { - String msg1 = "Invalid SyncExecute via POST/XML for WPS 2.0"; - Assert.assertTrue(VSE_Flag, msg1); - } - - /* - * // The Process Flow should as this one String VSEXmlString = - * GetContentFromPOSTXMLRequest(SERVICE_URL, literalDocument); Document - * VSEDocument = TransformXMLStringToXMLDocument(VSEXmlString); Boolean VSE_Flag - * = (VSEDocument.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", - * "Result").getLength() > 0) ? true : false; if (VSE_Flag) { String msg = - * "Valid SyncExecute via POST/XML for WPS 2.0"; Assert.assertTrue(VSE_Flag, - * msg); } else { String msg = "Invalid SyncExecute via POST/XML for WPS 2.0"; - * Assert.assertTrue(VSE_Flag, msg); } - */ - } public void ProcessEchoProcessLiteralDataRequest(String SERVICE_URL, Document SEPDocument) { // Get the processid from user and replace the processid in the template xml @@ -929,129 +849,6 @@ public void ValidAutoExcecuteViaPOSTXML() throws Exception { } } - /** - * A.5.14. Verify that the server can handle GetStatus requests via POST/XML. - * Flow of Test Description: Send a valid XML Execute request to the server under test, - * setting the “mode” attribute to “async”. Verify that a valid wps:StatusInfo document - * is returned. Extract the wps:JobID. Send a valid XML GetStatus request to the server - * under test using the extracted JobID. Test passes if a valid wps:StatusInfo document - * is returned. - * - * @throws Exception - */ - @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); - Element executeElement = (Element) literalDocument - .getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "Execute").item(0); - executeElement.setAttribute("mode", "async"); - executeElement.setAttribute("response", "document"); - - String VAEXmlString = GetContentFromPOSTXMLRequest(SERVICE_URL, literalDocument); - Document VAEDocument = TransformXMLStringToXMLDocument(VAEXmlString); - - Boolean VAE_Flag = (VAEDocument.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "StatusInfo").getLength() > 0) ? true : false; - - if (VAE_Flag) { - Element JobIDElement1 = (Element) VAEDocument - .getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "JobID").item(0); - - URI URIGetStatusTemplate = BasicTests.class.getResource(GET_STATUS_TEMPLATE_PATH).toURI(); - Document GetStatusDocument = URIUtils.parseURI(URIGetStatusTemplate); - Element JobIDElement2 = (Element) GetStatusDocument - .getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "JobID").item(0); - JobIDElement2.setTextContent(JobIDElement1.getTextContent()); - - String VGSXmlString = GetContentFromPOSTXMLRequest(SERVICE_URL, GetStatusDocument); - Document VGSDocument = TransformXMLStringToXMLDocument(VGSXmlString); - - Boolean VGS_Flag = (VGSDocument.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "Status").getLength() > 0) ? true : false; - - if (VGS_Flag) { - String msg = "Valid GetStatus via POST/XML for WPS 2.0"; - Assert.assertTrue(VGS_Flag, msg); - } else { - String msg = "Invalid GetStatus via POST/XML for WPS 2.0"; - Assert.assertTrue(VGS_Flag, msg); - } - } else { - String msg = "Invalid Execute via POST/XML for WPS 2.0"; - Assert.assertTrue(VAE_Flag, msg); - } - } - - /** - * A.5.15. VSend a valid XML Execute request to the server under test, setting the “mode” - * attribute to “async”. Modulate the “response” parameter. Verify that a valid wps:StatusInfo - * document is returned. Extract the wps:JobID. Check the status of the job. If the job - * succeeded, send a valid XML GetResult request to the server under test using the extracted - * JobID. Depending on the value of the “response” parameter of the above Execute request. - * - * @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); - Element executeElement = (Element) literalDocument - .getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "Execute").item(0); - executeElement.setAttribute("mode", "async"); - executeElement.setAttribute("response", "raw"); - String VAEXmlString1 = GetContentFromPOSTXMLRequest(SERVICE_URL, literalDocument); - Document VAEDocument1 = TransformXMLStringToXMLDocument(VAEXmlString1); - Boolean VAE_Flag1 = (VAEDocument1.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "StatusInfo").getLength() > 0) ? true : false; - - executeElement.setAttribute("response", "document"); - String VAEXmlString2 = GetContentFromPOSTXMLRequest(SERVICE_URL, literalDocument); - Document VAEDocument2 = TransformXMLStringToXMLDocument(VAEXmlString2); - Boolean VAE_Flag2 = (VAEDocument2.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "StatusInfo").getLength() > 0) ? true : false; - - Boolean VAE_Flag = VAE_Flag1 && VAE_Flag2; - - if (VAE_Flag) { - URI URIGetResultTemplate1 = BasicTests.class.getResource(GET_RESULT_TEMPLATE_PATH).toURI(); - Element JobIDElement1 = (Element) VAEDocument1.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "JobID").item(0); - Document GetResultDocument1 = URIUtils.parseURI(URIGetResultTemplate1); - Element JobIDElement2 = (Element) GetResultDocument1.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "JobID").item(0); - JobIDElement2.setTextContent(JobIDElement1.getTextContent()); - String VGRXmlString1 = GetContentFromPOSTXMLRequest(SERVICE_URL, GetResultDocument1); - Document VGRDocument1 = TransformXMLStringToXMLDocument(VGRXmlString1); - Boolean VGR_Flag1 = (VGRDocument1.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "LiteralValue").getLength() > 0) ? true : false; - - URI URIGetResultTemplate2 = BasicTests.class.getResource(GET_RESULT_TEMPLATE_PATH).toURI(); - Element JobIDElement3 = (Element) VAEDocument2.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "JobID").item(0); - Document GetResultDocument2 = URIUtils.parseURI(URIGetResultTemplate2); - Element JobIDElement4 = (Element) GetResultDocument2.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "JobID").item(0); - JobIDElement4.setTextContent(JobIDElement3.getTextContent()); - String VGRXmlString2 = GetContentFromPOSTXMLRequest(SERVICE_URL, GetResultDocument2); - - Boolean VGR_Flag2 = VGRXmlString2.contains("LiteralValue") ? true : false; - -// Document VGRDocument2 = TransformXMLStringToXMLDocument(VGRXmlString2); -// Boolean VGR_Flag2 = (VGRDocument2.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "Result").getLength() > 0) ? true : false; - - Boolean VGR_Flag = VGR_Flag1 && VGR_Flag2; - - if (VGR_Flag) { - String msg = "Valid GetResult via POST/XML for WPS 2.0"; - Assert.assertTrue(VGR_Flag, msg); - } else { - String msg = "Invalid GetResult via POST/XML for WPS 2.0"; - Assert.assertTrue(VGR_Flag, msg); - } - } else { - String msg = "Invalid Execute via POST/XML for WPS 2.0"; - Assert.assertTrue(VAE_Flag, msg); - } - } - /** * A.5.16. Verify that the server can handle GetCapabilities requests via * GET/KVP @@ -1141,178 +938,6 @@ private void ValidDescribeProcessViaGETKVP() throws IOException, URISyntaxExcept } } - /** - * A.5.18. Verify that the server can handle GetStatus requests via GET/KVP. - * Send a valid XML Execute request to the server under test, setting the “mode” attribute - * to “async”. Verify that a valid wps:StatusInfo document is returned. Extract the - * wps:JobID. Send a valid KVP GetStatus request to the server under test, using the - * extracted JobID and modulating upper and lower case of the parameter names. Test passes - * if a valid document of the type wps:StatusInfo is returned. - * @throws IOException - * @throws URISyntaxException - * @throws SAXException - */ - @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 ValidGetStausViaGETKVP() 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); - Element executeElement = (Element) literalDocument - .getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "Execute").item(0); - executeElement.setAttribute("mode", "async"); - executeElement.setAttribute("response", "document"); - - String VAEXmlString = GetContentFromPOSTXMLRequest(SERVICE_URL, literalDocument); - Document VAEDocument = TransformXMLStringToXMLDocument(VAEXmlString); - - Boolean VAE_Flag = (VAEDocument.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "StatusInfo").getLength() > 0) ? true : false; - - if (VAE_Flag) { - Element JobIDElement1 = (Element) VAEDocument - .getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "JobID").item(0); - - Map GSU_Parameters = new LinkedHashMap<>(); - GSU_Parameters.put("Service".toUpperCase(), "WPS"); - GSU_Parameters.put("Version".toUpperCase(), "2.0.0"); - GSU_Parameters.put("Request".toUpperCase(), "GetStatus"); - GSU_Parameters.put("JobID".toUpperCase(), JobIDElement1.getTextContent()); - String GSU_XmlString = GetContentFromGETKVPRequest(SERVICE_URL, GSU_Parameters); - Document GSU_Document = TransformXMLStringToXMLDocument(GSU_XmlString); - - Map GSL_Parameters = new LinkedHashMap<>(); - GSL_Parameters.put("Service".toLowerCase(), "WPS"); - GSL_Parameters.put("Version".toLowerCase(), "2.0.0"); - GSL_Parameters.put("Request".toLowerCase(), "GetStatus"); - GSL_Parameters.put("JobID".toLowerCase(), JobIDElement1.getTextContent()); - String GSL_XmlString = GetContentFromGETKVPRequest(SERVICE_URL, GSL_Parameters); - Document GSL_Document = TransformXMLStringToXMLDocument(GSL_XmlString); - - Boolean GS_KVP_Flag = (GSU_Document.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "Status").getLength() > 0 - && GSL_Document.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "Status").getLength() > 0) ? true : false; - - if (GS_KVP_Flag) { - String msg = "Valid GetStatus via GET/KVP for WPS 2.0"; - Assert.assertTrue(GS_KVP_Flag, msg); - } else { - String msg = "Invalid GetStatus via GET/KVP for WPS 2.0"; - Assert.assertTrue(GS_KVP_Flag, msg); - } - } else { - String msg = "Invalid Execute via POST/XML for WPS 2.0"; - Assert.assertTrue(VAE_Flag, msg); - } - } - - /** - * A.5.19. Verify that the server can handle GetResult requests via GET/KVP. - * Send a valid XML Execute request to the server under test, setting the “mode” attribute - * to “async”. Modulate the “response” parameter. Verify that a valid wps:StatusInfo - * document is returned. Extract the wps:JobID. Check the status of the job. If the job - * succeeded, send a valid KVP GetResult request to the server under test using the - * extracted JobID and modulating upper and lower case of the parameter names. Depending - * on the value of the “response” parameter of the above Execute request: - * - Parameter value equal “document”. Verify that a valid Execute wps:Result document is returned. - * - Parameter equal to “raw”. Verify that raw is returned. - * @throws IOException - * @throws URISyntaxException - * @throws SAXException - */ - @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); - Element executeElement = (Element) literalDocument - .getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "Execute").item(0); - executeElement.setAttribute("mode", "async"); - - executeElement.setAttribute("response", "document"); - String VAEXmlString1 = GetContentFromPOSTXMLRequest(SERVICE_URL, literalDocument); - Document VAEDocument1 = TransformXMLStringToXMLDocument(VAEXmlString1); - Boolean VAE_Flag1 = (VAEDocument1.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "StatusInfo").getLength() > 0) ? true : false; - - executeElement.setAttribute("response", "raw"); - String VAEXmlString2 = GetContentFromPOSTXMLRequest(SERVICE_URL, literalDocument); - Document VAEDocument2 = TransformXMLStringToXMLDocument(VAEXmlString2); - Boolean VAE_Flag2 = (VAEDocument2.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "StatusInfo").getLength() > 0) ? true : false; - - Boolean VAE_Flag = VAE_Flag1 && VAE_Flag2; - - if (VAE_Flag) { - Element JobIDElement1 = (Element) VAEDocument1 - .getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "JobID").item(0); - CheckGetStatus(SERVICE_URL, JobIDElement1.getTextContent()); - Map GR_Parameters1 = new LinkedHashMap<>(); - GR_Parameters1.put("Service", "WPS"); - GR_Parameters1.put("Version", "2.0.0"); - GR_Parameters1.put("Request", "GetResult"); - GR_Parameters1.put("JobID", JobIDElement1.getTextContent()); - String GR_XmlString1 = GetContentFromGETKVPRequest(SERVICE_URL, GR_Parameters1); - Document GR_Document1 = TransformXMLStringToXMLDocument(GR_XmlString1); - - Boolean VGR_Flag1 = (GR_Document1.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "Result").getLength() > 0) ? true : false; - - Element JobIDElement2 = (Element) VAEDocument2 - .getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "JobID").item(0); - CheckGetStatus(SERVICE_URL, JobIDElement2.getTextContent()); - Map GR_Parameters2 = new LinkedHashMap<>(); - GR_Parameters2.put("Service", "WPS"); - GR_Parameters2.put("Version", "2.0.0"); - GR_Parameters2.put("Request", "GetResult"); - GR_Parameters2.put("JobID", JobIDElement2.getTextContent()); - String GR_XmlString2 = GetContentFromGETKVPRequest(SERVICE_URL, GR_Parameters2); -// System.out.println(GR_XmlString2); -// System.out.println(JobIDElement2.getTextContent()); - -// Boolean VGR_Flag2 = GR_XmlString2.contains("wps:LiteralValue") ? true : false; - - Document GR_Document2 = TransformXMLStringToXMLDocument(GR_XmlString2); - Boolean VGR_Flag2 = (GR_Document2.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "LiteralValue").getLength() > 0) ? true : false; - - Boolean VGR_Flag = VGR_Flag1 && VGR_Flag2; - - if (VGR_Flag) { - String msg = "Valid GetResult via GET/KVP for WPS 2.0"; - Assert.assertTrue(VGR_Flag, msg); - } else { - String msg = "Invalid GetResult via GET/KVP for WPS 2.0"; - Assert.assertTrue(VGR_Flag, msg); - } - } else { - String msg = "Invalid Execute via POST/XML for WPS 2.0"; - Assert.assertTrue(VAE_Flag, msg); - } - } - - public void CheckGetStatus(String SERVICE_URL, String jobID) { - Map GR_Parameters1 = new LinkedHashMap<>(); - GR_Parameters1.put("Service", "WPS"); - GR_Parameters1.put("Version", "2.0.0"); - GR_Parameters1.put("Request", "GetStatus"); - GR_Parameters1.put("JobID", jobID); - - String GR_XmlString1 = GetContentFromGETKVPRequest(SERVICE_URL, GR_Parameters1); - Document docGetStatus = TransformXMLStringToXMLDocument(GR_XmlString1); - Boolean statusFlag = (docGetStatus.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "Status").getLength() > 0) ? true : false; - String msg = "Invalid GetStatus via GET/KVP for WPS 2.0"; - if (!statusFlag) - Assert.assertTrue(false, msg); - else { - Element statusElement = (Element) docGetStatus.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "Status").item(0); - String status = statusElement.getTextContent(); - if (status.toLowerCase().equals("succeeded")) { - return; - } - else { - Assert.assertTrue(false, msg); - } - } - } - public void TestPostWithDocumentAndAssertMessage(String SERVICE_URL, Document literalDocument, String message) throws Exception { // status code is 200 response validation @@ -1351,63 +976,10 @@ private static boolean isXMLSchemaValid(String xmlString, String xsdPath) { return true; } - /** - * @param xmlString - * @return - */ - private static Document TransformXMLStringToXMLDocument(String xmlString) { - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - factory.setNamespaceAware(true); - DocumentBuilder builder = null; - try { - builder = factory.newDocumentBuilder(); - Document doc = builder.parse(new InputSource(new StringReader(xmlString))); - return doc; - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } - /** - * @param URI - * @return - */ - private static Document TransformXMLFileToXMLDocument(String URI) { - DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance(); - factory.setNamespaceAware(true); - DocumentBuilder builder = null; - try { - builder = factory.newDocumentBuilder(); - Document doc = builder.parse(new File(URI)); - return doc; - } catch (Exception e) { - e.printStackTrace(); - } - return null; - } - /** - * @param xmlDoc - * @throws Exception - */ - private static String TransformXMLDocumentToXMLString(Document xmlDoc) throws Exception { - Transformer tf = TransformerFactory.newInstance().newTransformer(); - tf.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); - tf.setOutputProperty(OutputKeys.INDENT, "yes"); - Writer out = new StringWriter(); - tf.transform(new DOMSource(xmlDoc), new StreamResult(out)); - return out.toString(); - } - /** - * @param xmlDoc - * @throws Exception - */ - private static void prettyPrint(Document xmlDoc) throws Exception { - String str = TransformXMLDocumentToXMLString(xmlDoc); - System.out.println(str); - } + /** * Description: Identify that URL could get the response or not @@ -1432,99 +1004,6 @@ private static Boolean IsValidHTTP(String any_url, Map params) t return (responseCode != HttpURLConnection.HTTP_OK) ? false : true; } - /** - * Description: Send GET request with parameters and return Response as String - * - * @param any_url - * @param params - * @return - */ - private static String GetContentFromGETKVPRequest(String any_url, Map params) { - StringBuilder sb = new StringBuilder(); - HttpURLConnection urlConn = null; - InputStreamReader in = null; - try { - StringBuilder Data = new StringBuilder(); - for (Map.Entry param : params.entrySet()) { - if (Data.length() != 0) - Data.append('&'); - Data.append(URLEncoder.encode(param.getKey(), "UTF-8")); - Data.append('='); - Data.append(URLEncoder.encode(String.valueOf(param.getValue()), "UTF-8")); - } - URL url = new URL(any_url + "?" + Data.toString()); - urlConn = (HttpURLConnection) url.openConnection(); - urlConn.setRequestMethod("GET"); - urlConn.setDoOutput(true); - if (urlConn != null) - urlConn.setReadTimeout(60 * 1000); - if (urlConn != null && urlConn.getInputStream() != null) { - in = new InputStreamReader(urlConn.getInputStream(), Charset.defaultCharset()); - BufferedReader bufferedReader = new BufferedReader(in); - if (bufferedReader != null) { - int cp; - while ((cp = bufferedReader.read()) != -1) { - sb.append((char) cp); - } - bufferedReader.close(); - } - } - in.close(); - } catch (Exception e) { - throw new RuntimeException("Exception while calling URL:" + any_url, e); - } - return sb.toString(); - } - - /** - * Description: Send POST request with parameters and return Response as String - * - * @param any_url - * @param params - * @return - */ - private static String GetContentFromPOSTXMLRequest(String any_url, Document xml_doc) { - StringBuilder sb = new StringBuilder(); - HttpURLConnection urlConn = null; - InputStreamReader in = null; - try { - Transformer tf = TransformerFactory.newInstance().newTransformer(); - tf.setOutputProperty(OutputKeys.ENCODING, "UTF-8"); - tf.setOutputProperty(OutputKeys.INDENT, "yes"); - Writer out = new StringWriter(); - tf.transform(new DOMSource(xml_doc), new StreamResult(out)); - byte[] postDataBytes = out.toString().getBytes("UTF-8"); - - URL url = new URL(any_url); - urlConn = (HttpURLConnection) url.openConnection(); - urlConn.setRequestMethod("POST"); - urlConn.setRequestProperty("Content-Type", "application/xml"); - urlConn.setRequestProperty("Content-Length", String.valueOf(postDataBytes.length)); - urlConn.setDoOutput(true); - urlConn.getOutputStream().write(postDataBytes); - if (urlConn != null) - urlConn.setReadTimeout(60 * 1000); - if (urlConn != null && urlConn.getInputStream() != null) { - in = new InputStreamReader(urlConn.getInputStream(), Charset.defaultCharset()); - BufferedReader bufferedReader = new BufferedReader(in); - if (bufferedReader != null) { - int cp; - while ((cp = bufferedReader.read()) != -1) { - sb.append((char) cp); - } - bufferedReader.close(); - } - } - in.close(); - } catch (Exception e) { - throw new RuntimeException("Exception while calling URL:" + any_url, e); - } - return sb.toString(); - } - private HttpURLConnection GetConnection(String serviceURL) throws IOException { - URL urlObj = new URL(serviceURL); - return (HttpURLConnection) urlObj.openConnection(); - } } diff --git a/src/main/java/org/opengis/cite/wps20/level1/Capability1Tests.java b/src/main/java/org/opengis/cite/wps20/level1/Capability1Tests.java deleted file mode 100644 index 428a3b6..0000000 --- a/src/main/java/org/opengis/cite/wps20/level1/Capability1Tests.java +++ /dev/null @@ -1,95 +0,0 @@ -package org.opengis.cite.wps20.level1; - -import java.io.IOException; -import java.net.URL; -import javax.xml.transform.Source; -import javax.xml.transform.dom.DOMSource; -import org.opengis.cite.wps20.CommonFixture; -import org.opengis.cite.wps20.ErrorMessage; -import org.opengis.cite.wps20.ErrorMessageKeys; -import org.opengis.cite.wps20.SuiteAttribute; -import org.opengis.cite.validation.RelaxNGValidator; -import org.opengis.cite.validation.ValidationErrorHandler; -import org.testng.Assert; -import org.testng.ITestContext; -import org.testng.annotations.BeforeClass; -import org.testng.annotations.Test; -import org.w3c.dom.Document; -import org.xml.sax.SAXException; - -/** - * Includes various tests of capability 1. - */ -public class Capability1Tests extends CommonFixture { - - private Document testSubject; - - /** - * Obtains the test subject from the ISuite context. The suite attribute - * {@link org.opengis.cite.wps20.SuiteAttribute#TEST_SUBJECT} should - * evaluate to a DOM Document node. - * - * @param testContext - * The test (group) context. - */ - @BeforeClass - public void obtainTestSubject(ITestContext testContext) { - Object obj = testContext.getSuite().getAttribute( - SuiteAttribute.TEST_SUBJECT.getName()); - if ((null != obj) && Document.class.isAssignableFrom(obj.getClass())) { - this.testSubject = Document.class.cast(obj); - } - } - - /** - * Sets the test subject. This method is intended to facilitate unit - * testing. - * - * @param testSubject A Document node representing the test subject or - * metadata about it. - */ - public void setTestSubject(Document testSubject) { - this.testSubject = testSubject; - } - - /** - * Verifies the string is empty. - */ - @Test(description = "Implements ATC 1-1") - public void isEmpty() { - String str = " foo "; - Assert.assertTrue(str.isEmpty(), - ErrorMessage.get(ErrorMessageKeys.EMPTY_STRING)); - } - - /** - * Checks the behavior of the trim function. - */ - @Test(description = "Implements ATC 1-2") - public void trim() { - String str = " foo "; - Assert.assertTrue("foo".equals(str.trim())); - } - - /** - * Verify the test subject is a valid Atom feed. - * - * @throws SAXException - * If the resource cannot be parsed. - * @throws IOException - * If the resource is not accessible. - */ - @Test(description = "Implements ATC 1-3") - public void docIsValidAtomFeed() throws SAXException, IOException { - URL schemaRef = getClass().getResource( - "/org/opengis/cite/wps20/rnc/atom.rnc"); - RelaxNGValidator rngValidator = new RelaxNGValidator(schemaRef); - Source xmlSource = (null != testSubject) - ? new DOMSource(testSubject) : null; - rngValidator.validate(xmlSource); - ValidationErrorHandler err = rngValidator.getErrorHandler(); - Assert.assertFalse(err.errorsDetected(), - ErrorMessage.format(ErrorMessageKeys.NOT_SCHEMA_VALID, - err.getErrorCount(), err.toString())); - } -} diff --git a/src/main/java/org/opengis/cite/wps20/level1/package-info.java b/src/main/java/org/opengis/cite/wps20/level1/package-info.java deleted file mode 100644 index 24a5dd0..0000000 --- a/src/main/java/org/opengis/cite/wps20/level1/package-info.java +++ /dev/null @@ -1,14 +0,0 @@ -/** - * Conformance Level 1 includes basic facilities. The following capabilities - * must be supported: - *
    - *
  • Capability 1.1
  • - *
  • Capability 1.2
  • - *
  • Capability 1.3
  • - *
- * - * @see HTML5 - * - Conformance classes - */ -package org.opengis.cite.wps20.level1; diff --git a/src/main/java/org/opengis/cite/wps20/synchronous/SyncTests.java b/src/main/java/org/opengis/cite/wps20/synchronous/SyncTests.java new file mode 100644 index 0000000..4c465f7 --- /dev/null +++ b/src/main/java/org/opengis/cite/wps20/synchronous/SyncTests.java @@ -0,0 +1,226 @@ +package org.opengis.cite.wps20.synchronous; + +import static org.testng.Assert.assertTrue; + +import java.io.BufferedReader; +import java.io.DataOutputStream; +import java.io.File; +import java.io.IOException; +import java.io.InputStreamReader; +import java.io.StringReader; +import java.io.StringWriter; +import java.io.Writer; +import java.net.HttpURLConnection; +import java.net.URI; +//import java.net.URI; +import java.net.URISyntaxException; +import java.net.URL; +//import java.net.URLConnection; +import java.net.URLEncoder; +import java.nio.charset.Charset; +//import java.util.ArrayList; +//import java.util.HashMap; +import java.util.HashSet; +import java.util.LinkedHashMap; +//import java.util.List; +import java.util.Map; +import java.util.Set; +import java.util.Random; + +import javax.xml.parsers.DocumentBuilder; +import javax.xml.parsers.DocumentBuilderFactory; +import javax.xml.transform.OutputKeys; +//import javax.xml.transform.Source; +import javax.xml.transform.Transformer; +import javax.xml.transform.TransformerFactory; +import javax.xml.transform.dom.DOMSource; +import javax.xml.transform.stream.StreamResult; +import javax.xml.transform.stream.StreamSource; +import javax.xml.validation.Schema; +import javax.xml.validation.Validator; + +//import org.opengis.cite.wps20.Namespaces; +//import org.opengis.cite.wps20.SuiteAttribute; +import org.opengis.cite.wps20.CommonFixture; +import org.opengis.cite.wps20.basictests.BasicTests; +import org.testng.Assert; +import org.testng.annotations.Test; +import org.w3c.dom.Document; +import org.w3c.dom.Element; +import org.w3c.dom.Node; +//import org.w3c.dom.Node; +import org.w3c.dom.NodeList; +import org.xml.sax.InputSource; +import org.xml.sax.SAXException; + +/*import net.sf.saxon.s9api.Processor; +import net.sf.saxon.s9api.SaxonApiException; +import net.sf.saxon.s9api.XPathCompiler; +import net.sf.saxon.s9api.XPathSelector; +import net.sf.saxon.s9api.XdmNode; +import net.sf.saxon.s9api.XdmValue;*/ + +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 + * request to the server under test, setting the “mode” attribute to “sync”. + * Verify that a valid Execute wps:Result is returned. + * + * @throws Exception + */ + @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); + + // Response document + Element executeElement = (Element) literalDocument + .getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "Execute").item(0); + executeElement.setAttribute("mode", "sync"); + executeElement.setAttribute("response", "document"); + + /* + * try { prettyPrint(literalDocument); } catch (Exception e) { // TODO + * Auto-generated catch block e.printStackTrace(); } + */ + + + /* + * // Code by Aries //status code is 200 response validation HttpURLConnection + * conn = GetConnection(SERVICE_URL); conn.setRequestMethod("POST"); + * conn.setRequestProperty("Content-Type", "application/xml"); + * conn.setDoOutput(true); + * + * DataOutputStream outputStream = new DataOutputStream(conn.getOutputStream()); + * String xml = TransformXMLDocumentToXMLString(literalDocument); + * outputStream.writeBytes(xml); outputStream.flush(); outputStream.close(); + * + * int responseCode = conn.getResponseCode(); boolean respDocFlag = + * (responseCode == HttpURLConnection.HTTP_OK); + */ + + String respDocResult = GetContentFromPOSTXMLRequest(SERVICE_URL, literalDocument); + Document respDocResultDocument = TransformXMLStringToXMLDocument(respDocResult); + boolean respDocFlag = respDocResultDocument.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", "Result").getLength() > 0; + String msg = "Invalid SyncExecute via POST/XML for WPS 2.0"; + assertTrue(respDocFlag, msg); + + // Raw data output + executeElement.setAttribute("response", "raw"); + + /* + * try { prettyPrint(literalDocument); } catch (Exception e) { // TODO + * Auto-generated catch block e.printStackTrace(); } + */ + + String respRawResult = GetContentFromPOSTXMLRequest(SERVICE_URL, literalDocument); + boolean VSE_Flag = respRawResult.contains("hello_literal"); + + if (VSE_Flag) { + String msg1 = "Valid SyncExecute via POST/XML for WPS 2.0"; + Assert.assertTrue(VSE_Flag, msg1); + } else { + String msg1 = "Invalid SyncExecute via POST/XML for WPS 2.0"; + Assert.assertTrue(VSE_Flag, msg1); + } + + /* + * // The Process Flow should as this one String VSEXmlString = + * GetContentFromPOSTXMLRequest(SERVICE_URL, literalDocument); Document + * VSEDocument = TransformXMLStringToXMLDocument(VSEXmlString); Boolean VSE_Flag + * = (VSEDocument.getElementsByTagNameNS("http://www.opengis.net/wps/2.0", + * "Result").getLength() > 0) ? true : false; if (VSE_Flag) { String msg = + * "Valid SyncExecute via POST/XML for WPS 2.0"; Assert.assertTrue(VSE_Flag, + * msg); } else { String msg = "Invalid SyncExecute via POST/XML for WPS 2.0"; + * Assert.assertTrue(VSE_Flag, msg); } + */ + } + + 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/resources/org/opengis/cite/wps20/testng.xml b/src/main/resources/org/opengis/cite/wps20/testng.xml index 03f9915..94b4fa5 100644 --- a/src/main/resources/org/opengis/cite/wps20/testng.xml +++ b/src/main/resources/org/opengis/cite/wps20/testng.xml @@ -10,14 +10,19 @@ - + - - + + + + + + + + + + + - - - - diff --git a/src/test/java/org/opengis/cite/wps20/level1/VerifyCapability1Tests.java b/src/test/java/org/opengis/cite/wps20/level1/VerifyCapability1Tests.java deleted file mode 100644 index 7d4872a..0000000 --- a/src/test/java/org/opengis/cite/wps20/level1/VerifyCapability1Tests.java +++ /dev/null @@ -1,72 +0,0 @@ -package org.opengis.cite.wps20.level1; - -import java.io.IOException; -import javax.xml.parsers.DocumentBuilder; -import javax.xml.parsers.DocumentBuilderFactory; -import org.junit.AfterClass; -import org.junit.BeforeClass; -import org.junit.Test; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; -import org.testng.ISuite; -import org.testng.ITestContext; -import org.w3c.dom.Document; -import org.xml.sax.SAXException; - -/** - * Verifies the behavior of the Capability1Tests test class. Test stubs replace - * fixture constituents where appropriate. - */ -public class VerifyCapability1Tests { - - private static final String SUBJ = "testSubject"; - private static DocumentBuilder docBuilder; - private static ITestContext testContext; - private static ISuite suite; - - public VerifyCapability1Tests() { - } - - @BeforeClass - public static void setUpClass() throws Exception { - testContext = mock(ITestContext.class); - suite = mock(ISuite.class); - when(testContext.getSuite()).thenReturn(suite); - DocumentBuilderFactory dbf = DocumentBuilderFactory.newInstance(); - dbf.setNamespaceAware(true); - docBuilder = dbf.newDocumentBuilder(); - } - - @AfterClass - public static void tearDownClass() throws Exception { - } - - @Test(expected = AssertionError.class) - public void testIsEmpty() { - Capability1Tests iut = new Capability1Tests(); - iut.isEmpty(); - } - - @Test - public void testTrim() { - Capability1Tests iut = new Capability1Tests(); - iut.trim(); - } - - @Test(expected = NullPointerException.class) - public void supplyNullTestSubject() throws SAXException, IOException { - Capability1Tests iut = new Capability1Tests(); - iut.docIsValidAtomFeed(); - } - - @Test - public void supplyValidAtomFeedViaTestContext() throws SAXException, - IOException { - Document doc = docBuilder.parse(this.getClass().getResourceAsStream( - "/atom-feed.xml")); - when(suite.getAttribute(SUBJ)).thenReturn(doc); - Capability1Tests iut = new Capability1Tests(); - iut.obtainTestSubject(testContext); - iut.docIsValidAtomFeed(); - } -} From e88a1de8d610aa916fb908a563d088cef1ef3865 Mon Sep 17 00:00:00 2001 From: Gobe Hobona Date: Thu, 15 Dec 2022 12:24:03 +0000 Subject: [PATCH 2/2] Update wps20-suite.ctl --- src/main/scripts/ctl/wps20-suite.ctl | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/scripts/ctl/wps20-suite.ctl b/src/main/scripts/ctl/wps20-suite.ctl index 75d7091..fe09881 100644 --- a/src/main/scripts/ctl/wps20-suite.ctl +++ b/src/main/scripts/ctl/wps20-suite.ctl @@ -71,11 +71,11 @@

--> -

+

|