use of com.netflix.conductor.common.metadata.workflow.WorkflowDef in project conductor by Netflix.
the class WorkflowDefValidatorTest method testWorkflowDefConstraintsDualEnvVariable.
@Test
public void testWorkflowDefConstraintsDualEnvVariable() {
// name is null
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} ${NETFLIX_STACK}");
workflowTask_1.setInputParameters(inputParam);
List<WorkflowTask> tasks = new ArrayList<>();
tasks.add(workflowTask_1);
workflowDef.setTasks(tasks);
ValidatorFactory factory = Validation.buildDefaultValidatorFactory();
Validator validator = factory.getValidator();
Set<ConstraintViolation<Object>> result = validator.validate(workflowDef);
assertEquals(0, result.size());
}
use of com.netflix.conductor.common.metadata.workflow.WorkflowDef in project conductor by Netflix.
the class WorkflowDefValidatorTest method testWorkflowOwnerValidEmail.
@Test
public void testWorkflowOwnerValidEmail() {
WorkflowDef workflowDef = new WorkflowDef();
workflowDef.setName("test_env");
workflowDef.setOwnerEmail("owner@test.com");
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(0, result.size());
}
use of com.netflix.conductor.common.metadata.workflow.WorkflowDef in project conductor by Netflix.
the class SimpleTaskMapperTest method getMappedTasksException.
@Test
public void getMappedTasksException() throws Exception {
// Given
WorkflowTask taskToSchedule = new WorkflowTask();
taskToSchedule.setName("simple_task");
String taskId = IDGenerator.generate();
String retriedTaskId = IDGenerator.generate();
WorkflowDef wd = new WorkflowDef();
Workflow w = new Workflow();
w.setWorkflowDefinition(wd);
TaskMapperContext taskMapperContext = TaskMapperContext.newBuilder().withWorkflowDefinition(wd).withWorkflowInstance(w).withTaskDefinition(new TaskDef()).withTaskToSchedule(taskToSchedule).withTaskInput(new HashMap<>()).withRetryCount(0).withRetryTaskId(retriedTaskId).withTaskId(taskId).build();
// then
expectedException.expect(TerminateWorkflowException.class);
expectedException.expectMessage(String.format("Invalid task. Task %s does not have a definition", taskToSchedule.getName()));
// when
simpleTaskMapper.getMappedTasks(taskMapperContext);
}
use of com.netflix.conductor.common.metadata.workflow.WorkflowDef in project conductor by Netflix.
the class SubWorkflowTaskMapperTest method getMappedTasks.
@SuppressWarnings("unchecked")
@Test
public void getMappedTasks() {
// Given
WorkflowDef workflowDef = new WorkflowDef();
Workflow workflowInstance = new Workflow();
workflowInstance.setWorkflowDefinition(workflowDef);
WorkflowTask taskToSchedule = new WorkflowTask();
SubWorkflowParams subWorkflowParams = new SubWorkflowParams();
subWorkflowParams.setName("Foo");
subWorkflowParams.setVersion(2);
taskToSchedule.setSubWorkflowParam(subWorkflowParams);
Map<String, Object> taskInput = new HashMap<>();
Map<String, String> taskToDomain = new HashMap<String, String>() {
{
put("*", "unittest");
}
};
Map<String, Object> subWorkflowParamMap = new HashMap<>();
subWorkflowParamMap.put("name", "FooWorkFlow");
subWorkflowParamMap.put("version", 2);
subWorkflowParamMap.put("taskToDomain", taskToDomain);
when(parametersUtils.getTaskInputV2(anyMap(), any(Workflow.class), any(), any())).thenReturn(subWorkflowParamMap);
// When
TaskMapperContext taskMapperContext = TaskMapperContext.newBuilder().withWorkflowDefinition(workflowDef).withWorkflowInstance(workflowInstance).withTaskToSchedule(taskToSchedule).withTaskInput(taskInput).withRetryCount(0).withTaskId(IDGenerator.generate()).withDeciderService(deciderService).build();
List<Task> mappedTasks = subWorkflowTaskMapper.getMappedTasks(taskMapperContext);
// Then
assertTrue(!mappedTasks.isEmpty());
assertEquals(1, mappedTasks.size());
Task subWorkFlowTask = mappedTasks.get(0);
assertEquals(Task.Status.SCHEDULED, subWorkFlowTask.getStatus());
assertEquals(SubWorkflow.NAME, subWorkFlowTask.getTaskType());
assertEquals(taskToDomain, subWorkFlowTask.getInputData().get("subWorkflowTaskToDomain"));
}
use of com.netflix.conductor.common.metadata.workflow.WorkflowDef in project conductor by Netflix.
the class TerminateTaskMapperTest method getMappedTasks.
@Test
public void getMappedTasks() throws Exception {
WorkflowTask taskToSchedule = new WorkflowTask();
taskToSchedule.setType(TaskType.TASK_TYPE_TERMINATE);
String taskId = IDGenerator.generate();
WorkflowDef workflowDef = new WorkflowDef();
Workflow workflow = new Workflow();
workflow.setWorkflowDefinition(workflowDef);
TaskMapperContext taskMapperContext = TaskMapperContext.newBuilder().withWorkflowDefinition(workflowDef).withWorkflowInstance(workflow).withTaskDefinition(new TaskDef()).withTaskToSchedule(taskToSchedule).withRetryCount(0).withTaskId(taskId).build();
List<Task> mappedTasks = new TerminateTaskMapper(parametersUtils).getMappedTasks(taskMapperContext);
Assert.assertNotNull(mappedTasks);
Assert.assertEquals(1, mappedTasks.size());
Assert.assertEquals(TaskType.TASK_TYPE_TERMINATE, mappedTasks.get(0).getTaskType());
}
Aggregations