From 4768ca4f620753d592de4a3efb07e8f021674679 Mon Sep 17 00:00:00 2001 From: Rodrigo Pastrana Date: Fri, 28 Jun 2024 12:34:44 -0400 Subject: [PATCH] HPCC4J-618 WIP Add WsECL testsuite - Adds WsECL test suite - Adds published query setup logic - Adds simple ECL query file - Adds wsdl, xsd, req, resp request logic - Changes Utils.connection to allow post init changs of conn Signed-off-by: Rodrigo Pastrana --- .../ws/client/utils/Connection.java | 21 +- .../org/hpccsystems/ws/client/WSECLTests.java | 181 ++++++++++++++++++ .../test/resources/RoxieEchoPersonInfo.ecl | 3 + .../src/test/resources/SimpleFunction.ecl | 19 ++ 4 files changed, 221 insertions(+), 3 deletions(-) create mode 100644 wsclient/src/test/java/org/hpccsystems/ws/client/WSECLTests.java create mode 100644 wsclient/src/test/resources/RoxieEchoPersonInfo.ecl create mode 100644 wsclient/src/test/resources/SimpleFunction.ecl diff --git a/wsclient/src/main/java/org/hpccsystems/ws/client/utils/Connection.java b/wsclient/src/main/java/org/hpccsystems/ws/client/utils/Connection.java index c5acac2e7..97a6a75a0 100644 --- a/wsclient/src/main/java/org/hpccsystems/ws/client/utils/Connection.java +++ b/wsclient/src/main/java/org/hpccsystems/ws/client/utils/Connection.java @@ -486,12 +486,27 @@ private void setProtocol(String protocol_) * @param port_ * the new port */ - private void setPort(String port_) + public void setPort(String port_) { - if (port_ != null && port_.length() > 0) + boolean hasChanged = false; + + if (port_ != null && !port_.isEmpty()) + { + if (port != null && !port.equals(port_)) + hasChanged = true; + port = port_; + } else + { + if (port != null && !port.isEmpty()) + hasChanged = true; + port = ""; + } + + if(baseUrl != null && !baseUrl.isEmpty() && hasChanged) + constructUrl(); } /** @@ -516,7 +531,7 @@ private void setURIPath(String path) /** * Construct url. */ - private void constructUrl() + public void constructUrl() { baseUrl = new StringBuffer(); baseUrl.append(protocol).append(protDelimiter); diff --git a/wsclient/src/test/java/org/hpccsystems/ws/client/WSECLTests.java b/wsclient/src/test/java/org/hpccsystems/ws/client/WSECLTests.java new file mode 100644 index 000000000..ded212ab8 --- /dev/null +++ b/wsclient/src/test/java/org/hpccsystems/ws/client/WSECLTests.java @@ -0,0 +1,181 @@ +/*############################################################################## + + HPCC SYSTEMS software Copyright (C) 2024 HPCC Systems®. + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. +############################################################################## */ + +package org.hpccsystems.ws.client; + +import static org.junit.Assume.assumeTrue; + +import java.io.ByteArrayOutputStream; +import java.io.InputStream; +import java.util.List; + +import org.hpccsystems.ws.client.utils.Connection; +import org.hpccsystems.ws.client.wrappers.gen.wsworkunits.WUPublishWorkunitResponseWrapper; +import org.hpccsystems.ws.client.wrappers.wsworkunits.QueryResultWrapper; +import org.hpccsystems.ws.client.wrappers.wsworkunits.WorkunitWrapper; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.FixMethodOrder; +import org.junit.Test; +import org.junit.runners.MethodSorters; + +public class WSECLTests extends BaseRemoteTest +{ + private static HPCCWsWorkUnitsClient wswuclient = null; + private static boolean hasPublishedQuery = false; + private final static String wsECLPort = System.getProperty("wseclport", "8002"); + private final static String eclScriptName = "SimpleFunction.ecl"; + private static Connection wseclConn = null; + + @BeforeClass + public static void setup() throws Exception + { + wswuclient = wsclient.getWsWorkunitsClient(); //for publishing queries + Assert.assertNotNull(wswuclient); + + try + { + InputStream resourceStream = BaseRemoteTest.class.getClassLoader().getResourceAsStream(eclScriptName); + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); + + byte[] buffer = new byte[4096]; + int bytesRead = resourceStream.read(buffer); + while (bytesRead > -1) { + byteArrayOutputStream.write(buffer, 0, bytesRead); + bytesRead = resourceStream.read(buffer); + } + + byte[] eclData = byteArrayOutputStream.toByteArray(); + String ecl = new String(eclData, "UTF-8"); + + WorkunitWrapper wu = new WorkunitWrapper(); + wu.setECL(ecl); + wu.setJobname(eclScriptName); + wu.setCluster(thorclustername); + + //wswuclient.createAndRunWUFromECLAndGetResults(wu); + WUPublishWorkunitResponseWrapper resp = wswuclient.publishWUFromEclWrapped(wu); + System.out.println("Finished publishing query" + resp.toString()); + List queries = wswuclient.listQueries(wu.getWuid(), wu.getJobname(), wu.getCluster(), null, null, null, null, null, null); + for (QueryResultWrapper query : queries) + { + if (query.getName().equalsIgnoreCase(eclScriptName)) + { + hasPublishedQuery = true; + return; + } + } + } + catch (Exception e) + { + System.out.println("Could not publish ECL query: " + e.getLocalizedMessage()); + } + + wseclConn = wsclient.getConnection(); + wseclConn.setPort(wsECLPort); + wseclConn.setSocketTimeoutMilli(15000); + wseclConn.setWriteTimeoutMilli(15000); + } + + @Test + public void testWsECLGetWSDL() + { + assumeTrue("WsECL connection not available", wseclConn != null); + assumeTrue("WsECL connection port appears invalid", wseclConn.getPort().equals(wsECLPort)); + assumeTrue("Cannot test WsECL published query WSDL feature without published queries!", hasPublishedQuery); + + try + { + String wsdlURI = "/WsEcl/definitions/query/" + thorclustername + "/" + eclScriptName + "/main/" + eclScriptName + ".wsdl"; + + String wsdlResponse = wseclConn.sendGetRequest(wsdlURI); + Assert.assertNotNull("Unexpected Null response", wsdlResponse); + //TODO determine good way to confirm success/failure + //Assert.assertArrayEquals(expectedWsdlResponse, wsdlResponse) + } + catch (Exception e) + { + Assert.fail("Could not fetch WsECL query wsdl: " + e.getLocalizedMessage()); + } + } + + @Test + public void testWsECLGetSampleReq() + { + assumeTrue("WsECL connection not available", wseclConn != null); + assumeTrue("WsECL connection port appears invalid", wseclConn.getPort().equals(wsECLPort)); + assumeTrue("Cannot test WsECL published query WSDL feature without published queries!", hasPublishedQuery); + + try + { + //http://127.0.0.1:8002/WsEcl/example/request/query// + String sampleReqURI = "/WsEcl/example/request/query" + thorclustername + "/" + eclScriptName; + String sampleReqResponse = wseclConn.sendGetRequest(sampleReqURI); + Assert.assertNotNull("Unexpected Null response", sampleReqResponse); + //TODO determine good way to confirm success/failure + //Assert.assertArrayEquals(expectedWsdlResponse, wsdlResponse) + } + catch (Exception e) + { + Assert.fail("Could not fetch WsECL query wsdl: " + e.getLocalizedMessage()); + } + } + + @Test + public void testWsECLGetSampleResp() + { + assumeTrue("WsECL connection not available", wseclConn != null); + assumeTrue("WsECL connection port appears invalid", wseclConn.getPort().equals(wsECLPort)); + assumeTrue("Cannot test WsECL published query WSDL feature without published queries!", hasPublishedQuery); + + try + { + //http://127.0.0.1:8002/WsEcl/example/response/query// + String sampleRespURI = "/WsEcl/example/response/query" + thorclustername + "/" + eclScriptName; + String sampleRespResponse = wseclConn.sendGetRequest(sampleRespURI); + Assert.assertNotNull("Unexpected Null response", sampleRespResponse); + //TODO determine good way to confirm success/failure + //Assert.assertArrayEquals(expectedWsdlResponse, wsdlResponse) + } + catch (Exception e) + { + Assert.fail("Could not fetch WsECL query wsdl: " + e.getLocalizedMessage()); + } + } + + @Test + public void testWsECLGetSchema() + { + assumeTrue("WsECL connection not available", wseclConn != null); + assumeTrue("WsECL connection port appears invalid", wseclConn.getPort().equals(wsECLPort)); + assumeTrue("Cannot test WsECL published query WSDL feature without published queries!", hasPublishedQuery); + + try + { + String xsdURI = "/WsEcl/definitions/query/" + thorclustername + "/" + eclScriptName + "/main/" + eclScriptName + ".xsd"; + String xsdResponse = wseclConn.sendGetRequest(xsdURI); + Assert.assertNotNull("Unexpected Null response", xsdResponse); + //TODO determine good way to confirm success/failure + //Assert.assertArrayEquals(expectedWsdlResponse, wsdlResponse) + } + catch (Exception e) + { + Assert.fail("Could not fetch WsECL query xsd: " + e.getLocalizedMessage()); + } + } + +} diff --git a/wsclient/src/test/resources/RoxieEchoPersonInfo.ecl b/wsclient/src/test/resources/RoxieEchoPersonInfo.ecl new file mode 100644 index 000000000..ae149b093 --- /dev/null +++ b/wsclient/src/test/resources/RoxieEchoPersonInfo.ecl @@ -0,0 +1,3 @@ +import $.esdl_example; +request := dataset([], esdl_example.t_RoxieEchoPersonInfoRequest) : stored('RoxieEchoPersonInfoRequest', few); +output(request, named('RoxieEchoPersonInfoResponse')); \ No newline at end of file diff --git a/wsclient/src/test/resources/SimpleFunction.ecl b/wsclient/src/test/resources/SimpleFunction.ecl new file mode 100644 index 000000000..e1e3238f5 --- /dev/null +++ b/wsclient/src/test/resources/SimpleFunction.ecl @@ -0,0 +1,19 @@ +MyFunc(STRING DataIn, STRING1 SearchChar) := FUNCTION + +StrLen := LENGTH(TRIM(dataIn)); + ds := DATASET([{DataIn}], {STRING chars}); + + OutRec := RECORD + UNSIGNED1 flag; + END; + + OutRec Xform(ds L, INTEGER C) := TRANSFORM + SELF.flag := IF(L.chars[C] = SearchChar, 1, 0); + END; + + n := NORMALIZE(ds, StrLen, Xform(LEFT, COUNTER)); + + RETURN COUNT(n(flag=1)); +END; + +OUTPUT(MyFunc('abc~xyz~def~fred', '~'));