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