Search in sources :

Example 41 with TaskDef

use of com.netflix.conductor.common.metadata.tasks.TaskDef in project conductor by Netflix.

the class WorkflowDefConstraintTest method init.

@Before
public void init() {
    validator = new ValidationModule().getValidator();
    mockMetadataDao = Mockito.mock(MetadataDAO.class);
    when(mockMetadataDao.getTaskDef(anyString())).thenReturn(new TaskDef());
    ValidationContext.initialize(mockMetadataDao);
}
Also used : TaskDef(com.netflix.conductor.common.metadata.tasks.TaskDef) ValidationModule(com.netflix.conductor.core.config.ValidationModule) MetadataDAO(com.netflix.conductor.dao.MetadataDAO) Before(org.junit.Before)

Example 42 with TaskDef

use of com.netflix.conductor.common.metadata.tasks.TaskDef 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 43 with TaskDef

use of com.netflix.conductor.common.metadata.tasks.TaskDef 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 44 with TaskDef

use of com.netflix.conductor.common.metadata.tasks.TaskDef in project conductor by Netflix.

the class WorkflowTaskTypeConstraintTest method testWorkflowTaskTypeDecision.

@Test
public void testWorkflowTaskTypeDecision() {
    WorkflowTask workflowTask = createSampleWorkflowTask();
    workflowTask.setType("DECISION");
    when(mockMetadataDao.getTaskDef(anyString())).thenReturn(new TaskDef());
    Set<ConstraintViolation<WorkflowTask>> result = validator.validate(workflowTask);
    assertEquals(2, result.size());
    List<String> validationErrors = new ArrayList<>();
    result.forEach(e -> validationErrors.add(e.getMessage()));
    assertTrue(validationErrors.contains("decisionCases should have atleast one task for taskType: DECISION taskName: encode"));
    assertTrue(validationErrors.contains("caseValueParam or caseExpression field is required for taskType: DECISION taskName: encode"));
}
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 45 with TaskDef

use of com.netflix.conductor.common.metadata.tasks.TaskDef in project conductor by Netflix.

the class WorkflowTaskTypeConstraintTest method testWorkflowTaskTypeKafkaPublishWithRequestParamMissing.

@Test
public void testWorkflowTaskTypeKafkaPublishWithRequestParamMissing() {
    WorkflowTask workflowTask = createSampleWorkflowTask();
    workflowTask.setType("KAFKA_PUBLISH");
    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("inputParameters.kafka_request field is required for taskType: KAFKA_PUBLISH taskName: encode"));
}
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)

Aggregations

TaskDef (com.netflix.conductor.common.metadata.tasks.TaskDef)172 Test (org.junit.Test)128 WorkflowTask (com.netflix.conductor.common.metadata.workflow.WorkflowTask)121 Task (com.netflix.conductor.common.metadata.tasks.Task)77 Workflow (com.netflix.conductor.common.run.Workflow)76 WorkflowDef (com.netflix.conductor.common.metadata.workflow.WorkflowDef)73 HashMap (java.util.HashMap)56 ArrayList (java.util.ArrayList)32 ConstraintViolation (javax.validation.ConstraintViolation)31 SubWorkflow (com.netflix.conductor.core.execution.tasks.SubWorkflow)30 UserTask (com.netflix.conductor.tests.utils.UserTask)28 LinkedList (java.util.LinkedList)28 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)27 List (java.util.List)22 Map (java.util.Map)19 ApplicationException (com.netflix.conductor.core.execution.ApplicationException)18 Before (org.junit.Before)14 ExpectedException (org.junit.rules.ExpectedException)13 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)12 Collectors (java.util.stream.Collectors)11