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 c6ade9d
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 @@ -25,6 +25,7 @@
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;

import com.netflix.conductor.common.run.WorkflowTestRequest;
import org.apache.commons.lang3.Validate;
import org.apache.commons.lang3.concurrent.BasicThreadFactory;

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() {
WorkflowDef workflowDef = new WorkflowDef();
workflowDef.setName("testable-flow");
WorkflowTask task = new WorkflowTask();
task.setName("testable-task");
task.setTaskReferenceName("testable-task-ref");
List<WorkflowTask> tasks = List.of(task);
workflowDef.setTasks(tasks);

WorkflowTestRequest testRequest = new WorkflowTestRequest();
testRequest.setWorkflowDef(workflowDef);
testRequest.setName("testable-flow");
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.assertNotNull(workflow);
Assertions.assertEquals("ok", workflow.getOutput().get("result"));
}

StartWorkflowRequest getStartWorkflowRequest() {
StartWorkflowRequest startWorkflowRequest = new StartWorkflowRequest();
startWorkflowRequest.setName(Commons.WORKFLOW_NAME);
Expand Down

0 comments on commit c6ade9d

Please sign in to comment.