use of org.activiti.workflow.simple.definition.WorkflowDefinition in project Activiti by Activiti.
the class WorkflowConversionTest method testUserTasksInChoice.
@Test
public void testUserTasksInChoice() throws Exception {
TaskService taskService = activitiRule.getTaskService();
WorkflowDefinition workflowDefinition = new WorkflowDefinition().name("testWorkflow").description("This is a test workflow").inChoice().inList().addCondition("test", "==", "'hello'").addHumanStep("first task", "kermit").addHumanStep("second task", "kermit").endList().inList().addHumanStep("gonzo task", "gonzo").endList().endChoice().addHumanStep("last task", "kermit");
// Validate
Map<String, Object> varMap = new HashMap<String, Object>();
varMap.put("test", "hello");
String definitionKey = convertAndDeploy(workflowDefinition);
ProcessInstance instance = activitiRule.getRuntimeService().startProcessInstanceByKey(definitionKey, varMap);
assertEquals(1, taskService.createTaskQuery().taskAssignee("kermit").count());
assertEquals(0, taskService.createTaskQuery().taskAssignee("gonzo").count());
Task task = taskService.createTaskQuery().singleResult();
assertEquals("first task", task.getName());
taskService.complete(task.getId());
task = taskService.createTaskQuery().singleResult();
assertEquals("second task", task.getName());
taskService.complete(task.getId());
task = taskService.createTaskQuery().singleResult();
assertEquals("last task", task.getName());
taskService.complete(task.getId());
assertEquals(0, activitiRule.getRuntimeService().createProcessInstanceQuery().processInstanceId(instance.getId()).count());
varMap = new HashMap<String, Object>();
varMap.put("test", "world");
instance = activitiRule.getRuntimeService().startProcessInstanceByKey(definitionKey, varMap);
assertEquals(0, taskService.createTaskQuery().taskAssignee("kermit").count());
assertEquals(1, taskService.createTaskQuery().taskAssignee("gonzo").count());
task = taskService.createTaskQuery().singleResult();
assertEquals("gonzo task", task.getName());
taskService.complete(task.getId());
task = taskService.createTaskQuery().singleResult();
assertEquals("last task", task.getName());
taskService.complete(task.getId());
assertEquals(0, activitiRule.getRuntimeService().createProcessInstanceQuery().processInstanceId(instance.getId()).count());
}
use of org.activiti.workflow.simple.definition.WorkflowDefinition in project Activiti by Activiti.
the class JsonConverterTest method testParallelConversion.
@Test
public void testParallelConversion() {
// Create definition
WorkflowDefinition workflowDefinition = new WorkflowDefinition().name("testWorkflow").description("This is a test workflow").inParallel().inList().addHumanStep("first task", "kermit").addHumanStep("second task", "kermit").endList().inList().addHumanStep("gonzo task", "gonzo").endList().endParallel();
// Write result to byte-array
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Writer writer = new OutputStreamWriter(baos);
converter.writeWorkflowDefinition(workflowDefinition, writer);
// Parse definition based on written JSON
WorkflowDefinition parsedDefinition = converter.readWorkflowDefinition(baos.toByteArray());
// Check if parsed definition matches the original one
assertEquals(workflowDefinition.getName(), parsedDefinition.getName());
assertEquals(workflowDefinition.getDescription(), parsedDefinition.getDescription());
ParallelStepsDefinition parallelDef = null;
for (StepDefinition step : parsedDefinition.getSteps()) {
if (step instanceof ParallelStepsDefinition) {
parallelDef = (ParallelStepsDefinition) step;
}
}
assertNotNull(parallelDef);
assertEquals(2, parallelDef.getStepList().size());
ListStepDefinition<ParallelStepsDefinition> listSteps = parallelDef.getStepList().get(0);
assertEquals(2, listSteps.getSteps().size());
listSteps = parallelDef.getStepList().get(1);
assertEquals(1, listSteps.getSteps().size());
}
use of org.activiti.workflow.simple.definition.WorkflowDefinition in project Activiti by Activiti.
the class JsonConverterTest method testChoiceConversion.
@Test
public void testChoiceConversion() {
// Create definition
WorkflowDefinition workflowDefinition = new WorkflowDefinition().name("testWorkflow").description("This is a test workflow").inChoice().inList().addCondition("test", "==", "'hello'").addCondition("test2", "==", "'world'").addHumanStep("first task", "kermit").endList().inList().addHumanStep("gonzo task", "gonzo").endList().endChoice();
// Write result to byte-array
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Writer writer = new OutputStreamWriter(baos);
converter.writeWorkflowDefinition(workflowDefinition, writer);
// Parse definition based on written JSON
WorkflowDefinition parsedDefinition = converter.readWorkflowDefinition(baos.toByteArray());
// Check if parsed definition matches the original one
assertEquals(workflowDefinition.getName(), parsedDefinition.getName());
assertEquals(workflowDefinition.getDescription(), parsedDefinition.getDescription());
ChoiceStepsDefinition choiceDef = null;
for (StepDefinition step : parsedDefinition.getSteps()) {
if (step instanceof ChoiceStepsDefinition) {
choiceDef = (ChoiceStepsDefinition) step;
}
}
assertNotNull(choiceDef);
assertEquals(2, choiceDef.getStepList().size());
ListConditionStepDefinition<ChoiceStepsDefinition> listSteps = choiceDef.getStepList().get(0);
assertEquals(2, listSteps.getConditions().size());
assertEquals("test", listSteps.getConditions().get(0).getLeftOperand());
assertEquals("==", listSteps.getConditions().get(0).getOperator());
assertEquals("'hello'", listSteps.getConditions().get(0).getRightOperand());
listSteps = choiceDef.getStepList().get(1);
assertEquals(0, listSteps.getConditions().size());
}
use of org.activiti.workflow.simple.definition.WorkflowDefinition in project Activiti by Activiti.
the class JsonConverterTest method testWorkflowDefinitionConversion.
@Test
public void testWorkflowDefinitionConversion() {
// Create definition
WorkflowDefinition workflowDefinition = new WorkflowDefinition().name("testWorkflow").description("This is a test workflow").id("the id").key("the key");
// Write result to byte-array
ByteArrayOutputStream baos = new ByteArrayOutputStream();
Writer writer = new OutputStreamWriter(baos);
converter.writeWorkflowDefinition(workflowDefinition, writer);
// Parse definition based on written JSON
WorkflowDefinition parsedDefinition = converter.readWorkflowDefinition(baos.toByteArray());
// Check if parsed definition matches the original one
assertEquals(workflowDefinition.getName(), parsedDefinition.getName());
assertEquals(workflowDefinition.getKey(), parsedDefinition.getKey());
assertEquals(workflowDefinition.getId(), parsedDefinition.getId());
assertEquals(workflowDefinition.getDescription(), parsedDefinition.getDescription());
}
use of org.activiti.workflow.simple.definition.WorkflowDefinition in project Activiti by Activiti.
the class WorkflowConversionTest method testFeedbackStepWithFixedUsersAllFeedbackProvided.
@Test
public void testFeedbackStepWithFixedUsersAllFeedbackProvided() {
WorkflowDefinition workflowDefinition = new WorkflowDefinition().name("testWorkflow").description("This is a test workflow").addFeedbackStep("Test feedback", "kermit", Arrays.asList("gonzo", "mispiggy", "fozzie"));
activitiRule.getRuntimeService().startProcessInstanceByKey(convertAndDeploy(workflowDefinition));
// First, a task should be assigned to kermit to select the people
assertEquals(1, taskService.createTaskQuery().count());
assertEquals(1, taskService.createTaskQuery().taskAssignee("kermit").count());
Task task = taskService.createTaskQuery().singleResult();
taskService.complete(task.getId());
// Four tasks should be available now
assertEquals(4, taskService.createTaskQuery().count());
assertEquals(1, taskService.createTaskQuery().taskAssignee("kermit").count());
assertEquals(1, taskService.createTaskQuery().taskAssignee("gonzo").count());
assertEquals(1, taskService.createTaskQuery().taskAssignee("mispiggy").count());
assertEquals(1, taskService.createTaskQuery().taskAssignee("fozzie").count());
// Completing the feedback tasks first should only leave the 'gather feedback' task for kermit open
for (Task feedbackTask : taskService.createTaskQuery().list()) {
if (!feedbackTask.getAssignee().equals("kermit")) {
activitiRule.getTaskService().complete(feedbackTask.getId());
}
}
assertEquals(1, taskService.createTaskQuery().count());
assertEquals(1, taskService.createTaskQuery().taskAssignee("kermit").count());
// Completing this last task should finish the process
activitiRule.getTaskService().complete(activitiRule.getTaskService().createTaskQuery().singleResult().getId());
assertEquals(0, activitiRule.getRuntimeService().createProcessInstanceQuery().count());
}
Aggregations