Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HPCC4J-590 Add WsResources test cases #699

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -48,7 +55,7 @@ public class HPCCWsResourcesClient extends BaseHPCCWsClient

/**
* Load WSDLURL.
*/
*/
private static void loadWSDLURL()
{
try
Expand All @@ -67,7 +74,7 @@ private static void loadWSDLURL()
* Gets the service URI.
*
* @return the service URI
*/
*/
public String getServiceURI()
{
return WSRESOURCESURI;
Expand Down Expand Up @@ -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)
Expand All @@ -128,7 +135,7 @@ public static HPCCWsResourcesClient get(Connection connection)
}

/**
* Gets the.
* Gets the Ws Resources client
*
* @param protocol
* the protocol
Expand All @@ -150,7 +157,7 @@ public static HPCCWsResourcesClient get(String protocol, String targetHost, Stri
}

/**
* Gets the.
* Gets the Ws Resources client
*
* @param protocol
* the protocol
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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;
Expand All @@ -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.WebLinksQueryRequestWrapper}
* object.
* @throws Exception a {@link java.lang.Exception} object.
* @return a
* {@link org.hpccsystems.ws.client.wrappers.gen.wsresources.WebLinksQueryResponseWrapper}
* 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.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
*
Expand Down Expand Up @@ -54,9 +56,16 @@ public String toString()
}
public org.hpccsystems.ws.client.gen.axis2.wsresources.latest.HPCCQueueType getRaw()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@rpastrana As we discussed offline this will likely be headache down the line, but there doesn't seem like much we could do here at the moment. In the future it might be worthwhile having the wrappers be auto-generated and subclass them to override behavior. That would require some changes to other parts of the code that construct the wrappers, but would could probably have a "factory" method on the wrapper that can be overridden as well so the calling code doesn't have to know that the correct subclass to construct.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I may not understand what the 'raw' means. Why not change the name to getHPCCQueueType()?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@wangkx this is actually an accepted convention for our generated wrapper code, the wrapper exposes the underlying raw types via the getraw methods

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OK

{
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;
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,17 @@ 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.EspExceptionWrapper;
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;
Expand All @@ -36,13 +43,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
Expand All @@ -65,7 +72,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<HPCCServiceWrapper> services = resp.getServices().getService();
Expand All @@ -88,7 +95,72 @@ 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);

try
{
TargetQueryResponseWrapper response = wsResourcesClient.targetQuery(request);
Assert.assertNotNull(response);
}
catch (ArrayOfEspExceptionWrapper e)
{
List<EspExceptionWrapper> espexceptions = e.getEspExceptions();
Assert.assertNotNull(espexceptions);
Assert.assertNotNull(espexceptions.get(0));
Assert.assertTrue(e.getEspExceptions().get(0).getMessage().contains("HPCCQueueType not defined."));
wangkx marked this conversation as resolved.
Show resolved Hide resolved
}
catch (Exception e)
{
Assert.fail("Unexpected Exception type");
}
}

@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
Expand All @@ -97,7 +169,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)
{
Expand Down
Loading