Search in sources :

Example 6 with StepDefinition

use of org.activiti.workflow.simple.definition.StepDefinition 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 7 with StepDefinition

use of org.activiti.workflow.simple.definition.StepDefinition 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)

Aggregations

StepDefinition (org.activiti.workflow.simple.definition.StepDefinition)7 HumanStepDefinition (org.activiti.workflow.simple.definition.HumanStepDefinition)5 ListConditionStepDefinition (org.activiti.workflow.simple.definition.ListConditionStepDefinition)5 ListStepDefinition (org.activiti.workflow.simple.definition.ListStepDefinition)5 ByteArrayOutputStream (java.io.ByteArrayOutputStream)3 OutputStreamWriter (java.io.OutputStreamWriter)3 Writer (java.io.Writer)3 FlowElement (org.activiti.bpmn.model.FlowElement)3 ChoiceStepsDefinition (org.activiti.workflow.simple.definition.ChoiceStepsDefinition)3 WorkflowDefinition (org.activiti.workflow.simple.definition.WorkflowDefinition)3 Test (org.junit.Test)3 ArrayList (java.util.ArrayList)2 WorkflowDefinitionConversionFactory (org.activiti.workflow.simple.converter.WorkflowDefinitionConversionFactory)2 ConditionDefinition (org.activiti.workflow.simple.definition.ConditionDefinition)2 ParallelStepsDefinition (org.activiti.workflow.simple.definition.ParallelStepsDefinition)2 FormDefinition (org.activiti.workflow.simple.definition.form.FormDefinition)2 EndEvent (org.activiti.bpmn.model.EndEvent)1 ExclusiveGateway (org.activiti.bpmn.model.ExclusiveGateway)1 MultiInstanceLoopCharacteristics (org.activiti.bpmn.model.MultiInstanceLoopCharacteristics)1 ParallelGateway (org.activiti.bpmn.model.ParallelGateway)1