Skip to content

Commit

Permalink
Fix issue 31, check multiple LiteralDataInput and get the input id wh…
Browse files Browse the repository at this point in the history
…ich supports string, organize common code to CommonFixture
  • Loading branch information
arieslai committed May 31, 2023
1 parent c59d3b3 commit 9d04e4d
Show file tree
Hide file tree
Showing 4 changed files with 131 additions and 357 deletions.
137 changes: 118 additions & 19 deletions src/main/java/org/opengis/cite/wps20/CommonFixture.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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);
Expand All @@ -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
Expand All @@ -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<String, Object> 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
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
}
99 changes: 5 additions & 94 deletions src/main/java/org/opengis/cite/wps20/asynchronous/AsyncTests.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand Down Expand Up @@ -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");
Expand All @@ -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;

Expand Down Expand Up @@ -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<String, Object> 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);
}

}
Loading

0 comments on commit 9d04e4d

Please sign in to comment.