Skip to content

Commit

Permalink
Add testWorkflow to OrkesWorkflowClient
Browse files Browse the repository at this point in the history
  • Loading branch information
ystxn committed Dec 12, 2024
1 parent 1259a4a commit a6be214
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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<WorkflowSummary> search(String query) {
return workflowClient.search(query);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit a6be214

Please sign in to comment.