From a6be214299a43b6531cf043ef79b580d1fc243c5 Mon Sep 17 00:00:00 2001 From: Yong Sheng Tan Date: Thu, 12 Dec 2024 10:10:06 +0800 Subject: [PATCH] Add testWorkflow to OrkesWorkflowClient --- .../client/http/OrkesWorkflowClient.java | 5 ++++ .../client/http/WorkflowClientTests.java | 25 +++++++++++++++++++ 2 files changed, 30 insertions(+) diff --git a/conductor-clients/java/conductor-java-sdk/orkes-client/src/main/java/io/orkes/conductor/client/http/OrkesWorkflowClient.java b/conductor-clients/java/conductor-java-sdk/orkes-client/src/main/java/io/orkes/conductor/client/http/OrkesWorkflowClient.java index 0b47c6ff3..6748409e4 100644 --- a/conductor-clients/java/conductor-java-sdk/orkes-client/src/main/java/io/orkes/conductor/client/http/OrkesWorkflowClient.java +++ b/conductor-clients/java/conductor-java-sdk/orkes-client/src/main/java/io/orkes/conductor/client/http/OrkesWorkflowClient.java @@ -36,6 +36,7 @@ import com.netflix.conductor.common.run.SearchResult; import com.netflix.conductor.common.run.Workflow; import com.netflix.conductor.common.run.WorkflowSummary; +import com.netflix.conductor.common.run.WorkflowTestRequest; import io.orkes.conductor.client.model.CorrelationIdsSearchRequest; import io.orkes.conductor.client.model.WorkflowRun; @@ -202,6 +203,10 @@ public void skipTaskFromWorkflow(String workflowId, String taskReferenceName) { workflowClient.skipTaskFromWorkflow(workflowId, taskReferenceName); } + public Workflow testWorkflow(WorkflowTestRequest testRequest) { + return workflowClient.testWorkflow(testRequest); + } + public SearchResult search(String query) { return workflowClient.search(query); } diff --git a/conductor-clients/java/conductor-java-sdk/tests/src/test/java/io/orkes/conductor/client/http/WorkflowClientTests.java b/conductor-clients/java/conductor-java-sdk/tests/src/test/java/io/orkes/conductor/client/http/WorkflowClientTests.java index 465ec03b8..7e8ec62cf 100644 --- a/conductor-clients/java/conductor-java-sdk/tests/src/test/java/io/orkes/conductor/client/http/WorkflowClientTests.java +++ b/conductor-clients/java/conductor-java-sdk/tests/src/test/java/io/orkes/conductor/client/http/WorkflowClientTests.java @@ -16,6 +16,9 @@ import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; +import com.netflix.conductor.common.metadata.tasks.TaskResult; +import com.netflix.conductor.common.metadata.workflow.WorkflowTask; +import com.netflix.conductor.common.run.WorkflowTestRequest; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.Test; @@ -184,6 +187,28 @@ void testExecuteWorkflow() { // TODO } + @Test + void testWorkflow() { + WorkflowTask task = new WorkflowTask(); + task.setName("testable-task"); + task.setTaskReferenceName("testable-task-ref"); + + WorkflowDef workflowDef = new WorkflowDef(); + workflowDef.setName("testable-flow"); + workflowDef.setTasks(List.of(task)); + + WorkflowTestRequest testRequest = new WorkflowTestRequest(); + testRequest.setName("testable-flow"); + testRequest.setWorkflowDef(workflowDef); + testRequest.setTaskRefToMockOutput(Map.of( + "testable-task-ref", + List.of(new WorkflowTestRequest.TaskMock(TaskResult.Status.COMPLETED, Map.of("result", "ok"))) + )); + + Workflow workflow = workflowClient.testWorkflow(testRequest); + Assertions.assertEquals("ok", workflow.getOutput().get("result")); + } + StartWorkflowRequest getStartWorkflowRequest() { StartWorkflowRequest startWorkflowRequest = new StartWorkflowRequest(); startWorkflowRequest.setName(Commons.WORKFLOW_NAME);