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);
}
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);
}
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());
}
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"));
}
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"));
}
Aggregations