From 63369bc1eb9b2e6d702e73bbc3f50a32c836b333 Mon Sep 17 00:00:00 2001 From: Rodrigo Pastrana Date: Wed, 27 Mar 2024 11:38:45 -0400 Subject: [PATCH] XXX-HPCC4J Add WsResources test cases - Adds test cases to account for all wsresources methods - Adds logic to create HPCCQueueType based on string representation - Adds all available methods to HPCCWsResourcesClient Signed-off-by: Rodrigo Pastrana --- .../ws/client/HPCCWsResourcesClient.java | 109 ++++++++++++++++-- .../gen/wsresources/HPCCQueueTypeWrapper.java | 13 ++- .../ws/client/WSResroucesClientTest.java | 71 +++++++++++- 3 files changed, 175 insertions(+), 18 deletions(-) diff --git a/wsclient/src/main/java/org/hpccsystems/ws/client/HPCCWsResourcesClient.java b/wsclient/src/main/java/org/hpccsystems/ws/client/HPCCWsResourcesClient.java index d8f39c8fe..aa41ff519 100644 --- a/wsclient/src/main/java/org/hpccsystems/ws/client/HPCCWsResourcesClient.java +++ b/wsclient/src/main/java/org/hpccsystems/ws/client/HPCCWsResourcesClient.java @@ -27,12 +27,19 @@ HPCC SYSTEMS software Copyright (C) 2021 HPCC Systems®. import org.apache.logging.log4j.Logger; import org.hpccsystems.ws.client.gen.axis2.wsresources.latest.ArrayOfEspException; import org.hpccsystems.ws.client.gen.axis2.wsresources.latest.ServiceQueryResponse; +import org.hpccsystems.ws.client.gen.axis2.wsresources.latest.TargetQueryResponse; import org.hpccsystems.ws.client.gen.axis2.wsresources.latest.WsResourcesPingRequest; import org.hpccsystems.ws.client.gen.axis2.wsresources.latest.WsResourcesStub; +import org.hpccsystems.ws.client.gen.axis2.wsresources.latest.WebLinksQueryResponse; import org.hpccsystems.ws.client.utils.Connection; import org.hpccsystems.ws.client.wrappers.ArrayOfEspExceptionWrapper; import org.hpccsystems.ws.client.wrappers.gen.wsresources.ServiceQueryRequestWrapper; import org.hpccsystems.ws.client.wrappers.gen.wsresources.ServiceQueryResponseWrapper; +import org.hpccsystems.ws.client.wrappers.gen.wsresources.TargetQueryRequestWrapper; +import org.hpccsystems.ws.client.wrappers.gen.wsresources.TargetQueryResponseWrapper; +import org.hpccsystems.ws.client.wrappers.gen.wsresources.WebLinksQueryRequestWrapper; +import org.hpccsystems.ws.client.wrappers.gen.wsresources.WebLinksQueryResponseWrapper; + /** * Facilitates discovery of containerized HPCC Systems resources. @@ -48,7 +55,7 @@ public class HPCCWsResourcesClient extends BaseHPCCWsClient /** * Load WSDLURL. - */ + */ private static void loadWSDLURL() { try @@ -67,7 +74,7 @@ private static void loadWSDLURL() * Gets the service URI. * * @return the service URI - */ + */ public String getServiceURI() { return WSRESOURCESURI; @@ -116,10 +123,10 @@ public Stub getDefaultStub() throws AxisFault } /** - * Gets the. + * Gets the Ws Resources client * * @param connection - * the connection + * the connection * @return the HPCC HPCCWsResources client */ public static HPCCWsResourcesClient get(Connection connection) @@ -128,7 +135,7 @@ public static HPCCWsResourcesClient get(Connection connection) } /** - * Gets the. + * Gets the Ws Resources client * * @param protocol * the protocol @@ -150,7 +157,7 @@ public static HPCCWsResourcesClient get(String protocol, String targetHost, Stri } /** - * Gets the. + * Gets the Ws Resources client * * @param protocol * the protocol @@ -188,7 +195,8 @@ protected HPCCWsResourcesClient(Connection baseConnection) } /** - * Initializes the service's underlying stub Should only be used by constructors. + * Initializes the service's underlying stub Should only be used by + * constructors. * * @param conn * -- All connection settings included @@ -219,14 +227,19 @@ protected void initWsResourcesClientStub(Connection conn) /** * Submit service query request * - * @param req a {@link org.hpccsystems.ws.client.wrappers.gen.wsresources.ServiceQueryRequestWrapper} object. + * @param req a + * {@link org.hpccsystems.ws.client.wrappers.gen.wsresources.ServiceQueryRequestWrapper} + * object. * @throws Exception a {@link java.lang.Exception} object. - * @return a {@link org.hpccsystems.ws.client.wrappers.gen.wsresources.ServiceQueryResponseWrapper} object. + * @return a + * {@link org.hpccsystems.ws.client.wrappers.gen.wsresources.ServiceQueryResponseWrapper} + * object. */ public ServiceQueryResponseWrapper serviceQuery(ServiceQueryRequestWrapper req) throws Exception { if (req == null) - throw new Exception(""); + throw new Exception("ServiceQueryRequestWrapper must be provided!"); + verifyStub(); ServiceQueryResponse resp = null; @@ -249,6 +262,82 @@ public ServiceQueryResponseWrapper serviceQuery(ServiceQueryRequestWrapper req) return new ServiceQueryResponseWrapper(resp); } + /** + * Submit target query request + * + * @param req a + * {@link org.hpccsystems.ws.client.wrappers.gen.wsresources.TargetQueryRequestWrapper} + * object. + * @throws Exception a {@link java.lang.Exception} object. + * @return a + * {@link org.hpccsystems.ws.client.wrappers.gen.wsresources.TargetQueryResponseWrapper} + * object. + */ + public TargetQueryResponseWrapper targetQuery(TargetQueryRequestWrapper req) throws Exception + { + if (req == null) + throw new Exception("TargetQueryRequestWrapper must be provided!"); + + verifyStub(); + + TargetQueryResponse resp = null; + + try + { + resp = ((WsResourcesStub) stub).targetQuery(req.getRaw()); + } + catch (RemoteException e) + { + throw new Exception("HPCCWSRESOURCESClient.targetQuery(TargetQueryRequestWrapper) encountered RemoteException.", e); + } + + if (resp.getExceptions() != null) + { + ArrayOfEspException exceptions = resp.getExceptions(); + handleEspExceptions(new ArrayOfEspExceptionWrapper(exceptions), "Error processing service query"); + } + + return new TargetQueryResponseWrapper(resp); + } + + /** + * Submit WebLinks query request + * + * @param req a + * {@link org.hpccsystems.ws.client.wrappers.gen.wsresources.WebLinksRequestWrapper} + * object. + * @throws Exception a {@link java.lang.Exception} object. + * @return a + * {@link org.hpccsystems.ws.client.wrappers.gen.wsresources.WebLinksResponseWrapper} + * object. + */ + public WebLinksQueryResponseWrapper webLinks(WebLinksQueryRequestWrapper req) throws Exception + { + if (req == null) + throw new Exception("WebLinksQueryRequestWrapper must be provided!"); + + verifyStub(); + + WebLinksQueryResponse resp = null; + + try + { + resp = ((WsResourcesStub) stub).webLinksQuery(req.getRaw()); + } + catch (RemoteException e) + { + throw new Exception("HPCCWSRESOURCESClient.webLinksQuery(WebLinksQueryRequestWrapper) encountered RemoteException.", e); + } + + if (resp.getExceptions() != null) + { + ArrayOfEspException exceptions = resp.getExceptions(); + handleEspExceptions(new ArrayOfEspExceptionWrapper(exceptions), "Error processing service query"); + } + + return new WebLinksQueryResponseWrapper(resp); + } + /** * Ping. * diff --git a/wsclient/src/main/java/org/hpccsystems/ws/client/wrappers/gen/wsresources/HPCCQueueTypeWrapper.java b/wsclient/src/main/java/org/hpccsystems/ws/client/wrappers/gen/wsresources/HPCCQueueTypeWrapper.java index 216be011c..695b9312d 100644 --- a/wsclient/src/main/java/org/hpccsystems/ws/client/wrappers/gen/wsresources/HPCCQueueTypeWrapper.java +++ b/wsclient/src/main/java/org/hpccsystems/ws/client/wrappers/gen/wsresources/HPCCQueueTypeWrapper.java @@ -1,5 +1,7 @@ package org.hpccsystems.ws.client.wrappers.gen.wsresources; +import org.hpccsystems.ws.client.gen.axis2.wsresources.latest.HPCCQueueType; + /******************************************************************************* * HPCC SYSTEMS software Copyright (C) 2021 HPCC Systems. * @@ -54,9 +56,16 @@ public String toString() } public org.hpccsystems.ws.client.gen.axis2.wsresources.latest.HPCCQueueType getRaw() { - org.hpccsystems.ws.client.gen.axis2.wsresources.latest.HPCCQueueType raw = null; + if (local_hPCCQueueType.equalsIgnoreCase("ALL")) + return org.hpccsystems.ws.client.gen.axis2.wsresources.latest.HPCCQueueType.All; + else if (local_hPCCQueueType.equalsIgnoreCase("Thor")) + return org.hpccsystems.ws.client.gen.axis2.wsresources.latest.HPCCQueueType.Thor; + else if (local_hPCCQueueType.equalsIgnoreCase("HThor")) + return org.hpccsystems.ws.client.gen.axis2.wsresources.latest.HPCCQueueType.HThor; + else if (local_hPCCQueueType.equalsIgnoreCase("Roxie")) + return org.hpccsystems.ws.client.gen.axis2.wsresources.latest.HPCCQueueType.Roxie; //WARNING base class does not provide expected default constructor//Warning raw class doe not provide expected method: setHPCCQueueType(hPCCQueueType); - return raw; + return null; } diff --git a/wsclient/src/test/java/org/hpccsystems/ws/client/WSResroucesClientTest.java b/wsclient/src/test/java/org/hpccsystems/ws/client/WSResroucesClientTest.java index 865d41dc0..350d735c5 100644 --- a/wsclient/src/test/java/org/hpccsystems/ws/client/WSResroucesClientTest.java +++ b/wsclient/src/test/java/org/hpccsystems/ws/client/WSResroucesClientTest.java @@ -22,10 +22,16 @@ HPCC SYSTEMS software Copyright (C) 2021 HPCC Systems®. import java.util.List; import org.apache.axis2.AxisFault; +import org.hpccsystems.ws.client.gen.axis2.wsresources.latest.HPCCQueueType; import org.hpccsystems.ws.client.wrappers.ArrayOfEspExceptionWrapper; +import org.hpccsystems.ws.client.wrappers.gen.wsresources.HPCCQueueTypeWrapper; import org.hpccsystems.ws.client.wrappers.gen.wsresources.HPCCServiceWrapper; import org.hpccsystems.ws.client.wrappers.gen.wsresources.ServiceQueryRequestWrapper; import org.hpccsystems.ws.client.wrappers.gen.wsresources.ServiceQueryResponseWrapper; +import org.hpccsystems.ws.client.wrappers.gen.wsresources.TargetQueryRequestWrapper; +import org.hpccsystems.ws.client.wrappers.gen.wsresources.TargetQueryResponseWrapper; +import org.hpccsystems.ws.client.wrappers.gen.wsresources.WebLinksQueryRequestWrapper; +import org.hpccsystems.ws.client.wrappers.gen.wsresources.WebLinksQueryResponseWrapper; import org.junit.Assert; import org.junit.Assume; import org.junit.Before; @@ -36,13 +42,13 @@ HPCC SYSTEMS software Copyright (C) 2021 HPCC Systems®. @FixMethodOrder(MethodSorters.NAME_ASCENDING) public class WSResroucesClientTest extends BaseRemoteTest { - private static HPCCWsResourcesClient client; + private static HPCCWsResourcesClient wsResourcesClient; private boolean iscontainerized = false; static { - client = HPCCWsResourcesClient.get(connection); - Assert.assertNotNull(client); + wsResourcesClient = HPCCWsResourcesClient.get(connection); + Assert.assertNotNull(wsResourcesClient); } @Before @@ -65,7 +71,7 @@ public void serviceQueryTest() try { System.out.println("Querying all HPCC Services..."); - ServiceQueryResponseWrapper resp = client.serviceQuery(new ServiceQueryRequestWrapper()); + ServiceQueryResponseWrapper resp = wsResourcesClient.serviceQuery(new ServiceQueryRequestWrapper()); Assert.assertNotNull(resp); Assert.assertNotNull(resp.getServices()); List services = resp.getServices().getService(); @@ -88,7 +94,60 @@ public void serviceQueryTest() public void getContainerizedModeTest() throws Exception { System.out.println("Fetching isTargetHPCCContainerized..."); - assertNotNull(client.isTargetHPCCContainerized()); + assertNotNull(wsResourcesClient.isTargetHPCCContainerized()); + } + + @Test + public void testTargetQueryNullType() throws Exception + { + // Create a target query request + TargetQueryRequestWrapper request = new TargetQueryRequestWrapper(); + // Set the request parameters + request.setType(null); + + // Call the targetQuery method + TargetQueryResponseWrapper response = wsResourcesClient.targetQuery(request); + + Assert.assertNotNull(response); + } + + @Test + public void testTargetQueryAllType() throws Exception + { + // Create a target query request + TargetQueryRequestWrapper request = new TargetQueryRequestWrapper(); + request.setType(new HPCCQueueTypeWrapper(HPCCQueueType._All)); + + // Call the targetQuery method + TargetQueryResponseWrapper response = wsResourcesClient.targetQuery(request); + + Assert.assertNotNull(response); + } + + @Test + public void testTargetQueryRoxieType() throws Exception + { + // Create a target query request + TargetQueryRequestWrapper request = new TargetQueryRequestWrapper(); + request.setType(new HPCCQueueTypeWrapper(HPCCQueueType._Roxie)); + + // Call the targetQuery method + TargetQueryResponseWrapper response = wsResourcesClient.targetQuery(request); + + Assert.assertNotNull(response); + } + + @Test + public void testWebLinksQuery() throws Exception + { + // Create a web links query request + WebLinksQueryRequestWrapper request = new WebLinksQueryRequestWrapper(); + // Call the webLinksQuery method + WebLinksQueryResponseWrapper response = wsResourcesClient.webLinks(request); + + // Assert the response + Assert.assertNotNull(response); + // Add more assertions as needed } @Test @@ -97,7 +156,7 @@ public void ping() throws Exception Assume.assumeTrue("Target HPCC does not seem to be containerized", iscontainerized); try { - Assert.assertTrue(client.ping()); + Assert.assertTrue(wsResourcesClient.ping()); } catch (AxisFault e) {