Search in sources :

Example 71 with WorkflowTask

use of com.netflix.conductor.common.metadata.workflow.WorkflowTask in project conductor by Netflix.

the class WorkflowDefConstraintTest method testWorkflowTaskInvalidInputParam.

@Test
public /*Testcase to check inputParam is not valid
     */
void testWorkflowTaskInvalidInputParam() {
    WorkflowDef workflowDef = new WorkflowDef();
    workflowDef.setName("sampleWorkflow");
    workflowDef.setDescription("Sample workflow def");
    workflowDef.setOwnerEmail("sample@test.com");
    workflowDef.setVersion(2);
    WorkflowTask workflowTask_1 = new WorkflowTask();
    workflowTask_1.setName("task_1");
    workflowTask_1.setTaskReferenceName("task_1");
    workflowTask_1.setType(TaskType.TASK_TYPE_SIMPLE);
    Map<String, Object> inputParam = new HashMap<>();
    inputParam.put("fileLocation", "${work.input.fileLocation}");
    workflowTask_1.setInputParameters(inputParam);
    List<WorkflowTask> tasks = new ArrayList<>();
    tasks.add(workflowTask_1);
    workflowDef.setTasks(tasks);
    ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
    validator = factory.getValidator();
    when(mockMetadataDao.getTaskDef("work1")).thenReturn(new TaskDef());
    Set<ConstraintViolation<WorkflowDef>> result = validator.validate(workflowDef);
    assertEquals(1, result.size());
    assertEquals(result.iterator().next().getMessage(), "taskReferenceName: work for given task: task_1 input value: fileLocation of input parameter: ${work.input.fileLocation} is not defined in workflow definition.");
}
Also used : WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) ValidatorFactory(javax.validation.ValidatorFactory) HashMap(java.util.HashMap) TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) ConstraintViolation(javax.validation.ConstraintViolation) ArrayList(java.util.ArrayList) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 72 with WorkflowTask

use of com.netflix.conductor.common.metadata.workflow.WorkflowTask in project conductor by Netflix.

the class WorkflowDefConstraintTest method testWorkflowTaskSimple.

@Test
public void testWorkflowTaskSimple() {
    WorkflowDef workflowDef = new WorkflowDef();
    workflowDef.setName("sampleWorkflow");
    workflowDef.setDescription("Sample workflow def");
    workflowDef.setOwnerEmail("sample@test.com");
    workflowDef.setVersion(2);
    WorkflowTask workflowTask_1 = new WorkflowTask();
    workflowTask_1.setName("task_1");
    workflowTask_1.setTaskReferenceName("task_1");
    workflowTask_1.setType(TaskType.TASK_TYPE_SIMPLE);
    Map<String, Object> inputParam = new HashMap<>();
    inputParam.put("fileLocation", "${workflow.input.fileLocation}");
    workflowTask_1.setInputParameters(inputParam);
    List<WorkflowTask> tasks = new ArrayList<>();
    tasks.add(workflowTask_1);
    workflowDef.setTasks(tasks);
    Set<ConstraintViolation<WorkflowDef>> result = validator.validate(workflowDef);
    assertEquals(0, result.size());
}
Also used : WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) HashMap(java.util.HashMap) ConstraintViolation(javax.validation.ConstraintViolation) ArrayList(java.util.ArrayList) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Matchers.anyString(org.mockito.Matchers.anyString) Test(org.junit.Test)

Example 73 with WorkflowTask

use of com.netflix.conductor.common.metadata.workflow.WorkflowTask in project conductor by Netflix.

the class WorkflowTaskTypeConstraintTest method testWorkflowTaskTypeDoWhileWithSubWorkflow.

@Test
public void testWorkflowTaskTypeDoWhileWithSubWorkflow() {
    WorkflowTask workflowTask = createSampleWorkflowTask();
    workflowTask.setType("DO_WHILE");
    workflowTask.setLoopCondition("Test condition");
    WorkflowTask workflowTask2 = createSampleWorkflowTask();
    workflowTask2.setType("SUB_WORKFLOW");
    workflowTask.setLoopOver(Collections.singletonList(workflowTask2));
    when(mockMetadataDao.getTaskDef(anyString())).thenReturn(new TaskDef());
    Set<ConstraintViolation<WorkflowTask>> result = validator.validate(workflowTask);
    assertEquals(1, result.size());
    List<String> validationErrors = new ArrayList<>();
    result.forEach(e -> validationErrors.add(e.getMessage()));
    assertTrue(validationErrors.contains("SUB_WORKFLOW task inside loopover task: encode is not supported."));
}
Also used : TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) ConstraintViolation(javax.validation.ConstraintViolation) ArrayList(java.util.ArrayList) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) ArgumentMatchers.anyString(org.mockito.ArgumentMatchers.anyString) Test(org.junit.Test)

Example 74 with WorkflowTask

use of com.netflix.conductor.common.metadata.workflow.WorkflowTask in project conductor by Netflix.

the class WorkflowTaskTypeConstraintTest method testWorkflowTaskTestSetType.

@Test
public void testWorkflowTaskTestSetType() throws NoSuchMethodException {
    WorkflowTask workflowTask = createSampleWorkflowTask();
    Method method = WorkflowTask.class.getMethod("setType", String.class);
    Object[] parameterValues = { "" };
    ExecutableValidator executableValidator = validator.forExecutables();
    Set<ConstraintViolation<Object>> result = executableValidator.validateParameters(workflowTask, method, parameterValues);
    assertEquals(1, result.size());
    assertEquals(result.iterator().next().getMessage(), "WorkTask type cannot be null or empty");
}
Also used : ExecutableValidator(javax.validation.executable.ExecutableValidator) ConstraintViolation(javax.validation.ConstraintViolation) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 75 with WorkflowTask

use of com.netflix.conductor.common.metadata.workflow.WorkflowTask in project conductor by Netflix.

the class MetadataMapperServiceTest method testNoVersionPopulationForSubworkflowTaskIfAvailable.

@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);
}
Also used : SubWorkflowParams(com.netflix.conductor.common.metadata.workflow.SubWorkflowParams) WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Test(org.junit.Test)

Aggregations

WorkflowTask (com.netflix.conductor.common.metadata.workflow.WorkflowTask)244 Test (org.junit.Test)166 WorkflowDef (com.netflix.conductor.common.metadata.workflow.WorkflowDef)148 TaskDef (com.netflix.conductor.common.metadata.tasks.TaskDef)106 Workflow (com.netflix.conductor.common.run.Workflow)106 HashMap (java.util.HashMap)103 Task (com.netflix.conductor.common.metadata.tasks.Task)98 ArrayList (java.util.ArrayList)52 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)44 ConstraintViolation (javax.validation.ConstraintViolation)41 LinkedList (java.util.LinkedList)40 List (java.util.List)36 SubWorkflow (com.netflix.conductor.core.execution.tasks.SubWorkflow)32 Map (java.util.Map)26 SubWorkflowParams (com.netflix.conductor.common.metadata.workflow.SubWorkflowParams)25 DynamicForkJoinTaskList (com.netflix.conductor.common.metadata.workflow.DynamicForkJoinTaskList)18 WorkflowSystemTask (com.netflix.conductor.core.execution.tasks.WorkflowSystemTask)14 UserTask (com.netflix.conductor.tests.utils.UserTask)14 ValidatorFactory (javax.validation.ValidatorFactory)13 VisibleForTesting (com.google.common.annotations.VisibleForTesting)11