DynamicTaskMapper implements TaskMapper { @VisibleForTesting TaskDef getDynamicTaskDefinition(WorkflowTask taskToSchedule) throws TerminateWorkflowException { return Optional.ofNullable(taskToSchedule.getTaskDefinition()) .orElseGet(() -> Optional.ofNullable(metadataDAO.getTaskDef(taskToSchedule.getName())) .orElseThrow(() -> { String reason = String.format("Invalid task specified. Cannot find task by name %s in the task definitions", taskToSchedule.getName()); return new TerminateWorkflowException(reason); })); } DynamicTaskMapper(ParametersUtils parametersUtils, MetadataDAO metadataDAO); @Override List<Task> getMappedTasks(TaskMapperContext taskMapperContext);  }
@Test public void getDynamicTaskDefinition() { WorkflowTask workflowTask = new WorkflowTask(); workflowTask.setName("Foo"); TaskDef taskDef = new TaskDef(); taskDef.setName("Foo"); workflowTask.setTaskDefinition(taskDef); when(metadataDAO.getTaskDef(any())).thenReturn(new TaskDef()); TaskDef dynamicTaskDefinition = dynamicTaskMapper.getDynamicTaskDefinition(workflowTask); assertEquals(dynamicTaskDefinition, taskDef); }
@Test public void getDynamicTaskDefinitionNull() { WorkflowTask workflowTask = new WorkflowTask(); workflowTask.setName("Foo"); expectedException.expect(TerminateWorkflowException.class); expectedException.expectMessage(String.format("Invalid task specified. Cannot find task by name %s in the task definitions", workflowTask.getName())); dynamicTaskMapper.getDynamicTaskDefinition(workflowTask); }