MetadataMapperService { public WorkflowDef populateTaskDefinitions(WorkflowDef workflowDefinition) { Preconditions.checkNotNull(workflowDefinition, "workflowDefinition cannot be null"); workflowDefinition.collectTasks().forEach( this::populateWorkflowTaskWithDefinition ); checkNotEmptyDefinitions(workflowDefinition); return workflowDefinition; } @Inject  MetadataMapperService(MetadataDAO metadataDAO); WorkflowDef lookupForWorkflowDefinition(String name, Integer version); Workflow populateWorkflowWithDefinitions(Workflow workflow); WorkflowDef populateTaskDefinitions(WorkflowDef workflowDefinition); Task populateTaskWithDefinition(Task task); static final Logger logger; }
@Test public void testMetadataPopulationOnSimpleTask() { String nameTaskDefinition = "task1"; TaskDef taskDefinition = createTaskDefinition(nameTaskDefinition); WorkflowTask workflowTask = createWorkflowTask(nameTaskDefinition); when(metadataDAO.getTaskDef(nameTaskDefinition)).thenReturn(taskDefinition); WorkflowDef workflowDefinition = createWorkflowDefinition("testMetadataPopulation"); workflowDefinition.setTasks(ImmutableList.of(workflowTask)); metadataMapperService.populateTaskDefinitions(workflowDefinition); assertEquals(1, workflowDefinition.getTasks().size()); WorkflowTask populatedWorkflowTask = workflowDefinition.getTasks().get(0); assertNotNull(populatedWorkflowTask.getTaskDefinition()); verify(metadataDAO).getTaskDef(nameTaskDefinition); }
@Test public void testNoMetadataPopulationOnEmbeddedTaskDefinition() { String nameTaskDefinition = "task2"; TaskDef taskDefinition = createTaskDefinition(nameTaskDefinition); WorkflowTask workflowTask = createWorkflowTask(nameTaskDefinition); workflowTask.setTaskDefinition(taskDefinition); WorkflowDef workflowDefinition = createWorkflowDefinition("testMetadataPopulation"); workflowDefinition.setTasks(ImmutableList.of(workflowTask)); metadataMapperService.populateTaskDefinitions(workflowDefinition); assertEquals(1, workflowDefinition.getTasks().size()); WorkflowTask populatedWorkflowTask = workflowDefinition.getTasks().get(0); assertNotNull(populatedWorkflowTask.getTaskDefinition()); verifyNoInteractions(metadataDAO); }
@Test public void testMetadataPopulationOnlyOnNecessaryWorkflowTasks() { String nameTaskDefinition1 = "task4"; TaskDef taskDefinition = createTaskDefinition(nameTaskDefinition1); WorkflowTask workflowTask1 = createWorkflowTask(nameTaskDefinition1); workflowTask1.setTaskDefinition(taskDefinition); String nameTaskDefinition2 = "task5"; WorkflowTask workflowTask2 = createWorkflowTask(nameTaskDefinition2); WorkflowDef workflowDefinition = createWorkflowDefinition("testMetadataPopulation"); workflowDefinition.setTasks(ImmutableList.of(workflowTask1, workflowTask2)); when(metadataDAO.getTaskDef(nameTaskDefinition2)).thenReturn(taskDefinition); metadataMapperService.populateTaskDefinitions(workflowDefinition); assertEquals(2, workflowDefinition.getTasks().size()); List<WorkflowTask> workflowTasks = workflowDefinition.getTasks(); assertNotNull(workflowTasks.get(0).getTaskDefinition()); assertNotNull(workflowTasks.get(1).getTaskDefinition()); verify(metadataDAO).getTaskDef(nameTaskDefinition2); verifyNoMoreInteractions(metadataDAO); }
@Test(expected = ApplicationException.class) public void testMetadataPopulationMissingDefinitions() { String nameTaskDefinition1 = "task4"; WorkflowTask workflowTask1 = createWorkflowTask(nameTaskDefinition1); String nameTaskDefinition2 = "task5"; WorkflowTask workflowTask2 = createWorkflowTask(nameTaskDefinition2); TaskDef taskDefinition = createTaskDefinition(nameTaskDefinition1); WorkflowDef workflowDefinition = createWorkflowDefinition("testMetadataPopulation"); workflowDefinition.setTasks(ImmutableList.of(workflowTask1, workflowTask2)); when(metadataDAO.getTaskDef(nameTaskDefinition1)).thenReturn(taskDefinition); when(metadataDAO.getTaskDef(nameTaskDefinition2)).thenReturn(null); metadataMapperService.populateTaskDefinitions(workflowDefinition); }
@Test public void testVersionPopulationForSubworkflowTaskIfVersionIsNotAvailable() { String nameTaskDefinition = "taskSubworkflow6"; String workflowDefinitionName = "subworkflow"; Integer version = 3; WorkflowDef subWorkflowDefinition = createWorkflowDefinition("workflowDefinitionName"); subWorkflowDefinition.setVersion(version); WorkflowTask workflowTask = createWorkflowTask(nameTaskDefinition); workflowTask.setWorkflowTaskType(TaskType.SUB_WORKFLOW); SubWorkflowParams subWorkflowParams = new SubWorkflowParams(); subWorkflowParams.setName(workflowDefinitionName); workflowTask.setSubWorkflowParam(subWorkflowParams); WorkflowDef workflowDefinition = createWorkflowDefinition("testMetadataPopulation"); workflowDefinition.setTasks(ImmutableList.of(workflowTask)); when(metadataDAO.getLatestWorkflowDef(workflowDefinitionName)).thenReturn(Optional.of(subWorkflowDefinition)); metadataMapperService.populateTaskDefinitions(workflowDefinition); assertEquals(1, workflowDefinition.getTasks().size()); List<WorkflowTask> workflowTasks = workflowDefinition.getTasks(); SubWorkflowParams params = workflowTasks.get(0).getSubWorkflowParam(); assertEquals(workflowDefinitionName, params.getName()); assertEquals(version, params.getVersion()); verify(metadataDAO).getLatestWorkflowDef(workflowDefinitionName); verify(metadataDAO).getTaskDef(nameTaskDefinition); verifyNoMoreInteractions(metadataDAO); }
@Test public void testNoVersionPopulationForSubworkflowTaskIfAvailable() { String nameTaskDefinition = "taskSubworkflow7"; String workflowDefinitionName = "subworkflow"; Integer version = 2; WorkflowTask workflowTask = createWorkflowTask(nameTaskDefinition); workflowTask.setWorkflowTaskType(TaskType.SUB_WORKFLOW); SubWorkflowParams subWorkflowParams = new SubWorkflowParams(); subWorkflowParams.setName(workflowDefinitionName); subWorkflowParams.setVersion(version); workflowTask.setSubWorkflowParam(subWorkflowParams); WorkflowDef workflowDefinition = createWorkflowDefinition("testMetadataPopulation"); workflowDefinition.setTasks(ImmutableList.of(workflowTask)); metadataMapperService.populateTaskDefinitions(workflowDefinition); assertEquals(1, workflowDefinition.getTasks().size()); List<WorkflowTask> workflowTasks = workflowDefinition.getTasks(); SubWorkflowParams params = workflowTasks.get(0).getSubWorkflowParam(); assertEquals(workflowDefinitionName, params.getName()); assertEquals(version, params.getVersion()); verify(metadataDAO).getTaskDef(nameTaskDefinition); verifyNoMoreInteractions(metadataDAO); }
@Test(expected = TerminateWorkflowException.class) public void testExceptionWhenWorkflowDefinitionNotAvailable() { String nameTaskDefinition = "taskSubworkflow8"; String workflowDefinitionName = "subworkflow"; WorkflowTask workflowTask = createWorkflowTask(nameTaskDefinition); workflowTask.setWorkflowTaskType(TaskType.SUB_WORKFLOW); SubWorkflowParams subWorkflowParams = new SubWorkflowParams(); subWorkflowParams.setName(workflowDefinitionName); workflowTask.setSubWorkflowParam(subWorkflowParams); WorkflowDef workflowDefinition = createWorkflowDefinition("testMetadataPopulation"); workflowDefinition.setTasks(ImmutableList.of(workflowTask)); when(metadataDAO.getLatestWorkflowDef(workflowDefinitionName)).thenReturn(Optional.empty()); metadataMapperService.populateTaskDefinitions(workflowDefinition); verify(metadataDAO).getLatestWorkflowDef(workflowDefinitionName); }