Search in sources :

Example 6 with WorkflowDef

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

the class SubWorkflowParamsTest method testWorkflowDefJson.

@Test
public void testWorkflowDefJson() throws Exception {
    // name is null
    SubWorkflowParams subWorkflowParams = new SubWorkflowParams();
    subWorkflowParams.setName("dummy-name");
    WorkflowDef def = new WorkflowDef();
    def.setName("test_workflow");
    def.setVersion(1);
    WorkflowTask task = new WorkflowTask();
    task.setName("test_task");
    task.setTaskReferenceName("t1");
    def.getTasks().add(task);
    subWorkflowParams.setWorkflowDefinition(def);
    String expected = "{\n" + "  \"name\" : \"test_workflow\",\n" + "  \"version\" : 1,\n" + "  \"workflowDefinition\" : {\n" + "    \"inputParameters\" : [ ],\n" + "    \"name\" : \"test_workflow\",\n" + "    \"outputParameters\" : { },\n" + "    \"restartable\" : true,\n" + "    \"schemaVersion\" : 2,\n" + "    \"tasks\" : [ {\n" + "      \"asyncComplete\" : false,\n" + "      \"decisionCases\" : { },\n" + "      \"defaultCase\" : [ ],\n" + "      \"defaultExclusiveJoinTask\" : [ ],\n" + "      \"forkTasks\" : [ ],\n" + "      \"inputParameters\" : { },\n" + "      \"joinOn\" : [ ],\n" + "      \"loopOver\" : [ ],\n" + "      \"name\" : \"test_task\",\n" + "      \"optional\" : false,\n" + "      \"retryLogic\" : \"UNSPECIFIED\",\n" + "      \"startDelay\" : 0,\n" + "      \"taskReferenceName\" : \"t1\",\n" + "      \"type\" : \"SIMPLE\"\n" + "    } ],\n" + "    \"timeoutPolicy\" : \"ALERT_ONLY\",\n" + "    \"timeoutSeconds\" : 0,\n" + "    \"variables\" : { },\n" + "    \"version\" : 1,\n" + "    \"workflowStatusListenerEnabled\" : false\n" + "  }\n" + "}";
    ObjectMapper objectMapper = new JsonMapperProvider().get();
    objectMapper.enable(SerializationFeature.INDENT_OUTPUT);
    objectMapper.enable(MapperFeature.SORT_PROPERTIES_ALPHABETICALLY);
    objectMapper.enable(SerializationFeature.ORDER_MAP_ENTRIES_BY_KEYS);
    assertEquals(expected, objectMapper.writerWithDefaultPrettyPrinter().writeValueAsString(subWorkflowParams));
    SubWorkflowParams actualSubWorkflowParam = objectMapper.readValue(expected, SubWorkflowParams.class);
    assertEquals(subWorkflowParams, actualSubWorkflowParam);
    assertEquals(def, actualSubWorkflowParam.getWorkflowDefinition());
    assertEquals(def, actualSubWorkflowParam.getWorkflowDef());
}
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) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) JsonMapperProvider(com.netflix.conductor.common.utils.JsonMapperProvider) Test(org.junit.Test)

Example 7 with WorkflowDef

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

the class WorkflowDefValidatorTest method testWorkflowTaskInputParamInvalid.

@Test
public void testWorkflowTaskInputParamInvalid() {
    // name is null
    WorkflowDef workflowDef = new WorkflowDef();
    workflowDef.setSchemaVersion(2);
    workflowDef.setName("test_env");
    workflowDef.setOwnerEmail("owner@test.com");
    // name is null
    WorkflowTask workflowTask = new WorkflowTask();
    workflowTask.setName("t1");
    workflowTask.setWorkflowTaskType(TaskType.SIMPLE);
    workflowTask.setTaskReferenceName("t1");
    Map<String, Object> map = new HashMap<>();
    map.put("blabla", "${workflow.input.Space Value}");
    workflowTask.setInputParameters(map);
    workflowDef.getTasks().add(workflowTask);
    ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
    Validator validator = factory.getValidator();
    Set<ConstraintViolation<Object>> result = validator.validate(workflowDef);
    assertEquals(1, result.size());
    List<String> validationErrors = new ArrayList<>();
    result.forEach(e -> validationErrors.add(e.getMessage()));
    assertTrue(validationErrors.contains("key: blabla input parameter value: workflow.input.Space Value is not valid"));
}
Also used : WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) ValidatorFactory(javax.validation.ValidatorFactory) HashMap(java.util.HashMap) ConstraintViolation(javax.validation.ConstraintViolation) ArrayList(java.util.ArrayList) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Validator(javax.validation.Validator) Test(org.junit.Test)

Example 8 with WorkflowDef

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

the class WorkflowDefValidatorTest method testWorkflowDefConstraints.

