Search in sources :

Example 71 with WorkflowDef

use of com.netflix.conductor.common.metadata.workflow.WorkflowDef 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 WorkflowDef

use of com.netflix.conductor.common.metadata.workflow.WorkflowDef 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 WorkflowDef

use of com.netflix.conductor.common.metadata.workflow.WorkflowDef 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)

Example 74 with WorkflowDef

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

the class MetadataMapperServiceTest method testExceptionWhenWorkflowDefinitionNotAvailable.

@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);
}
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)

Example 75 with WorkflowDef

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

the class JsonMapperProviderTest method testWorkflowSerDe.

@Test
public void testWorkflowSerDe() throws IOException {
    WorkflowDef workflowDef = new WorkflowDef();
    workflowDef.setName("testDef");
    workflowDef.setVersion(2);
    Workflow workflow = new Workflow();
    workflow.setWorkflowDefinition(workflowDef);
    workflow.setWorkflowId("test-workflow-id");
    workflow.setStatus(Workflow.WorkflowStatus.RUNNING);
    workflow.setStartTime(10L);
    workflow.setInput(null);
    Map<String, Object> data = new HashMap<>();
    data.put("someKey", null);
    data.put("someId", "abc123");
    workflow.setOutput(data);
    ObjectMapper objectMapper = new JsonMapperProvider().get();
    String workflowPayload = objectMapper.writeValueAsString(workflow);
    Workflow workflow1 = objectMapper.readValue(workflowPayload, Workflow.class);
    assertTrue(workflow1.getOutput().containsKey("someKey"));
    assertNull(workflow1.getOutput().get("someKey"));
    assertNotNull(workflow1.getInput());
}
Also used : WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) HashMap(java.util.HashMap) Workflow(com.netflix.conductor.common.run.Workflow) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonMapperProvider(com.netflix.conductor.common.utils.JsonMapperProvider) Test(org.junit.Test)

Aggregations

WorkflowDef (com.netflix.conductor.common.metadata.workflow.WorkflowDef)247 Test (org.junit.Test)185 WorkflowTask (com.netflix.conductor.common.metadata.workflow.WorkflowTask)173 Workflow (com.netflix.conductor.common.run.Workflow)128 HashMap (java.util.HashMap)123 Task (com.netflix.conductor.common.metadata.tasks.Task)100 TaskDef (com.netflix.conductor.common.metadata.tasks.TaskDef)71 SubWorkflow (com.netflix.conductor.core.execution.tasks.SubWorkflow)49 ArrayList (java.util.ArrayList)43 LinkedList (java.util.LinkedList)37 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)35 List (java.util.List)33 UserTask (com.netflix.conductor.tests.utils.UserTask)28 Map (java.util.Map)25 SubWorkflowParams (com.netflix.conductor.common.metadata.workflow.SubWorkflowParams)20 ConstraintViolation (javax.validation.ConstraintViolation)14 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)13 ApplicationException (com.netflix.conductor.core.execution.ApplicationException)13 ValidatorFactory (javax.validation.ValidatorFactory)13 DynamicForkJoinTaskList (com.netflix.conductor.common.metadata.workflow.DynamicForkJoinTaskList)12