From 6b7429efdae2343ed6154240713754e6a637f9c3 Mon Sep 17 00:00:00 2001 From: Hoan Nguyen Date: Wed, 31 Jul 2024 14:09:24 +0700 Subject: [PATCH] Convert to 11.4 Fix test Introduce new tests --- .../connector/uipath/test/UiPathMock.java | 14 +++++++ .../connector/uipath/test/json/folders.json | 22 +++++++++++ .../connector/uipath/test/json/machines.json | 38 +++++++++++++++++++ .../{TestUiPathRPA.java => UiPathTest.java} | 28 ++++++++++---- ui-path-connector/processes/uiPathRpa.p.json | 31 +++++++++------ .../connector/uipath/TenantHeaderFeature.java | 1 - 6 files changed, 115 insertions(+), 19 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} (65%) 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 b1d6300..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 @@ -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 65% 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 0d2f5b3..58340f8 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,14 +26,16 @@ /** * 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) { + @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", ""); @@ -58,9 +61,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(); + } } diff --git a/ui-path-connector/processes/uiPathRpa.p.json b/ui-path-connector/processes/uiPathRpa.p.json index 33ca42a..30a4cc7 100644 --- a/ui-path-connector/processes/uiPathRpa.p.json +++ b/ui-path-connector/processes/uiPathRpa.p.json @@ -34,7 +34,7 @@ } }, "visual" : { - "at" : { "x" : 312, "y" : 64 }, + "at" : { "x" : 256, "y" : 64 }, "size" : { "width" : 128 }, "description" : [ "Simple request against RPA Orchestration Platform provided by UIPath", @@ -43,7 +43,7 @@ "icon" : "res:/webContent/icons/uipath.png" }, "connect" : [ - { "id" : "f6", "to" : "f5" } + { "id" : "f6", "to" : "f37" } ] }, { "id" : "f5", @@ -55,7 +55,10 @@ "config" : { "target" : { "clientId" : "c700c640-4f76-4cbe-8724-dbc663d8bc0a", - "path" : "/odata/Jobs" + "path" : "/odata/Jobs", + "headers" : { + "X-Uipath-Organizationunitid" : "in.organizationunitId" + } }, "response" : { "entity" : { @@ -68,12 +71,12 @@ } }, "visual" : { - "at" : { "x" : 472, "y" : 64 }, + "at" : { "x" : 464, "y" : 144 }, "size" : { "width" : 128 }, "icon" : "res:/webContent/icons/uipath.png" }, "connect" : [ - { "id" : "f1", "to" : "f37" } + { "id" : "f1", "to" : "f0" } ] }, { "id" : "f0", @@ -113,7 +116,7 @@ ] }, "visual" : { - "at" : { "x" : 472, "y" : 224 }, + "at" : { "x" : 464, "y" : 224 }, "size" : { "width" : 128 }, "icon" : "res:/webContent/icons/uipath.png" }, @@ -145,6 +148,9 @@ "path" : "/odata/Releases", "queryParams" : { "$filter" : "\"contains(ProcessKey, 'order')\"" + }, + "headers" : { + "X-Uipath-Organizationunitid" : "in.organizationunitId" } }, "response" : { @@ -158,7 +164,7 @@ } }, "visual" : { - "at" : { "x" : 472, "y" : 304 }, + "at" : { "x" : 464, "y" : 304 }, "size" : { "width" : 128 }, "icon" : "res:/webContent/icons/uipath.png" }, @@ -176,7 +182,10 @@ "method" : "POST", "target" : { "clientId" : "c700c640-4f76-4cbe-8724-dbc663d8bc0a", - "path" : "/odata/Jobs/UiPath.Server.Configuration.OData.StartJobs" + "path" : "/odata/Jobs/UiPath.Server.Configuration.OData.StartJobs", + "headers" : { + "X-Uipath-Organizationunitid" : "in.organizationunitId" + } }, "body" : { "entity" : { @@ -212,7 +221,7 @@ } }, "visual" : { - "at" : { "x" : 472, "y" : 384 }, + "at" : { "x" : 464, "y" : 384 }, "size" : { "width" : 128 }, "icon" : "res:/webContent/icons/uipath.png" }, @@ -282,12 +291,12 @@ } }, "visual" : { - "at" : { "x" : 472, "y" : 144 }, + "at" : { "x" : 464, "y" : 64 }, "size" : { "width" : 128 }, "icon" : "res:/webContent/icons/uipath.png" }, "connect" : [ - { "id" : "f2", "to" : "f0" } + { "id" : "f2", "to" : "f5" } ] } ] } \ No newline at end of file diff --git a/ui-path-connector/src/com/axonivy/connector/uipath/TenantHeaderFeature.java b/ui-path-connector/src/com/axonivy/connector/uipath/TenantHeaderFeature.java index b75ed94..1ccee12 100644 --- a/ui-path-connector/src/com/axonivy/connector/uipath/TenantHeaderFeature.java +++ b/ui-path-connector/src/com/axonivy/connector/uipath/TenantHeaderFeature.java @@ -37,7 +37,6 @@ private OrechstratorTenantFilter(String tenant) public void filter(ClientRequestContext context) throws IOException { context.getHeaders().add("X-UIPATH-TenantName", tenant); - context.getHeaders().add("X-Uipath-Organizationunitid", tenant); } }