@Test
public void testWorkflowDefConstraints() {
    // name is null
    WorkflowDef workflowDef = new WorkflowDef();
    workflowDef.setSchemaVersion(2);
    ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
    Validator validator = factory.getValidator();
    Set<ConstraintViolation<Object>> result = validator.validate(workflowDef);
    assertEquals(3, result.size());
    List<String> validationErrors = new ArrayList<>();
    result.forEach(e -> validationErrors.add(e.getMessage()));
    assertTrue(validationErrors.contains("WorkflowDef name cannot be null or empty"));
    assertTrue(validationErrors.contains("WorkflowTask list cannot be empty"));
    assertTrue(validationErrors.contains("ownerEmail cannot be empty"));
// assertTrue(validationErrors.contains("workflowDef schemaVersion: 1 should be >= 2"));
}
Also used : WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) ValidatorFactory(javax.validation.ValidatorFactory) ConstraintViolation(javax.validation.ConstraintViolation) ArrayList(java.util.ArrayList) Validator(javax.validation.Validator) Test(org.junit.Test)

Example 9 with WorkflowDef

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

the class WorkflowDefValidatorTest method testWorkflowOwnerInvalidEmail.

@Test
public void testWorkflowOwnerInvalidEmail() {
    WorkflowDef workflowDef = new WorkflowDef();
    workflowDef.setName("test_env");
    workflowDef.setOwnerEmail("owner");
    WorkflowTask workflowTask = new WorkflowTask();
    workflowTask.setName("t1");
    workflowTask.setWorkflowTaskType(TaskType.SIMPLE);
    workflowTask.setTaskReferenceName("t1");
    Map<String, Object> map = new HashMap<>();
    map.put("blabla", "");
    workflowTask.setInputParameters(map);
    workflowDef.getTasks().add(workflowTask);
    ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
    Validator validator = factory.getValidator();
    Set<ConstraintViolation<Object>> result = validator.validate(workflowDef);
    assertEquals(1, result.size());
    List<String> validationErrors = new ArrayList<>();
    result.forEach(e -> validationErrors.add(e.getMessage()));
    assertTrue(validationErrors.contains("ownerEmail should be valid email address"));
}
Also used : WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) ValidatorFactory(javax.validation.ValidatorFactory) HashMap(java.util.HashMap) ConstraintViolation(javax.validation.ConstraintViolation) ArrayList(java.util.ArrayList) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Validator(javax.validation.Validator) Test(org.junit.Test)

Example 10 with WorkflowDef

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

the class WorkflowDefValidatorTest method testWorkflowDefConstraintsWithMultipleEnvVariable.

@Test
public void testWorkflowDefConstraintsWithMultipleEnvVariable() {
    WorkflowDef workflowDef = new WorkflowDef();
    workflowDef.setSchemaVersion(2);
    workflowDef.setName("test_env");
    workflowDef.setOwnerEmail("owner@test.com");
    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("taskId", "${CPEWF_TASK_ID}");
    inputParam.put("entryPoint", "${NETFLIX_ENVIRONMENT} ${NETFLIX_STACK} ${CPEWF_TASK_ID} ${workflow.input.status}");
    workflowTask_1.setInputParameters(inputParam);
    WorkflowTask workflowTask_2 = new WorkflowTask();
    workflowTask_2.setName("task_2");
    workflowTask_2.setTaskReferenceName("task_2");
    workflowTask_2.setType(TaskType.TASK_TYPE_SIMPLE);
    Map<String, Object> inputParam2 = new HashMap<>();
    inputParam2.put("env", inputParam);
    workflowTask_2.setInputParameters(inputParam2);
    List<WorkflowTask> tasks = new ArrayList<>();
    tasks.add(workflowTask_1);
    tasks.add(workflowTask_2);
    workflowDef.setTasks(tasks);
    ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
    Validator validator = factory.getValidator();
    Set<ConstraintViolation<Object>> result = validator.validate(workflowDef);
    assertEquals(0, result.size());
}
Also used : WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) ValidatorFactory(javax.validation.ValidatorFactory) HashMap(java.util.HashMap) ConstraintViolation(javax.validation.ConstraintViolation) ArrayList(java.util.ArrayList) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Validator(javax.validation.Validator) Test(org.junit.Test)

Aggregations

WorkflowDef (com.netflix.conductor.common.metadata.workflow.WorkflowDef)246 Test (org.junit.Test)185 WorkflowTask (com.netflix.conductor.common.metadata.workflow.WorkflowTask)172 Workflow (com.netflix.conductor.common.run.Workflow)128 HashMap (java.util.HashMap)122 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)42 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 ApplicationException (com.netflix.conductor.core.execution.ApplicationException)13 ValidatorFactory (javax.validation.ValidatorFactory)13 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)12 DynamicForkJoinTaskList (com.netflix.conductor.common.metadata.workflow.DynamicForkJoinTaskList)12