DeciderService { private List<Task> getNextTask(Workflow workflow, Task task) { final WorkflowDef workflowDef = workflow.getWorkflowDefinition(); if (SystemTaskType.is(task.getTaskType()) && SystemTaskType.DECISION.name().equals(task.getTaskType())) { if (task.getInputData().get("hasChildren") != null) { return Collections.emptyList(); } } String taskReferenceName = task.isLoopOverTask() ? TaskUtils.removeIterationFromTaskRefName(task.getReferenceTaskName()) : task.getReferenceTaskName(); WorkflowTask taskToSchedule = workflowDef.getNextTask(taskReferenceName); while (isTaskSkipped(taskToSchedule, workflow)) { taskToSchedule = workflowDef.getNextTask(taskToSchedule.getTaskReferenceName()); } if (taskToSchedule != null) { return getTasksToBeScheduled(workflow, taskToSchedule, 0); } return Collections.emptyList(); } @Inject  DeciderService(ParametersUtils parametersUtils, MetadataDAO metadataDAO,
                          ExternalPayloadStorageUtils externalPayloadStorageUtils,
                          @Named("TaskMappers") Map<String, TaskMapper> taskMappers, Configuration configuration); DeciderOutcome decide(Workflow workflow); List<Task> getTasksToBeScheduled(Workflow workflow,
                                            WorkflowTask taskToSchedule, int retryCount); List<Task> getTasksToBeScheduled(Workflow workflow,
                                            WorkflowTask taskToSchedule, int retryCount, String retriedTaskId);  }
@Test public void testGetNextTask() { WorkflowDef def = createNestedWorkflow(); WorkflowTask firstTask = def.getTasks().get(0); assertNotNull(firstTask); assertEquals("fork1", firstTask.getTaskReferenceName()); WorkflowTask nextAfterFirst = def.getNextTask(firstTask.getTaskReferenceName()); assertNotNull(nextAfterFirst); assertEquals("join1", nextAfterFirst.getTaskReferenceName()); WorkflowTask fork2 = def.getTaskByRefName("fork2"); assertNotNull(fork2); assertEquals("fork2", fork2.getTaskReferenceName()); WorkflowTask taskAfterFork2 = def.getNextTask("fork2"); assertNotNull(taskAfterFork2); assertEquals("join2", taskAfterFork2.getTaskReferenceName()); WorkflowTask t2 = def.getTaskByRefName("t2"); assertNotNull(t2); assertEquals("t2", t2.getTaskReferenceName()); WorkflowTask taskAfterT2 = def.getNextTask("t2"); assertNotNull(taskAfterT2); assertEquals("t4", taskAfterT2.getTaskReferenceName()); WorkflowTask taskAfterT3 = def.getNextTask("t3"); assertNotNull(taskAfterT3); assertEquals(TaskType.DECISION.name(), taskAfterT3.getType()); assertEquals("d1", taskAfterT3.getTaskReferenceName()); WorkflowTask taskAfterT4 = def.getNextTask("t4"); assertNotNull(taskAfterT4); assertEquals("join2", taskAfterT4.getTaskReferenceName()); WorkflowTask taskAfterT6 = def.getNextTask("t6"); assertNotNull(taskAfterT6); assertEquals("t9", taskAfterT6.getTaskReferenceName()); WorkflowTask taskAfterJoin2 = def.getNextTask("join2"); assertNotNull(taskAfterJoin2); assertEquals("join1", taskAfterJoin2.getTaskReferenceName()); WorkflowTask taskAfterJoin1 = def.getNextTask("join1"); assertNotNull(taskAfterJoin1); assertEquals("t5", taskAfterJoin1.getTaskReferenceName()); WorkflowTask taskAfterSubWF = def.getNextTask("sw1"); assertNotNull(taskAfterSubWF); assertEquals("join1", taskAfterSubWF.getTaskReferenceName()); WorkflowTask taskAfterT9 = def.getNextTask("t9"); assertNotNull(taskAfterT9); assertEquals("join2", taskAfterT9.getTaskReferenceName()); }