WaitTaskMapper implements TaskMapper { @Override public List<Task> getMappedTasks(TaskMapperContext taskMapperContext) { logger.debug("TaskMapperContext {} in WaitTaskMapper", taskMapperContext); WorkflowTask taskToSchedule = taskMapperContext.getTaskToSchedule(); Workflow workflowInstance = taskMapperContext.getWorkflowInstance(); String taskId = taskMapperContext.getTaskId(); Map<String, Object> waitTaskInput = parametersUtils.getTaskInputV2(taskMapperContext.getTaskToSchedule().getInputParameters(), workflowInstance, taskId, null); Task waitTask = new Task(); waitTask.setTaskType(Wait.NAME); waitTask.setTaskDefName(taskMapperContext.getTaskToSchedule().getName()); waitTask.setReferenceTaskName(taskMapperContext.getTaskToSchedule().getTaskReferenceName()); waitTask.setWorkflowInstanceId(workflowInstance.getWorkflowId()); waitTask.setWorkflowType(workflowInstance.getWorkflowName()); waitTask.setCorrelationId(workflowInstance.getCorrelationId()); waitTask.setScheduledTime(System.currentTimeMillis()); waitTask.setInputData(waitTaskInput); waitTask.setTaskId(taskId); waitTask.setStatus(Task.Status.IN_PROGRESS); waitTask.setWorkflowTask(taskToSchedule); waitTask.setWorkflowPriority(workflowInstance.getPriority()); return Collections.singletonList(waitTask); } WaitTaskMapper(ParametersUtils parametersUtils); @Override List<Task> getMappedTasks(TaskMapperContext taskMapperContext); static final Logger logger; }
@Test public void getMappedTasks() { WorkflowTask taskToSchedule = new WorkflowTask(); taskToSchedule.setName("Wait_task"); taskToSchedule.setType(TaskType.WAIT.name()); String taskId = IDGenerator.generate(); ParametersUtils parametersUtils = new ParametersUtils(); Workflow workflow = new Workflow(); WorkflowDef workflowDef = new WorkflowDef(); workflow.setWorkflowDefinition(workflowDef); TaskMapperContext taskMapperContext = TaskMapperContext.newBuilder() .withWorkflowDefinition(workflowDef) .withWorkflowInstance(workflow) .withTaskDefinition(new TaskDef()) .withTaskToSchedule(taskToSchedule) .withTaskInput(new HashMap<>()) .withRetryCount(0) .withTaskId(taskId) .build(); WaitTaskMapper waitTaskMapper = new WaitTaskMapper(parametersUtils); List<Task> mappedTasks = waitTaskMapper.getMappedTasks(taskMapperContext); assertEquals(1, mappedTasks.size()); assertEquals(Wait.NAME, mappedTasks.get(0).getTaskType()); }