From ba4363a9e648ee6f789c68c380f222b728d244ec Mon Sep 17 00:00:00 2001 From: Hoan Nguyen <83745591+nqhoan-axonivy@users.noreply.github.com> Date: Thu, 1 Aug 2024 10:51:58 +0700 Subject: [PATCH] Fix Test (#36) Upgrade to latest test version Introduce new tests --- ui-path-connector-test/pom.xml | 2 +- .../connector/uipath/test/UiPathMock.java | 16 +++++++- .../connector/uipath/test/json/folders.json | 22 +++++++++++ .../connector/uipath/test/json/machines.json | 38 ++++++++++++++++++ .../{TestUiPathRPA.java => UiPathTest.java} | 39 ++++++++++++++----- 5 files changed, 105 insertions(+), 12 deletions(-) create mode 100644 ui-path-connector-test/src/com/axonivy/connector/uipath/test/json/folders.json create mode 100644 ui-path-connector-test/src/com/axonivy/connector/uipath/test/json/machines.json rename ui-path-connector-test/src_test/com/axonivy/connector/uipath/test/{TestUiPathRPA.java => UiPathTest.java} (51%) diff --git a/ui-path-connector-test/pom.xml b/ui-path-connector-test/pom.xml index 86e2ede..b7a0ee4 100644 --- a/ui-path-connector-test/pom.xml +++ b/ui-path-connector-test/pom.xml @@ -15,7 +15,7 @@ com.axonivy.ivy.test unit-tester - 10.0.0 + 10.0.16 test diff --git a/ui-path-connector-test/src/com/axonivy/connector/uipath/test/UiPathMock.java b/ui-path-connector-test/src/com/axonivy/connector/uipath/test/UiPathMock.java index e6dc82b..4594515 100644 --- a/ui-path-connector-test/src/com/axonivy/connector/uipath/test/UiPathMock.java +++ b/ui-path-connector-test/src/com/axonivy/connector/uipath/test/UiPathMock.java @@ -31,7 +31,7 @@ @Hidden public class UiPathMock { - static final String PATH_SUFFIX = "rpaMock"; + static final String PATH_SUFFIX = "rpaMock/orchestrator_/"; // URI where this mock can be reached: to be referenced in tests that use it! public static final String URI = "{ivy.app.baseurl}/api/" + PATH_SUFFIX; @@ -54,6 +54,20 @@ public String getJobs() { return json; } + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("odata/Folders") + public String getFolders() { + return load("json/folders.json"); + } + + @GET + @Produces(MediaType.APPLICATION_JSON) + @Path("odata/Machines") + public String getMachines() { + return load("json/machines.json"); + } + @GET @Produces(MediaType.APPLICATION_JSON) @Path("odata/Robots") diff --git a/ui-path-connector-test/src/com/axonivy/connector/uipath/test/json/folders.json b/ui-path-connector-test/src/com/axonivy/connector/uipath/test/json/folders.json new file mode 100644 index 0000000..c67f003 --- /dev/null +++ b/ui-path-connector-test/src/com/axonivy/connector/uipath/test/json/folders.json @@ -0,0 +1,22 @@ +{ + "@odata.context": "https://platform.uipath.com/odata/$metadata#Folders", + "@odata.count": 1, + "value": [ + { + "Key": "1a374a79-9bdd-4055-a0cc-95488ae006a0", + "DisplayName": "MyTest", + "FullyQualifiedName": "MyTest", + "FullyQualifiedNameOrderable": "MyTest", + "Description": null, + "FolderType": "Standard", + "ProvisionType": "Automatic", + "PermissionModel": "FineGrained", + "ParentId": null, + "ParentKey": null, + "IsActive": true, + "FeedType": "Processes", + "ReservedOptions": null, + "Id": 89973 + } + ] +} diff --git a/ui-path-connector-test/src/com/axonivy/connector/uipath/test/json/machines.json b/ui-path-connector-test/src/com/axonivy/connector/uipath/test/json/machines.json new file mode 100644 index 0000000..a8a7cec --- /dev/null +++ b/ui-path-connector-test/src/com/axonivy/connector/uipath/test/json/machines.json @@ -0,0 +1,38 @@ +{ + "@odata.context": "https://cloud.uipath.com/orchestrator_/odata/$metadata#Machines/UiPath.Server.Configuration.OData.ExtendedMachineDto", + "@odata.count": 4, + "value": [ + { + "@odata.type": "#UiPath.Server.Configuration.OData.ExtendedMachineDto", + "ServerlessLicensingModel": null, + "LicenseKey": null, + "Name": "My workspace machine", + "Description": null, + "Type": "Template", + "Scope": "PersonalWorkspace", + "NonProductionSlots": 0, + "UnattendedSlots": 0, + "HeadlessSlots": 0, + "TestAutomationSlots": 0, + "AutomationCloudSlots": 0, + "AutomationCloudTestAutomationSlots": 0, + "Key": "480f27b8-09c8-4476-b01b-db2d1bd0f5d5", + "EndpointDetectionStatus": "NotAvailable", + "AutomationType": "Any", + "TargetFramework": "Any", + "ClientSecret": null, + "Id": 55490, + "RobotVersions": [ + { + "Count": 2, + "Version": "24.10.1" + } + ], + "RobotUsers": [], + "UpdatePolicy": null, + "Tags": [], + "MaintenanceWindow": null, + "VpnSettings": null + } + ] +} diff --git a/ui-path-connector-test/src_test/com/axonivy/connector/uipath/test/TestUiPathRPA.java b/ui-path-connector-test/src_test/com/axonivy/connector/uipath/test/UiPathTest.java similarity index 51% rename from ui-path-connector-test/src_test/com/axonivy/connector/uipath/test/TestUiPathRPA.java rename to ui-path-connector-test/src_test/com/axonivy/connector/uipath/test/UiPathTest.java index 146d0ec..f5cb3d9 100644 --- a/ui-path-connector-test/src_test/com/axonivy/connector/uipath/test/TestUiPathRPA.java +++ b/ui-path-connector-test/src_test/com/axonivy/connector/uipath/test/UiPathTest.java @@ -4,10 +4,11 @@ import java.util.List; -import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; import com.axonivy.connector.uipath.TenantHeaderFeature; +import com.axonivy.connector.uipath.ui.path.connector.UiPathJobData; import com.axonivy.connector.uipath.ui.path.connector.UiPathRpa; import ch.ivyteam.ivy.application.IApplication; @@ -25,18 +26,22 @@ /** * Service functionality is mocked out here: {@link UiPathMock} */ -@IvyProcessTest -public class TestUiPathRPA { +@IvyProcessTest(enableWebServer = true) +public class UiPathTest { - private static final BpmElement UI_PATH_END = BpmElement.pid("175F58F3612E10B1-f15"); + private static final String UI_PATH_REST_CLIENT = "UIPathRPA (UiPath.WebApi 18.0)"; + private static final BpmElement UI_PATH_JOB_ALL_ACTIVE_JOBS_END = BpmElement.pid("190E93ECBBC86C6F-f1"); + private static final BpmElement UI_PATH_JOB_START_JOB_END = BpmElement.pid("190E93ECBBC86C6F-f50"); + private static final BpmElement UI_PATH_RPA_END = BpmElement.pid("175F58F3612E10B1-f15"); - @BeforeEach - void beforeEach(AppFixture fixture, IApplication app) { - fixture.config("RestClients.UIPathRPA.Url", UiPathMock.URI); - fixture.config("RestClients.UIPathRPA.Features", ""); + + @BeforeAll + static void beforeAll(AppFixture fixture, IApplication app) { + fixture.config("RestClients." + UI_PATH_REST_CLIENT + ".Url", UiPathMock.URI); + fixture.config("RestClients." + UI_PATH_REST_CLIENT + ".Features", ""); RestClients clients = RestClients.of(app); - RestClient uiPathRpa = clients.find("UIPathRPA"); + RestClient uiPathRpa = clients.find(UI_PATH_REST_CLIENT); var testClient = uiPathRpa.toBuilder() .features(List.of( // exclude oauth-feature JsonFeature.class.getName(), @@ -44,6 +49,9 @@ void beforeEach(AppFixture fixture, IApplication app) { CsrfHeaderFeature.class.getName())) .property("AUTH.clientId", "notMyId") .property("AUTH.userKey", "notMyKey") + .property("AUTH.tenant", "notMyTenant") + .property("PATH.tenant", "tenant") + .property("PATH.organization", "organization") .toRestClient(); clients.set(testClient); } @@ -54,9 +62,20 @@ public void rpaDemo(BpmClient bpmClient, ISession session) { .process("uiPathDemo/robotGetOrders.ivp") .as().session(session) .execute(); - UiPathRpa data = result.data().lastOnElement(UI_PATH_END); + UiPathRpa data = result.data().lastOnElement(UI_PATH_RPA_END); assertThat(data.getLicense()).isNotNull(); assertThat(data.getReleases()).isNotEmpty(); assertThat(data.getRobots()).isNotEmpty(); } + + @Test + public void jobDemo(BpmClient bpmClient, ISession session) { + ExecutionResult result = bpmClient.start().process("uiPathDemo/triggerAllActiveJobs.ivp").as().session(session) + .execute(); + UiPathJobData data = result.data().lastOnElement(UI_PATH_JOB_ALL_ACTIVE_JOBS_END); + assertThat(data.getOrganizationunitId()).isNotNull(); + data = result.data().lastOnElement(UI_PATH_JOB_START_JOB_END); + assertThat(data.getMachines()).isNotEmpty(); + assertThat(data.getStartInfo()).isNotNull(); + } }