Search in sources :

Example 6 with WorkflowTask

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

the class ConstraintParamUtilTest method testExtractParamPathComponentsWithInvalidEnv.

@Test
public void testExtractParamPathComponentsWithInvalidEnv() {
    WorkflowDef workflowDef = constructWorkflowDef();
    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}  ${workflow.input.status}");
    Map<String, Object> envInputParam = new HashMap<>();
    envInputParam.put("packageId", "${workflow.input.packageId}");
    envInputParam.put("taskId", "${CPEWF_TASK_ID}");
    envInputParam.put("TEST_ENV1", "${TEST_ENV1}");
    inputParam.put("env", envInputParam);
    workflowTask_1.setInputParameters(inputParam);
    List<WorkflowTask> tasks = new ArrayList<>();
    tasks.add(workflowTask_1);
    workflowDef.setTasks(tasks);
    List<String> results = ConstraintParamUtil.validateInputParam(inputParam, "task_1", workflowDef);
    assertEquals(results.size(), 1);
}
Also used : WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Test(org.junit.Test)

Example 7 with WorkflowTask

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

the class ConstraintParamUtilTest method testExtractParamPathComponentsWithMissingEnvVariable.

@Test
public void testExtractParamPathComponentsWithMissingEnvVariable() {
    WorkflowDef workflowDef = constructWorkflowDef();
    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} ${NETFLIX_STACK}");
    workflowTask_1.setInputParameters(inputParam);
    List<WorkflowTask> tasks = new ArrayList<>();
    tasks.add(workflowTask_1);
    workflowDef.setTasks(tasks);
    List<String> results = ConstraintParamUtil.validateInputParam(inputParam, "task_1", workflowDef);
    assertEquals(results.size(), 0);
}
Also used : WorkflowDef(com.netflix.conductor.common.metadata.workflow.WorkflowDef) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) WorkflowTask(com.netflix.conductor.common.metadata.workflow.WorkflowTask) Test(org.junit.Test)

Example 8 with WorkflowTask

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

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

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

Aggregations

WorkflowTask (com.netflix.conductor.common.metadata.workflow.WorkflowTask)240 Test (org.junit.Test)166 WorkflowDef (com.netflix.conductor.common.metadata.workflow.WorkflowDef)147 TaskDef (com.netflix.conductor.common.metadata.tasks.TaskDef)106 Workflow (com.netflix.conductor.common.run.Workflow)106 HashMap (java.util.HashMap)102 Task (com.netflix.conductor.common.metadata.tasks.Task)98 ArrayList (java.util.ArrayList)51 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)44 ConstraintViolation (javax.validation.ConstraintViolation)41 LinkedList (java.util.LinkedList)40 List (java.util.List)33 SubWorkflow (com.netflix.conductor.core.execution.tasks.SubWorkflow)32 Map (java.util.Map)25 SubWorkflowParams (com.netflix.conductor.common.metadata.workflow.SubWorkflowParams)24 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