|
| 1 | +/*############################################################################## |
| 2 | +
|
| 3 | + HPCC SYSTEMS software Copyright (C) 2024 HPCC Systems®. |
| 4 | +
|
| 5 | + Licensed under the Apache License, Version 2.0 (the "License"); |
| 6 | + you may not use this file except in compliance with the License. |
| 7 | + You may obtain a copy of the License at |
| 8 | +
|
| 9 | + http://www.apache.org/licenses/LICENSE-2.0 |
| 10 | +
|
| 11 | + Unless required by applicable law or agreed to in writing, software |
| 12 | + distributed under the License is distributed on an "AS IS" BASIS, |
| 13 | + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 14 | + See the License for the specific language governing permissions and |
| 15 | + limitations under the License. |
| 16 | +############################################################################## */ |
| 17 | + |
| 18 | +package org.hpccsystems.ws.client; |
| 19 | + |
| 20 | +import static org.junit.Assume.assumeTrue; |
| 21 | + |
| 22 | +import java.io.ByteArrayOutputStream; |
| 23 | +import java.io.InputStream; |
| 24 | +import java.util.List; |
| 25 | + |
| 26 | +import org.hpccsystems.ws.client.utils.Connection; |
| 27 | +import org.hpccsystems.ws.client.wrappers.gen.wsworkunits.WUPublishWorkunitResponseWrapper; |
| 28 | +import org.hpccsystems.ws.client.wrappers.wsworkunits.QueryResultWrapper; |
| 29 | +import org.hpccsystems.ws.client.wrappers.wsworkunits.WorkunitWrapper; |
| 30 | +import org.junit.Assert; |
| 31 | +import org.junit.BeforeClass; |
| 32 | +import org.junit.FixMethodOrder; |
| 33 | +import org.junit.Test; |
| 34 | +import org.junit.runners.MethodSorters; |
| 35 | + |
| 36 | +public class WSECLTests extends BaseRemoteTest |
| 37 | +{ |
| 38 | + private static HPCCWsWorkUnitsClient wswuclient = null; |
| 39 | + private static boolean hasPublishedQuery = false; |
| 40 | + private final static String wsECLPort = System.getProperty("wseclport", "8002"); |
| 41 | + private final static String eclScriptName = "SimpleFunction.ecl"; |
| 42 | + private static Connection wseclConn = null; |
| 43 | + |
| 44 | + @BeforeClass |
| 45 | + public static void setup() throws Exception |
| 46 | + { |
| 47 | + wswuclient = wsclient.getWsWorkunitsClient(); //for publishing queries |
| 48 | + Assert.assertNotNull(wswuclient); |
| 49 | + |
| 50 | + try |
| 51 | + { |
| 52 | + InputStream resourceStream = BaseRemoteTest.class.getClassLoader().getResourceAsStream(eclScriptName); |
| 53 | + ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream(); |
| 54 | + |
| 55 | + byte[] buffer = new byte[4096]; |
| 56 | + int bytesRead = resourceStream.read(buffer); |
| 57 | + while (bytesRead > -1) { |
| 58 | + byteArrayOutputStream.write(buffer, 0, bytesRead); |
| 59 | + bytesRead = resourceStream.read(buffer); |
| 60 | + } |
| 61 | + |
| 62 | + byte[] eclData = byteArrayOutputStream.toByteArray(); |
| 63 | + String ecl = new String(eclData, "UTF-8"); |
| 64 | + |
| 65 | + WorkunitWrapper wu = new WorkunitWrapper(); |
| 66 | + wu.setECL(ecl); |
| 67 | + wu.setJobname(eclScriptName); |
| 68 | + wu.setCluster(thorclustername); |
| 69 | + |
| 70 | + //wswuclient.createAndRunWUFromECLAndGetResults(wu); |
| 71 | + WUPublishWorkunitResponseWrapper resp = wswuclient.publishWUFromEclWrapped(wu); |
| 72 | + System.out.println("Finished publishing query" + resp.toString()); |
| 73 | + List<QueryResultWrapper> queries = wswuclient.listQueries(wu.getWuid(), wu.getJobname(), wu.getCluster(), null, null, null, null, null, null); |
| 74 | + for (QueryResultWrapper query : queries) |
| 75 | + { |
| 76 | + if (query.getName().equalsIgnoreCase(eclScriptName)) |
| 77 | + { |
| 78 | + hasPublishedQuery = true; |
| 79 | + return; |
| 80 | + } |
| 81 | + } |
| 82 | + } |
| 83 | + catch (Exception e) |
| 84 | + { |
| 85 | + System.out.println("Could not publish ECL query: " + e.getLocalizedMessage()); |
| 86 | + } |
| 87 | + |
| 88 | + wseclConn = wsclient.getConnection(); |
| 89 | + wseclConn.setPort(wsECLPort); |
| 90 | + wseclConn.setSocketTimeoutMilli(15000); |
| 91 | + wseclConn.setWriteTimeoutMilli(15000); |
| 92 | + } |
| 93 | + |
| 94 | + @Test |
| 95 | + public void testWsECLGetWSDL() |
| 96 | + { |
| 97 | + assumeTrue("WsECL connection not available", wseclConn != null); |
| 98 | + assumeTrue("WsECL connection port appears invalid", wseclConn.getPort().equals(wsECLPort)); |
| 99 | + assumeTrue("Cannot test WsECL published query WSDL feature without published queries!", hasPublishedQuery); |
| 100 | + |
| 101 | + try |
| 102 | + { |
| 103 | + String wsdlURI = "/WsEcl/definitions/query/" + thorclustername + "/" + eclScriptName + "/main/" + eclScriptName + ".wsdl"; |
| 104 | + |
| 105 | + String wsdlResponse = wseclConn.sendGetRequest(wsdlURI); |
| 106 | + Assert.assertNotNull("Unexpected Null response", wsdlResponse); |
| 107 | + //TODO determine good way to confirm success/failure |
| 108 | + //Assert.assertArrayEquals(expectedWsdlResponse, wsdlResponse) |
| 109 | + } |
| 110 | + catch (Exception e) |
| 111 | + { |
| 112 | + Assert.fail("Could not fetch WsECL query wsdl: " + e.getLocalizedMessage()); |
| 113 | + } |
| 114 | + } |
| 115 | + |
| 116 | + @Test |
| 117 | + public void testWsECLGetSampleReq() |
| 118 | + { |
| 119 | + assumeTrue("WsECL connection not available", wseclConn != null); |
| 120 | + assumeTrue("WsECL connection port appears invalid", wseclConn.getPort().equals(wsECLPort)); |
| 121 | + assumeTrue("Cannot test WsECL published query WSDL feature without published queries!", hasPublishedQuery); |
| 122 | + |
| 123 | + try |
| 124 | + { |
| 125 | + //http://127.0.0.1:8002/WsEcl/example/request/query/<roxie>/<query> |
| 126 | + String sampleReqURI = "/WsEcl/example/request/query" + thorclustername + "/" + eclScriptName; |
| 127 | + String sampleReqResponse = wseclConn.sendGetRequest(sampleReqURI); |
| 128 | + Assert.assertNotNull("Unexpected Null response", sampleReqResponse); |
| 129 | + //TODO determine good way to confirm success/failure |
| 130 | + //Assert.assertArrayEquals(expectedWsdlResponse, wsdlResponse) |
| 131 | + } |
| 132 | + catch (Exception e) |
| 133 | + { |
| 134 | + Assert.fail("Could not fetch WsECL query wsdl: " + e.getLocalizedMessage()); |
| 135 | + } |
| 136 | + } |
| 137 | + |
| 138 | + @Test |
| 139 | + public void testWsECLGetSampleResp() |
| 140 | + { |
| 141 | + assumeTrue("WsECL connection not available", wseclConn != null); |
| 142 | + assumeTrue("WsECL connection port appears invalid", wseclConn.getPort().equals(wsECLPort)); |
| 143 | + assumeTrue("Cannot test WsECL published query WSDL feature without published queries!", hasPublishedQuery); |
| 144 | + |
| 145 | + try |
| 146 | + { |
| 147 | + //http://127.0.0.1:8002/WsEcl/example/response/query/<roxie>/<query> |
| 148 | + String sampleRespURI = "/WsEcl/example/response/query" + thorclustername + "/" + eclScriptName; |
| 149 | + String sampleRespResponse = wseclConn.sendGetRequest(sampleRespURI); |
| 150 | + Assert.assertNotNull("Unexpected Null response", sampleRespResponse); |
| 151 | + //TODO determine good way to confirm success/failure |
| 152 | + //Assert.assertArrayEquals(expectedWsdlResponse, wsdlResponse) |
| 153 | + } |
| 154 | + catch (Exception e) |
| 155 | + { |
| 156 | + Assert.fail("Could not fetch WsECL query wsdl: " + e.getLocalizedMessage()); |
| 157 | + } |
| 158 | + } |
| 159 | + |
| 160 | + @Test |
| 161 | + public void testWsECLGetSchema() |
| 162 | + { |
| 163 | + assumeTrue("WsECL connection not available", wseclConn != null); |
| 164 | + assumeTrue("WsECL connection port appears invalid", wseclConn.getPort().equals(wsECLPort)); |
| 165 | + assumeTrue("Cannot test WsECL published query WSDL feature without published queries!", hasPublishedQuery); |
| 166 | + |
| 167 | + try |
| 168 | + { |
| 169 | + String xsdURI = "/WsEcl/definitions/query/" + thorclustername + "/" + eclScriptName + "/main/" + eclScriptName + ".xsd"; |
| 170 | + String xsdResponse = wseclConn.sendGetRequest(xsdURI); |
| 171 | + Assert.assertNotNull("Unexpected Null response", xsdResponse); |
| 172 | + //TODO determine good way to confirm success/failure |
| 173 | + //Assert.assertArrayEquals(expectedWsdlResponse, wsdlResponse) |
| 174 | + } |
| 175 | + catch (Exception e) |
| 176 | + { |
| 177 | + Assert.fail("Could not fetch WsECL query xsd: " + e.getLocalizedMessage()); |
| 178 | + } |
| 179 | + } |
| 180 | + |
| 181 | +} |
0 commit comments