Search in sources :

Example 21 with WorkflowDefinition

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());
}
Also used : Task(org.activiti.engine.task.Task) HashMap(java.util.HashMap) TaskService(org.activiti.engine.TaskService) WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) ProcessInstance(org.activiti.engine.runtime.ProcessInstance) Test(org.junit.Test)

Example 22 with WorkflowDefinition

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());
}
Also used : WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) ParallelStepsDefinition(org.activiti.workflow.simple.definition.ParallelStepsDefinition) ListStepDefinition(org.activiti.workflow.simple.definition.ListStepDefinition) ListConditionStepDefinition(org.activiti.workflow.simple.definition.ListConditionStepDefinition) StepDefinition(org.activiti.workflow.simple.definition.StepDefinition) HumanStepDefinition(org.activiti.workflow.simple.definition.HumanStepDefinition) OutputStreamWriter(java.io.OutputStreamWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) Test(org.junit.Test)

Example 23 with WorkflowDefinition

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());
}
Also used : ChoiceStepsDefinition(org.activiti.workflow.simple.definition.ChoiceStepsDefinition) WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) ListStepDefinition(org.activiti.workflow.simple.definition.ListStepDefinition) ListConditionStepDefinition(org.activiti.workflow.simple.definition.ListConditionStepDefinition) StepDefinition(org.activiti.workflow.simple.definition.StepDefinition) HumanStepDefinition(org.activiti.workflow.simple.definition.HumanStepDefinition) OutputStreamWriter(java.io.OutputStreamWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) Test(org.junit.Test)

Example 24 with WorkflowDefinition

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());
}
Also used : WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) OutputStreamWriter(java.io.OutputStreamWriter) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Writer(java.io.Writer) OutputStreamWriter(java.io.OutputStreamWriter) Test(org.junit.Test)

Example 25 with WorkflowDefinition

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());
}
Also used : Task(org.activiti.engine.task.Task) WorkflowDefinition(org.activiti.workflow.simple.definition.WorkflowDefinition) Test(org.junit.Test)

Aggregations

WorkflowDefinition (org.activiti.workflow.simple.definition.WorkflowDefinition)32 Test (org.junit.Test)24 WorkflowDefinitionConversion (org.activiti.workflow.simple.converter.WorkflowDefinitionConversion)16 HumanStepDefinition (org.activiti.workflow.simple.definition.HumanStepDefinition)10 Task (org.activiti.engine.task.Task)7 FormDefinition (org.activiti.workflow.simple.definition.form.FormDefinition)7 ByteArrayOutputStream (java.io.ByteArrayOutputStream)6 TaskService (org.activiti.engine.TaskService)6 OutputStreamWriter (java.io.OutputStreamWriter)5 Process (org.activiti.bpmn.model.Process)5 Writer (java.io.Writer)4 BpmnModel (org.activiti.bpmn.model.BpmnModel)4 FlowElement (org.activiti.bpmn.model.FlowElement)4 M2Model (org.activiti.workflow.simple.alfresco.model.M2Model)4 ListStepDefinition (org.activiti.workflow.simple.definition.ListStepDefinition)4 RepositoryService (org.activiti.engine.RepositoryService)3 ProcessInstance (org.activiti.engine.runtime.ProcessInstance)3 M2Type (org.activiti.workflow.simple.alfresco.model.M2Type)3 ListConditionStepDefinition (org.activiti.workflow.simple.definition.ListConditionStepDefinition)3 StepDefinition (org.activiti.workflow.simple.definition.StepDefinition)3