ProcessBuilder extends AbstractProcessBuilder<ProcessBuilder> { public StartEventBuilder startEvent() { return startEvent(null); } ProcessBuilder(final BpmnModelInstance modelInstance, final Process process); StartEventBuilder startEvent(); StartEventBuilder startEvent(final String id); EventSubProcessBuilder eventSubProcess(); EventSubProcessBuilder eventSubProcess(final String id); ProcessBuilder eventSubProcess(
      final String id, final Consumer<EventSubProcessBuilder> consumer);  }
@Test public void testCreateProcessWithStartEvent() { modelInstance = Bpmn.createProcess().startEvent().done(); assertThat(modelInstance.getModelElementsByType(eventType)).hasSize(1); }
@Test public void testCreateProcessWithEndEvent() { modelInstance = Bpmn.createProcess().startEvent().endEvent().done(); assertThat(modelInstance.getModelElementsByType(eventType)).hasSize(2); }
@Test public void testCreateProcessWithServiceTask() { modelInstance = Bpmn.createProcess().startEvent().serviceTask().endEvent().done(); assertThat(modelInstance.getModelElementsByType(eventType)).hasSize(2); assertThat(modelInstance.getModelElementsByType(taskType)).hasSize(1); }
@Test public void testCreateProcessWithSendTask() { modelInstance = Bpmn.createProcess().startEvent().sendTask().endEvent().done(); assertThat(modelInstance.getModelElementsByType(eventType)).hasSize(2); assertThat(modelInstance.getModelElementsByType(taskType)).hasSize(1); }
@Test public void testCreateProcessWithUserTask() { modelInstance = Bpmn.createProcess().startEvent().userTask().endEvent().done(); assertThat(modelInstance.getModelElementsByType(eventType)).hasSize(2); assertThat(modelInstance.getModelElementsByType(taskType)).hasSize(1); }
@Test public void testCreateProcessWithBusinessRuleTask() { modelInstance = Bpmn.createProcess().startEvent().businessRuleTask().endEvent().done(); assertThat(modelInstance.getModelElementsByType(eventType)).hasSize(2); assertThat(modelInstance.getModelElementsByType(taskType)).hasSize(1); }
@Test public void testCreateProcessWithScriptTask() { modelInstance = Bpmn.createProcess().startEvent().scriptTask().endEvent().done(); assertThat(modelInstance.getModelElementsByType(eventType)).hasSize(2); assertThat(modelInstance.getModelElementsByType(taskType)).hasSize(1); }
@Test public void testCreateProcessWithReceiveTask() { modelInstance = Bpmn.createProcess().startEvent().receiveTask().endEvent().done(); assertThat(modelInstance.getModelElementsByType(eventType)).hasSize(2); assertThat(modelInstance.getModelElementsByType(taskType)).hasSize(1); }
@Test public void testCreateProcessWithManualTask() { modelInstance = Bpmn.createProcess().startEvent().manualTask().endEvent().done(); assertThat(modelInstance.getModelElementsByType(eventType)).hasSize(2); assertThat(modelInstance.getModelElementsByType(taskType)).hasSize(1); }
@Test public void testCreateProcessWithParallelGateway() { modelInstance = Bpmn.createProcess() .startEvent() .parallelGateway() .scriptTask() .endEvent() .moveToLastGateway() .userTask() .endEvent() .done(); assertThat(modelInstance.getModelElementsByType(eventType)).hasSize(3); assertThat(modelInstance.getModelElementsByType(taskType)).hasSize(2); assertThat(modelInstance.getModelElementsByType(gatewayType)).hasSize(1); }
@Test public void testCreateProcessWithExclusiveGateway() { modelInstance = Bpmn.createProcess() .startEvent() .userTask() .exclusiveGateway() .condition("approved", "${approved}") .serviceTask() .endEvent() .moveToLastGateway() .condition("not approved", "${!approved}") .scriptTask() .endEvent() .done(); assertThat(modelInstance.getModelElementsByType(eventType)).hasSize(3); assertThat(modelInstance.getModelElementsByType(taskType)).hasSize(3); assertThat(modelInstance.getModelElementsByType(gatewayType)).hasSize(1); }
@Test public void testCreateProcessWithInclusiveGateway() { modelInstance = Bpmn.createProcess() .startEvent() .userTask() .inclusiveGateway() .condition("approved", "${approved}") .serviceTask() .endEvent() .moveToLastGateway() .condition("not approved", "${!approved}") .scriptTask() .endEvent() .done(); final ModelElementType inclusiveGwType = modelInstance.getModel().getType(InclusiveGateway.class); assertThat(modelInstance.getModelElementsByType(eventType)).hasSize(3); assertThat(modelInstance.getModelElementsByType(taskType)).hasSize(3); assertThat(modelInstance.getModelElementsByType(inclusiveGwType)).hasSize(1); }
@Test public void testCreateProcessWithForkAndJoin() { modelInstance = Bpmn.createProcess() .startEvent() .userTask() .parallelGateway() .serviceTask() .parallelGateway() .id("join") .moveToLastGateway() .scriptTask() .connectTo("join") .userTask() .endEvent() .done(); assertThat(modelInstance.getModelElementsByType(eventType)).hasSize(2); assertThat(modelInstance.getModelElementsByType(taskType)).hasSize(4); assertThat(modelInstance.getModelElementsByType(gatewayType)).hasSize(2); }
@Test public void testCreateProcessWithMultipleParallelTask() { modelInstance = Bpmn.createProcess() .startEvent() .parallelGateway("fork") .userTask() .parallelGateway("join") .moveToNode("fork") .serviceTask() .connectTo("join") .moveToNode("fork") .userTask() .connectTo("join") .moveToNode("fork") .scriptTask() .connectTo("join") .endEvent() .done(); assertThat(modelInstance.getModelElementsByType(eventType)).hasSize(2); assertThat(modelInstance.getModelElementsByType(taskType)).hasSize(4); assertThat(modelInstance.getModelElementsByType(gatewayType)).hasSize(2); }
@Test public void testExtend() { modelInstance = Bpmn.createProcess().startEvent().userTask().id("task1").serviceTask().endEvent().done(); assertThat(modelInstance.getModelElementsByType(taskType)).hasSize(2); final UserTask userTask = modelInstance.getModelElementById("task1"); final SequenceFlow outgoingSequenceFlow = userTask.getOutgoing().iterator().next(); final FlowNode serviceTask = outgoingSequenceFlow.getTarget(); userTask.getOutgoing().remove(outgoingSequenceFlow); userTask.builder().scriptTask().userTask().connectTo(serviceTask.getId()); assertThat(modelInstance.getModelElementsByType(taskType)).hasSize(4); }
@Test public void testCreateInvoiceProcess() { modelInstance = Bpmn.createProcess() .executable() .startEvent() .name("Invoice received") .userTask() .name("Assign Approver") .userTask("approveInvoice") .name("Approve Invoice") .exclusiveGateway() .name("Invoice approved?") .gatewayDirection(GatewayDirection.Diverging) .condition("yes", "${approved}") .userTask() .name("Prepare Bank Transfer") .serviceTask() .name("Archive Invoice") .endEvent() .name("Invoice processed") .moveToLastGateway() .condition("no", "${!approved}") .userTask() .name("Review Invoice") .exclusiveGateway() .name("Review successful?") .gatewayDirection(GatewayDirection.Diverging) .condition("no", "${!clarified}") .endEvent() .name("Invoice not processed") .moveToLastGateway() .condition("yes", "${clarified}") .connectTo("approveInvoice") .done(); }
@Test public void testErrorDefinitionsForStartEvent() { modelInstance = Bpmn.createProcess() .startEvent("start") .errorEventDefinition("event") .error("errorCode") .errorEventDefinitionDone() .endEvent() .done(); assertErrorEventDefinition("start", "errorCode"); assertErrorEventDefinitionForErrorVariables("start"); }
@Test public void testErrorDefinitionsForStartEventWithoutEventDefinitionId() { modelInstance = Bpmn.createProcess() .startEvent("start") .errorEventDefinition() .error("errorCode") .errorEventDefinitionDone() .endEvent() .done(); assertErrorEventDefinition("start", "errorCode"); assertErrorEventDefinitionForErrorVariables("start"); }
@Test public void testSubProcessBuilder() { final BpmnModelInstance modelInstance = Bpmn.createProcess() .startEvent() .subProcess(SUB_PROCESS_ID) .embeddedSubProcess() .startEvent() .userTask() .endEvent() .subProcessDone() .serviceTask(SERVICE_TASK_ID) .endEvent() .done(); final SubProcess subProcess = modelInstance.getModelElementById(SUB_PROCESS_ID); final ServiceTask serviceTask = modelInstance.getModelElementById(SERVICE_TASK_ID); assertThat(subProcess.getChildElementsByType(Event.class)).hasSize(2); assertThat(subProcess.getChildElementsByType(Task.class)).hasSize(1); assertThat(subProcess.getFlowElements()).hasSize(5); assertThat(subProcess.getSucceedingNodes().singleResult()).isEqualTo(serviceTask); }
@Test public void testSubProcessBuilderDetached() { modelInstance = Bpmn.createProcess() .startEvent() .subProcess(SUB_PROCESS_ID) .serviceTask(SERVICE_TASK_ID) .endEvent() .done(); final SubProcess subProcess = modelInstance.getModelElementById(SUB_PROCESS_ID); subProcess.builder().embeddedSubProcess().startEvent().userTask().endEvent(); final ServiceTask serviceTask = modelInstance.getModelElementById(SERVICE_TASK_ID); assertThat(subProcess.getChildElementsByType(Event.class)).hasSize(2); assertThat(subProcess.getChildElementsByType(Task.class)).hasSize(1); assertThat(subProcess.getFlowElements()).hasSize(5); assertThat(subProcess.getSucceedingNodes().singleResult()).isEqualTo(serviceTask); }
@Test public void testSubProcessBuilderNested() { modelInstance = Bpmn.createProcess() .startEvent() .subProcess(SUB_PROCESS_ID + 1) .embeddedSubProcess() .startEvent() .userTask() .subProcess(SUB_PROCESS_ID + 2) .embeddedSubProcess() .startEvent() .userTask() .endEvent() .subProcessDone() .serviceTask(SERVICE_TASK_ID + 1) .endEvent() .subProcessDone() .serviceTask(SERVICE_TASK_ID + 2) .endEvent() .done(); final SubProcess subProcess = modelInstance.getModelElementById(SUB_PROCESS_ID + 1); final ServiceTask serviceTask = modelInstance.getModelElementById(SERVICE_TASK_ID + 2); assertThat(subProcess.getChildElementsByType(Event.class)).hasSize(2); assertThat(subProcess.getChildElementsByType(Task.class)).hasSize(2); assertThat(subProcess.getChildElementsByType(SubProcess.class)).hasSize(1); assertThat(subProcess.getFlowElements()).hasSize(9); assertThat(subProcess.getSucceedingNodes().singleResult()).isEqualTo(serviceTask); final SubProcess nestedSubProcess = modelInstance.getModelElementById(SUB_PROCESS_ID + 2); final ServiceTask nestedServiceTask = modelInstance.getModelElementById(SERVICE_TASK_ID + 1); assertThat(nestedSubProcess.getChildElementsByType(Event.class)).hasSize(2); assertThat(nestedSubProcess.getChildElementsByType(Task.class)).hasSize(1); assertThat(nestedSubProcess.getFlowElements()).hasSize(5); assertThat(nestedSubProcess.getSucceedingNodes().singleResult()).isEqualTo(nestedServiceTask); }
@Test public void testSubProcessBuilderWrongScope() { try { modelInstance = Bpmn.createProcess().startEvent().subProcessDone().endEvent().done(); fail("Exception expected"); } catch (final Exception e) { assertThat(e).isInstanceOf(BpmnModelException.class); } }
@Test public void testTransactionBuilder() { final BpmnModelInstance modelInstance = Bpmn.createProcess() .startEvent() .transaction(TRANSACTION_ID) .method(TransactionMethod.Image) .embeddedSubProcess() .startEvent() .userTask() .endEvent() .transactionDone() .serviceTask(SERVICE_TASK_ID) .endEvent() .done(); final Transaction transaction = modelInstance.getModelElementById(TRANSACTION_ID); final ServiceTask serviceTask = modelInstance.getModelElementById(SERVICE_TASK_ID); assertThat(transaction.getMethod()).isEqualTo(TransactionMethod.Image); assertThat(transaction.getChildElementsByType(Event.class)).hasSize(2); assertThat(transaction.getChildElementsByType(Task.class)).hasSize(1); assertThat(transaction.getFlowElements()).hasSize(5); assertThat(transaction.getSucceedingNodes().singleResult()).isEqualTo(serviceTask); }
@Test public void testTransactionBuilderDetached() { modelInstance = Bpmn.createProcess() .startEvent() .transaction(TRANSACTION_ID) .serviceTask(SERVICE_TASK_ID) .endEvent() .done(); final Transaction transaction = modelInstance.getModelElementById(TRANSACTION_ID); transaction.builder().embeddedSubProcess().startEvent().userTask().endEvent(); final ServiceTask serviceTask = modelInstance.getModelElementById(SERVICE_TASK_ID); assertThat(transaction.getChildElementsByType(Event.class)).hasSize(2); assertThat(transaction.getChildElementsByType(Task.class)).hasSize(1); assertThat(transaction.getFlowElements()).hasSize(5); assertThat(transaction.getSucceedingNodes().singleResult()).isEqualTo(serviceTask); }
@Test public void testScriptText() { modelInstance = Bpmn.createProcess() .startEvent() .scriptTask("script") .scriptFormat("groovy") .scriptText("println \"hello, world\";") .endEvent() .done(); final ScriptTask scriptTask = modelInstance.getModelElementById("script"); assertThat(scriptTask.getScriptFormat()).isEqualTo("groovy"); assertThat(scriptTask.getScript().getTextContent()).isEqualTo("println \"hello, world\";"); }
@Test public void testMessageStartEvent() { modelInstance = Bpmn.createProcess().startEvent("start").message("message").done(); assertMessageEventDefinition("start", "message"); }
@Test public void testMessageStartEventWithExistingMessage() { modelInstance = Bpmn.createProcess() .startEvent("start") .message("message") .subProcess() .triggerByEvent() .embeddedSubProcess() .startEvent("subStart") .message("message") .subProcessDone() .done(); final Message message = assertMessageEventDefinition("start", "message"); final Message subMessage = assertMessageEventDefinition("subStart", "message"); assertThat(message).isEqualTo(subMessage); assertOnlyOneMessageExists("message"); }
@Test public void testIntermediateMessageCatchEvent() { modelInstance = Bpmn.createProcess().startEvent().intermediateCatchEvent("catch").message("message").done(); assertMessageEventDefinition("catch", "message"); }
@Test public void testIntermediateMessageCatchEventWithExistingMessage() { modelInstance = Bpmn.createProcess() .startEvent() .intermediateCatchEvent("catch1") .message("message") .intermediateCatchEvent("catch2") .message("message") .done(); final Message message1 = assertMessageEventDefinition("catch1", "message"); final Message message2 = assertMessageEventDefinition("catch2", "message"); assertThat(message1).isEqualTo(message2); assertOnlyOneMessageExists("message"); }
@Test public void testMessageEndEvent() { modelInstance = Bpmn.createProcess().startEvent().endEvent("end").message("message").done(); assertMessageEventDefinition("end", "message"); }
@Test public void testMessageEventDefintionEndEvent() { modelInstance = Bpmn.createProcess() .startEvent() .endEvent("end") .messageEventDefinition() .message("message") .done(); assertMessageEventDefinition("end", "message"); }
@Test public void testMessageEndEventWithExistingMessage() { modelInstance = Bpmn.createProcess() .startEvent() .parallelGateway() .endEvent("end1") .message("message") .moveToLastGateway() .endEvent("end2") .message("message") .done(); final Message message1 = assertMessageEventDefinition("end1", "message"); final Message message2 = assertMessageEventDefinition("end2", "message"); assertThat(message1).isEqualTo(message2); assertOnlyOneMessageExists("message"); }
@Test public void testMessageEventDefinitionEndEventWithExistingMessage() { modelInstance = Bpmn.createProcess() .startEvent() .parallelGateway() .endEvent("end1") .messageEventDefinition() .message("message") .messageEventDefinitionDone() .moveToLastGateway() .endEvent("end2") .messageEventDefinition() .message("message") .done(); final Message message1 = assertMessageEventDefinition("end1", "message"); final Message message2 = assertMessageEventDefinition("end2", "message"); assertThat(message1).isEqualTo(message2); assertOnlyOneMessageExists("message"); }
@Test public void testIntermediateMessageThrowEvent() { modelInstance = Bpmn.createProcess().startEvent().intermediateThrowEvent("throw").message("message").done(); assertMessageEventDefinition("throw", "message"); }
@Test public void testIntermediateMessageEventDefintionThrowEvent() { modelInstance = Bpmn.createProcess() .startEvent() .intermediateThrowEvent("throw") .messageEventDefinition() .message("message") .done(); assertMessageEventDefinition("throw", "message"); }
@Test public void testIntermediateMessageThrowEventWithExistingMessage() { modelInstance = Bpmn.createProcess() .startEvent() .intermediateThrowEvent("throw1") .message("message") .intermediateThrowEvent("throw2") .message("message") .done(); final Message message1 = assertMessageEventDefinition("throw1", "message"); final Message message2 = assertMessageEventDefinition("throw2", "message"); assertThat(message1).isEqualTo(message2); assertOnlyOneMessageExists("message"); }
@Test public void testIntermediateMessageEventDefintionThrowEventWithExistingMessage() { modelInstance = Bpmn.createProcess() .startEvent() .intermediateThrowEvent("throw1") .messageEventDefinition() .message("message") .messageEventDefinitionDone() .intermediateThrowEvent("throw2") .messageEventDefinition() .message("message") .messageEventDefinitionDone() .done(); final Message message1 = assertMessageEventDefinition("throw1", "message"); final Message message2 = assertMessageEventDefinition("throw2", "message"); assertThat(message1).isEqualTo(message2); assertOnlyOneMessageExists("message"); }
@Test public void testIntermediateMessageThrowEventWithMessageDefinition() { modelInstance = Bpmn.createProcess() .startEvent() .intermediateThrowEvent("throw1") .messageEventDefinition() .id("messageEventDefinition") .message("message") .done(); final MessageEventDefinition event = modelInstance.getModelElementById("messageEventDefinition"); assertThat(event.getMessage().getName()).isEqualTo("message"); }
@Test public void testMessageEventDefinitionWithID() { modelInstance = Bpmn.createProcess() .startEvent() .intermediateThrowEvent("throw1") .messageEventDefinition("messageEventDefinition") .done(); MessageEventDefinition event = modelInstance.getModelElementById("messageEventDefinition"); assertThat(event).isNotNull(); modelInstance = Bpmn.createProcess() .startEvent() .intermediateThrowEvent("throw2") .messageEventDefinition() .id("messageEventDefinition1") .done(); event = modelInstance.getModelElementById("messageEventDefinition1"); assertThat(event).isNotNull(); modelInstance = Bpmn.createProcess() .startEvent() .endEvent("end1") .messageEventDefinition("messageEventDefinition") .done(); event = modelInstance.getModelElementById("messageEventDefinition"); assertThat(event).isNotNull(); modelInstance = Bpmn.createProcess() .startEvent() .endEvent("end2") .messageEventDefinition() .id("messageEventDefinition1") .done(); event = modelInstance.getModelElementById("messageEventDefinition1"); assertThat(event).isNotNull(); }
@Test public void testReceiveTaskMessage() { modelInstance = Bpmn.createProcess().startEvent().receiveTask("receive").message("message").done(); final ReceiveTask receiveTask = modelInstance.getModelElementById("receive"); final Message message = receiveTask.getMessage(); assertThat(message).isNotNull(); assertThat(message.getName()).isEqualTo("message"); }
@Test public void testReceiveTaskWithExistingMessage() { modelInstance = Bpmn.createProcess() .startEvent() .receiveTask("receive1") .message("message") .receiveTask("receive2") .message("message") .done(); final ReceiveTask receiveTask1 = modelInstance.getModelElementById("receive1"); final Message message1 = receiveTask1.getMessage(); final ReceiveTask receiveTask2 = modelInstance.getModelElementById("receive2"); final Message message2 = receiveTask2.getMessage(); assertThat(message1).isEqualTo(message2); assertOnlyOneMessageExists("message"); }
@Test public void testSendTaskMessage() { modelInstance = Bpmn.createProcess().startEvent().sendTask("send").message("message").done(); final SendTask sendTask = modelInstance.getModelElementById("send"); final Message message = sendTask.getMessage(); assertThat(message).isNotNull(); assertThat(message.getName()).isEqualTo("message"); }
@Test public void testSendTaskWithExistingMessage() { modelInstance = Bpmn.createProcess() .startEvent() .sendTask("send1") .message("message") .sendTask("send2") .message("message") .done(); final SendTask sendTask1 = modelInstance.getModelElementById("send1"); final Message message1 = sendTask1.getMessage(); final SendTask sendTask2 = modelInstance.getModelElementById("send2"); final Message message2 = sendTask2.getMessage(); assertThat(message1).isEqualTo(message2); assertOnlyOneMessageExists("message"); }
@Test public void testSignalStartEvent() { modelInstance = Bpmn.createProcess().startEvent("start").signal("signal").done(); assertSignalEventDefinition("start", "signal"); }
@Test public void testSignalStartEventWithExistingSignal() { modelInstance = Bpmn.createProcess() .startEvent("start") .signal("signal") .subProcess() .triggerByEvent() .embeddedSubProcess() .startEvent("subStart") .signal("signal") .subProcessDone() .done(); final Signal signal = assertSignalEventDefinition("start", "signal"); final Signal subSignal = assertSignalEventDefinition("subStart", "signal"); assertThat(signal).isEqualTo(subSignal); assertOnlyOneSignalExists("signal"); }
@Test public void testIntermediateSignalCatchEvent() { modelInstance = Bpmn.createProcess().startEvent().intermediateCatchEvent("catch").signal("signal").done(); assertSignalEventDefinition("catch", "signal"); }
@Test public void testIntermediateSignalCatchEventWithExistingSignal() { modelInstance = Bpmn.createProcess() .startEvent() .intermediateCatchEvent("catch1") .signal("signal") .intermediateCatchEvent("catch2") .signal("signal") .done(); final Signal signal1 = assertSignalEventDefinition("catch1", "signal"); final Signal signal2 = assertSignalEventDefinition("catch2", "signal"); assertThat(signal1).isEqualTo(signal2); assertOnlyOneSignalExists("signal"); }
@Test public void testSignalEndEvent() { modelInstance = Bpmn.createProcess().startEvent().endEvent("end").signal("signal").done(); assertSignalEventDefinition("end", "signal"); }
@Test public void testSignalEndEventWithExistingSignal() { modelInstance = Bpmn.createProcess() .startEvent() .parallelGateway() .endEvent("end1") .signal("signal") .moveToLastGateway() .endEvent("end2") .signal("signal") .done(); final Signal signal1 = assertSignalEventDefinition("end1", "signal"); final Signal signal2 = assertSignalEventDefinition("end2", "signal"); assertThat(signal1).isEqualTo(signal2); assertOnlyOneSignalExists("signal"); }
@Test public void testIntermediateSignalThrowEvent() { modelInstance = Bpmn.createProcess().startEvent().intermediateThrowEvent("throw").signal("signal").done(); assertSignalEventDefinition("throw", "signal"); }
@Test public void testIntermediateSignalThrowEventWithExistingSignal() { modelInstance = Bpmn.createProcess() .startEvent() .intermediateThrowEvent("throw1") .signal("signal") .intermediateThrowEvent("throw2") .signal("signal") .done(); final Signal signal1 = assertSignalEventDefinition("throw1", "signal"); final Signal signal2 = assertSignalEventDefinition("throw2", "signal"); assertThat(signal1).isEqualTo(signal2); assertOnlyOneSignalExists("signal"); }
@Test public void testMessageBoundaryEvent() { modelInstance = Bpmn.createProcess() .startEvent() .userTask("task") .endEvent() .moveToActivity("task") .boundaryEvent("boundary") .message("message") .endEvent("boundaryEnd") .done(); assertMessageEventDefinition("boundary", "message"); final UserTask userTask = modelInstance.getModelElementById("task"); final BoundaryEvent boundaryEvent = modelInstance.getModelElementById("boundary"); final EndEvent boundaryEnd = modelInstance.getModelElementById("boundaryEnd"); assertThat(boundaryEvent.getAttachedTo()).isEqualTo(userTask); assertThat(boundaryEvent.getIncoming()).isEmpty(); final List<FlowNode> succeedingNodes = boundaryEvent.getSucceedingNodes().list(); assertThat(succeedingNodes).containsOnly(boundaryEnd); }
@Test public void testMultipleBoundaryEvents() { modelInstance = Bpmn.createProcess() .startEvent() .userTask("task") .endEvent() .moveToActivity("task") .boundaryEvent("boundary1") .message("message") .endEvent("boundaryEnd1") .moveToActivity("task") .boundaryEvent("boundary2") .signal("signal") .endEvent("boundaryEnd2") .done(); assertMessageEventDefinition("boundary1", "message"); assertSignalEventDefinition("boundary2", "signal"); final UserTask userTask = modelInstance.getModelElementById("task"); final BoundaryEvent boundaryEvent1 = modelInstance.getModelElementById("boundary1"); final EndEvent boundaryEnd1 = modelInstance.getModelElementById("boundaryEnd1"); final BoundaryEvent boundaryEvent2 = modelInstance.getModelElementById("boundary2"); final EndEvent boundaryEnd2 = modelInstance.getModelElementById("boundaryEnd2"); assertThat(boundaryEvent1.getAttachedTo()).isEqualTo(userTask); assertThat(boundaryEvent2.getAttachedTo()).isEqualTo(userTask); assertThat(boundaryEvent1.getIncoming()).isEmpty(); assertThat(boundaryEvent2.getIncoming()).isEmpty(); List<FlowNode> succeedingNodes = boundaryEvent1.getSucceedingNodes().list(); assertThat(succeedingNodes).containsOnly(boundaryEnd1); succeedingNodes = boundaryEvent2.getSucceedingNodes().list(); assertThat(succeedingNodes).containsOnly(boundaryEnd2); }
@Test public void testMultiInstanceLoopCharacteristicsSequential() { modelInstance = Bpmn.createProcess() .startEvent() .userTask("task") .multiInstance() .sequential() .cardinality("card") .completionCondition("compl") .multiInstanceDone() .endEvent() .done(); final UserTask userTask = modelInstance.getModelElementById("task"); final Collection<MultiInstanceLoopCharacteristics> miCharacteristics = userTask.getChildElementsByType(MultiInstanceLoopCharacteristics.class); assertThat(miCharacteristics).hasSize(1); final MultiInstanceLoopCharacteristics miCharacteristic = miCharacteristics.iterator().next(); assertThat(miCharacteristic.isSequential()).isTrue(); assertThat(miCharacteristic.getLoopCardinality().getTextContent()).isEqualTo("card"); assertThat(miCharacteristic.getCompletionCondition().getTextContent()).isEqualTo("compl"); }
@Test public void testMultiInstanceLoopCharacteristicsParallel() { modelInstance = Bpmn.createProcess() .startEvent() .userTask("task") .multiInstance() .parallel() .multiInstanceDone() .endEvent() .done(); final UserTask userTask = modelInstance.getModelElementById("task"); final Collection<MultiInstanceLoopCharacteristics> miCharacteristics = userTask.getChildElementsByType(MultiInstanceLoopCharacteristics.class); assertThat(miCharacteristics).hasSize(1); final MultiInstanceLoopCharacteristics miCharacteristic = miCharacteristics.iterator().next(); assertThat(miCharacteristic.isSequential()).isFalse(); }
@Test public void testTimerStartEventWithDate() { modelInstance = Bpmn.createProcess().startEvent("start").timerWithDate(TIMER_DATE).done(); assertTimerWithDate("start", TIMER_DATE); }
@Test public void testTimerStartEventWithDuration() { modelInstance = Bpmn.createProcess().startEvent("start").timerWithDuration(TIMER_DURATION).done(); assertTimerWithDuration("start", TIMER_DURATION); }
@Test public void testTimerStartEventWithCycle() { modelInstance = Bpmn.createProcess().startEvent("start").timerWithCycle(TIMER_CYCLE).done(); assertTimerWithCycle("start", TIMER_CYCLE); }
@Test public void testIntermediateTimerCatchEventWithDate() { modelInstance = Bpmn.createProcess() .startEvent() .intermediateCatchEvent("catch") .timerWithDate(TIMER_DATE) .done(); assertTimerWithDate("catch", TIMER_DATE); }
@Test public void testIntermediateTimerCatchEventWithDuration() { modelInstance = Bpmn.createProcess() .startEvent() .intermediateCatchEvent("catch") .timerWithDuration(TIMER_DURATION) .done(); assertTimerWithDuration("catch", TIMER_DURATION); }
@Test public void testIntermediateTimerCatchEventWithCycle() { modelInstance = Bpmn.createProcess() .startEvent() .intermediateCatchEvent("catch") .timerWithCycle(TIMER_CYCLE) .done(); assertTimerWithCycle("catch", TIMER_CYCLE); }
@Test public void testTimerBoundaryEventWithDate() { modelInstance = Bpmn.createProcess() .startEvent() .userTask("task") .endEvent() .moveToActivity("task") .boundaryEvent("boundary") .timerWithDate(TIMER_DATE) .done(); assertTimerWithDate("boundary", TIMER_DATE); }
@Test public void testTimerBoundaryEventWithDuration() { modelInstance = Bpmn.createProcess() .startEvent() .userTask("task") .endEvent() .moveToActivity("task") .boundaryEvent("boundary") .timerWithDuration(TIMER_DURATION) .done(); assertTimerWithDuration("boundary", TIMER_DURATION); }
@Test public void testTimerBoundaryEventWithCycle() { modelInstance = Bpmn.createProcess() .startEvent() .userTask("task") .endEvent() .moveToActivity("task") .boundaryEvent("boundary") .timerWithCycle(TIMER_CYCLE) .done(); assertTimerWithCycle("boundary", TIMER_CYCLE); }
@Test public void testNotCancelingBoundaryEvent() { modelInstance = Bpmn.createProcess() .startEvent() .userTask() .boundaryEvent("boundary") .cancelActivity(false) .done(); final BoundaryEvent boundaryEvent = modelInstance.getModelElementById("boundary"); assertThat(boundaryEvent.cancelActivity()).isFalse(); }
@Test public void testCatchAllErrorBoundaryEvent() { modelInstance = Bpmn.createProcess() .startEvent() .userTask("task") .endEvent() .moveToActivity("task") .boundaryEvent("boundary") .error() .endEvent("boundaryEnd") .done(); final ErrorEventDefinition errorEventDefinition = assertAndGetSingleEventDefinition("boundary", ErrorEventDefinition.class); assertThat(errorEventDefinition.getError()).isNull(); }
@Test public void testCompensationTask() { modelInstance = Bpmn.createProcess() .startEvent() .userTask("task") .boundaryEvent("boundary") .compensateEventDefinition() .compensateEventDefinitionDone() .compensationStart() .userTask("compensate") .name("compensate") .compensationDone() .endEvent("theend") .done(); final Collection<Association> associations = modelInstance.getModelElementsByType(Association.class); assertThat(associations).hasSize(1); final Association association = associations.iterator().next(); assertThat(association.getSource().getId()).isEqualTo("boundary"); assertThat(association.getTarget().getId()).isEqualTo("compensate"); assertThat(association.getAssociationDirection()).isEqualTo(AssociationDirection.One); final UserTask task = modelInstance.getModelElementById("task"); final Collection<SequenceFlow> outgoing = task.getOutgoing(); assertThat(outgoing).hasSize(1); final SequenceFlow flow = outgoing.iterator().next(); assertThat(flow.getSource().getId()).isEqualTo("task"); assertThat(flow.getTarget().getId()).isEqualTo("theend"); }
@Test public void testOnlyOneCompensateBoundaryEventAllowed() { final UserTaskBuilder builder = Bpmn.createProcess() .startEvent() .userTask("task") .boundaryEvent("boundary") .compensateEventDefinition() .compensateEventDefinitionDone() .compensationStart() .userTask("compensate") .name("compensate"); thrown.expect(BpmnModelException.class); thrown.expectMessage( "Only single compensation handler allowed. Call compensationDone() to continue main flow."); builder.userTask(); }
@Test public void testInvalidCompensationStartCall() { final StartEventBuilder builder = Bpmn.createProcess().startEvent(); thrown.expect(BpmnModelException.class); thrown.expectMessage( "Compensation can only be started on a boundary event with a compensation event definition"); builder.compensationStart(); }
@Test public void testInvalidCompensationDoneCall() { final AbstractFlowNodeBuilder builder = Bpmn.createProcess() .startEvent() .userTask("task") .boundaryEvent("boundary") .compensateEventDefinition() .compensateEventDefinitionDone(); thrown.expect(BpmnModelException.class); thrown.expectMessage("No compensation in progress. Call compensationStart() first."); builder.compensationDone(); }
@Test public void testErrorBoundaryEvent() { modelInstance = Bpmn.createProcess() .startEvent() .userTask("task") .endEvent() .moveToActivity("task") .boundaryEvent("boundary") .error("myErrorCode") .endEvent("boundaryEnd") .done(); assertErrorEventDefinition("boundary", "myErrorCode"); final UserTask userTask = modelInstance.getModelElementById("task"); final BoundaryEvent boundaryEvent = modelInstance.getModelElementById("boundary"); final EndEvent boundaryEnd = modelInstance.getModelElementById("boundaryEnd"); assertThat(boundaryEvent.getAttachedTo()).isEqualTo(userTask); assertThat(boundaryEvent.getIncoming()).isEmpty(); final List<FlowNode> succeedingNodes = boundaryEvent.getSucceedingNodes().list(); assertThat(succeedingNodes).containsOnly(boundaryEnd); }
@Test public void testErrorDefinitionForBoundaryEvent() { modelInstance = Bpmn.createProcess() .startEvent() .userTask("task") .endEvent() .moveToActivity("task") .boundaryEvent("boundary") .errorEventDefinition("event") .error("errorCode") .errorEventDefinitionDone() .endEvent("boundaryEnd") .done(); assertErrorEventDefinition("boundary", "errorCode"); assertErrorEventDefinitionForErrorVariables("boundary"); }
@Test public void testErrorDefinitionForBoundaryEventWithoutEventDefinitionId() { modelInstance = Bpmn.createProcess() .startEvent() .userTask("task") .endEvent() .moveToActivity("task") .boundaryEvent("boundary") .errorEventDefinition() .error("errorCode") .errorEventDefinitionDone() .endEvent("boundaryEnd") .done(); assertErrorEventDefinition("boundary", "errorCode"); assertErrorEventDefinitionForErrorVariables("boundary"); }
@Test public void testErrorEndEvent() { modelInstance = Bpmn.createProcess().startEvent().endEvent("end").error("myErrorCode").done(); assertErrorEventDefinition("end", "myErrorCode"); }
@Test public void testErrorEndEventWithExistingError() { modelInstance = Bpmn.createProcess() .startEvent() .userTask("task") .endEvent("end") .error("myErrorCode") .moveToActivity("task") .boundaryEvent("boundary") .error("myErrorCode") .endEvent("boundaryEnd") .done(); final Error boundaryError = assertErrorEventDefinition("boundary", "myErrorCode"); final Error endError = assertErrorEventDefinition("end", "myErrorCode"); assertThat(boundaryError).isEqualTo(endError); assertOnlyOneErrorExists("myErrorCode"); }
@Test public void testErrorStartEvent() { modelInstance = Bpmn.createProcess() .startEvent() .endEvent() .subProcess() .triggerByEvent() .embeddedSubProcess() .startEvent("subProcessStart") .error("myErrorCode") .endEvent() .done(); assertErrorEventDefinition("subProcessStart", "myErrorCode"); }
@Test public void testCatchAllErrorStartEvent() { modelInstance = Bpmn.createProcess() .startEvent() .endEvent() .subProcess() .triggerByEvent() .embeddedSubProcess() .startEvent("subProcessStart") .error() .endEvent() .done(); final ErrorEventDefinition errorEventDefinition = assertAndGetSingleEventDefinition("subProcessStart", ErrorEventDefinition.class); assertThat(errorEventDefinition.getError()).isNull(); }
@Test public void testCatchAllEscalationBoundaryEvent() { modelInstance = Bpmn.createProcess() .startEvent() .userTask("task") .endEvent() .moveToActivity("task") .boundaryEvent("boundary") .escalation() .endEvent("boundaryEnd") .done(); final EscalationEventDefinition escalationEventDefinition = assertAndGetSingleEventDefinition("boundary", EscalationEventDefinition.class); assertThat(escalationEventDefinition.getEscalation()).isNull(); }
@Test public void testEscalationBoundaryEvent() { modelInstance = Bpmn.createProcess() .startEvent() .subProcess("subProcess") .endEvent() .moveToActivity("subProcess") .boundaryEvent("boundary") .escalation("myEscalationCode") .endEvent("boundaryEnd") .done(); assertEscalationEventDefinition("boundary", "myEscalationCode"); final SubProcess subProcess = modelInstance.getModelElementById("subProcess"); final BoundaryEvent boundaryEvent = modelInstance.getModelElementById("boundary"); final EndEvent boundaryEnd = modelInstance.getModelElementById("boundaryEnd"); assertThat(boundaryEvent.getAttachedTo()).isEqualTo(subProcess); assertThat(boundaryEvent.getIncoming()).isEmpty(); final List<FlowNode> succeedingNodes = boundaryEvent.getSucceedingNodes().list(); assertThat(succeedingNodes).containsOnly(boundaryEnd); }
@Test public void testEscalationEndEvent() { modelInstance = Bpmn.createProcess().startEvent().endEvent("end").escalation("myEscalationCode").done(); assertEscalationEventDefinition("end", "myEscalationCode"); }
@Test public void testEscalationStartEvent() { modelInstance = Bpmn.createProcess() .startEvent() .endEvent() .subProcess() .triggerByEvent() .embeddedSubProcess() .startEvent("subProcessStart") .escalation("myEscalationCode") .endEvent() .done(); assertEscalationEventDefinition("subProcessStart", "myEscalationCode"); }
@Test public void testCatchAllEscalationStartEvent() { modelInstance = Bpmn.createProcess() .startEvent() .endEvent() .subProcess() .triggerByEvent() .embeddedSubProcess() .startEvent("subProcessStart") .escalation() .endEvent() .done(); final EscalationEventDefinition escalationEventDefinition = assertAndGetSingleEventDefinition("subProcessStart", EscalationEventDefinition.class); assertThat(escalationEventDefinition.getEscalation()).isNull(); }
@Test public void testIntermediateEscalationThrowEvent() { modelInstance = Bpmn.createProcess() .startEvent() .intermediateThrowEvent("throw") .escalation("myEscalationCode") .endEvent() .done(); assertEscalationEventDefinition("throw", "myEscalationCode"); }
@Test public void testEscalationEndEventWithExistingEscalation() { modelInstance = Bpmn.createProcess() .startEvent() .userTask("task") .endEvent("end") .escalation("myEscalationCode") .moveToActivity("task") .boundaryEvent("boundary") .escalation("myEscalationCode") .endEvent("boundaryEnd") .done(); final Escalation boundaryEscalation = assertEscalationEventDefinition("boundary", "myEscalationCode"); final Escalation endEscalation = assertEscalationEventDefinition("end", "myEscalationCode"); assertThat(boundaryEscalation).isEqualTo(endEscalation); assertOnlyOneEscalationExists("myEscalationCode"); }
@Test public void testCompensationStartEvent() { modelInstance = Bpmn.createProcess() .startEvent() .endEvent() .subProcess() .triggerByEvent() .embeddedSubProcess() .startEvent("subProcessStart") .compensation() .endEvent() .done(); assertCompensationEventDefinition("subProcessStart"); }
@Test public void testInterruptingStartEvent() { modelInstance = Bpmn.createProcess() .startEvent() .endEvent() .subProcess() .triggerByEvent() .embeddedSubProcess() .startEvent("subProcessStart") .interrupting(true) .error() .endEvent() .done(); final StartEvent startEvent = modelInstance.getModelElementById("subProcessStart"); assertThat(startEvent).isNotNull(); assertThat(startEvent.isInterrupting()).isTrue(); }
@Test public void testNonInterruptingStartEvent() { modelInstance = Bpmn.createProcess() .startEvent() .endEvent() .subProcess() .triggerByEvent() .embeddedSubProcess() .startEvent("subProcessStart") .interrupting(false) .error() .endEvent() .done(); final StartEvent startEvent = modelInstance.getModelElementById("subProcessStart"); assertThat(startEvent).isNotNull(); assertThat(startEvent.isInterrupting()).isFalse(); }
@Test public void testCompensateEventDefintionCatchStartEvent() { modelInstance = Bpmn.createProcess() .startEvent("start") .compensateEventDefinition() .waitForCompletion(false) .compensateEventDefinitionDone() .userTask("userTask") .endEvent("end") .done(); final CompensateEventDefinition eventDefinition = assertAndGetSingleEventDefinition("start", CompensateEventDefinition.class); final Activity activity = eventDefinition.getActivity(); assertThat(activity).isNull(); assertThat(eventDefinition.isWaitForCompletion()).isFalse(); }
@Test public void testCompensateEventDefintionCatchBoundaryEvent() { modelInstance = Bpmn.createProcess() .startEvent() .userTask("userTask") .boundaryEvent("catch") .compensateEventDefinition() .waitForCompletion(false) .compensateEventDefinitionDone() .endEvent("end") .done(); final CompensateEventDefinition eventDefinition = assertAndGetSingleEventDefinition("catch", CompensateEventDefinition.class); final Activity activity = eventDefinition.getActivity(); assertThat(activity).isNull(); assertThat(eventDefinition.isWaitForCompletion()).isFalse(); }
@Test public void testCompensateEventDefintionCatchBoundaryEventWithId() { modelInstance = Bpmn.createProcess() .startEvent() .userTask("userTask") .boundaryEvent("catch") .compensateEventDefinition("foo") .waitForCompletion(false) .compensateEventDefinitionDone() .endEvent("end") .done(); final CompensateEventDefinition eventDefinition = assertAndGetSingleEventDefinition("catch", CompensateEventDefinition.class); assertThat(eventDefinition.getId()).isEqualTo("foo"); }
@Test public void testCompensateEventDefintionThrowEndEvent() { modelInstance = Bpmn.createProcess() .startEvent() .userTask("userTask") .endEvent("end") .compensateEventDefinition() .activityRef("userTask") .waitForCompletion(true) .compensateEventDefinitionDone() .done(); final CompensateEventDefinition eventDefinition = assertAndGetSingleEventDefinition("end", CompensateEventDefinition.class); final Activity activity = eventDefinition.getActivity(); assertThat(activity).isEqualTo(modelInstance.getModelElementById("userTask")); assertThat(eventDefinition.isWaitForCompletion()).isTrue(); }
@Test public void testCompensateEventDefintionThrowIntermediateEvent() { modelInstance = Bpmn.createProcess() .startEvent() .userTask("userTask") .intermediateThrowEvent("throw") .compensateEventDefinition() .activityRef("userTask") .waitForCompletion(true) .compensateEventDefinitionDone() .endEvent("end") .done(); final CompensateEventDefinition eventDefinition = assertAndGetSingleEventDefinition("throw", CompensateEventDefinition.class); final Activity activity = eventDefinition.getActivity(); assertThat(activity).isEqualTo(modelInstance.getModelElementById("userTask")); assertThat(eventDefinition.isWaitForCompletion()).isTrue(); }
@Test public void testCompensateEventDefintionThrowIntermediateEventWithId() { modelInstance = Bpmn.createProcess() .startEvent() .userTask("userTask") .intermediateCatchEvent("throw") .compensateEventDefinition("foo") .activityRef("userTask") .waitForCompletion(true) .compensateEventDefinitionDone() .endEvent("end") .done(); final CompensateEventDefinition eventDefinition = assertAndGetSingleEventDefinition("throw", CompensateEventDefinition.class); assertThat(eventDefinition.getId()).isEqualTo("foo"); }
@Test public void testCompensateEventDefintionReferencesNonExistingActivity() { modelInstance = Bpmn.createProcess().startEvent().userTask("userTask").endEvent("end").done(); final UserTask userTask = modelInstance.getModelElementById("userTask"); final UserTaskBuilder userTaskBuilder = userTask.builder(); try { userTaskBuilder .boundaryEvent() .compensateEventDefinition() .activityRef("nonExistingTask") .done(); fail("should fail"); } catch (final BpmnModelException e) { assertThat(e).hasMessageContaining("Activity with id 'nonExistingTask' does not exist"); } }
@Test public void testCompensateEventDefintionReferencesActivityInDifferentScope() { modelInstance = Bpmn.createProcess() .startEvent() .userTask("userTask") .subProcess() .embeddedSubProcess() .startEvent() .userTask("subProcessTask") .endEvent() .subProcessDone() .endEvent("end") .done(); final UserTask userTask = modelInstance.getModelElementById("userTask"); final UserTaskBuilder userTaskBuilder = userTask.builder(); try { userTaskBuilder .boundaryEvent("boundary") .compensateEventDefinition() .activityRef("subProcessTask") .done(); fail("should fail"); } catch (final BpmnModelException e) { assertThat(e) .hasMessageContaining( "Activity with id 'subProcessTask' must be in the same scope as 'boundary'"); } }
@Test public void testIntermediateConditionalEventDefinition() { modelInstance = Bpmn.createProcess() .startEvent() .intermediateCatchEvent(CATCH_ID) .conditionalEventDefinition(CONDITION_ID) .condition(TEST_CONDITION) .conditionalEventDefinitionDone() .endEvent() .done(); final ConditionalEventDefinition eventDefinition = assertAndGetSingleEventDefinition(CATCH_ID, ConditionalEventDefinition.class); assertThat(eventDefinition.getId()).isEqualTo(CONDITION_ID); assertThat(eventDefinition.getCondition().getTextContent()).isEqualTo(TEST_CONDITION); }
@Test public void testIntermediateConditionalEventDefinitionShortCut() { modelInstance = Bpmn.createProcess() .startEvent() .intermediateCatchEvent(CATCH_ID) .condition(TEST_CONDITION) .endEvent() .done(); final ConditionalEventDefinition eventDefinition = assertAndGetSingleEventDefinition(CATCH_ID, ConditionalEventDefinition.class); assertThat(eventDefinition.getCondition().getTextContent()).isEqualTo(TEST_CONDITION); }
@Test public void testBoundaryConditionalEventDefinition() { modelInstance = Bpmn.createProcess() .startEvent() .userTask(USER_TASK_ID) .endEvent() .moveToActivity(USER_TASK_ID) .boundaryEvent(BOUNDARY_ID) .conditionalEventDefinition(CONDITION_ID) .condition(TEST_CONDITION) .conditionalEventDefinitionDone() .endEvent() .done(); final ConditionalEventDefinition eventDefinition = assertAndGetSingleEventDefinition(BOUNDARY_ID, ConditionalEventDefinition.class); assertThat(eventDefinition.getId()).isEqualTo(CONDITION_ID); assertThat(eventDefinition.getCondition().getTextContent()).isEqualTo(TEST_CONDITION); }
@Test public void testEventSubProcessConditionalStartEvent() { modelInstance = Bpmn.createProcess() .startEvent() .userTask() .endEvent() .subProcess() .triggerByEvent() .embeddedSubProcess() .startEvent(START_EVENT_ID) .conditionalEventDefinition(CONDITION_ID) .condition(TEST_CONDITION) .conditionalEventDefinitionDone() .endEvent() .done(); final ConditionalEventDefinition eventDefinition = assertAndGetSingleEventDefinition(START_EVENT_ID, ConditionalEventDefinition.class); assertThat(eventDefinition.getId()).isEqualTo(CONDITION_ID); assertThat(eventDefinition.getCondition().getTextContent()).isEqualTo(TEST_CONDITION); }
@Test public void testMoveToDoesNotReturnRawBuilders() { Bpmn.createProcess() .startEvent("goto") .moveToNode("goto") .serviceTask("task", b -> b.name("name")); Bpmn.createProcess() .startEvent() .exclusiveGateway() .userTask() .moveToLastExclusiveGateway() .serviceTask("task", b -> b.name("name")); Bpmn.createProcess() .startEvent() .parallelGateway() .userTask() .moveToLastGateway() .serviceTask("task", b -> b.name("name")); Bpmn.createProcess() .startEvent() .serviceTask("goto") .userTask() .moveToActivity("goto") .serviceTask("task", b -> b.name("name")); }
@Test public void testConnectToDoesNotReturnRawBuilder() { Bpmn.createProcess() .startEvent() .serviceTask("goto") .connectTo("goto") .serviceTask("task", b -> b.name("name")) .done(); }
@Test public void testSetIdAsDefaultNameForFlowElements() { final BpmnModelInstance instance = Bpmn.createExecutableProcess("process") .startEvent("start") .userTask("user") .endEvent("end") .name("name") .done(); final String startName = ((FlowElement) instance.getModelElementById("start")).getName(); assertEquals("start", startName); final String userName = ((FlowElement) instance.getModelElementById("user")).getName(); assertEquals("user", userName); final String endName = ((FlowElement) instance.getModelElementById("end")).getName(); assertEquals("name", endName); }