Java Code Examples for org.camunda.bpm.model.bpmn.Bpmn#createExecutableProcess()

The following examples show how to use org.camunda.bpm.model.bpmn.Bpmn#createExecutableProcess() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DiGeneratorForFlowNodesTest.java    From camunda-bpmn-model with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldGenerateShapeForManualTask() {

  // given
  ProcessBuilder processBuilder = Bpmn.createExecutableProcess();

  // when
  instance = processBuilder
                .startEvent(START_EVENT_ID)
                .manualTask(TASK_ID)
                .done();

  // then
  Collection<BpmnShape> allShapes = instance.getModelElementsByType(BpmnShape.class);
  assertEquals(2, allShapes.size());

  assertTaskShapeProperties(TASK_ID);
}
 
Example 2
Source File: DiGeneratorForFlowNodesTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldGenerateShapeForCallActivity() {

  // given
  ProcessBuilder processBuilder = Bpmn.createExecutableProcess();

  // when
  instance = processBuilder
                .startEvent(START_EVENT_ID)
                .callActivity(CALL_ACTIVITY_ID)
                .endEvent(END_EVENT_ID)
                .done();

  // then
  Collection<BpmnShape> allShapes = instance.getModelElementsByType(BpmnShape.class);
  assertEquals(3, allShapes.size());

  assertTaskShapeProperties(CALL_ACTIVITY_ID);
}
 
Example 3
Source File: DiGeneratorForFlowNodesTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldGenerateShapeForReceiveTask() {

  // given
  ProcessBuilder processBuilder = Bpmn.createExecutableProcess();

  // when
  instance = processBuilder
                .startEvent(START_EVENT_ID)
                .receiveTask(TASK_ID)
                .done();

  // then
  Collection<BpmnShape> allShapes = instance.getModelElementsByType(BpmnShape.class);
  assertEquals(2, allShapes.size());

  assertTaskShapeProperties(TASK_ID);
}
 
Example 4
Source File: DiGeneratorForFlowNodesTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldGenerateShapeForEventBasedGateway() {

  // given
  ProcessBuilder processBuilder = Bpmn.createExecutableProcess();

  // when
  instance = processBuilder
                .startEvent(START_EVENT_ID)
                .eventBasedGateway()
                  .id("eventBased")
                .endEvent(END_EVENT_ID)
                .done();

  // then
  Collection<BpmnShape> allShapes = instance.getModelElementsByType(BpmnShape.class);
  assertEquals(3, allShapes.size());

  assertGatewayShapeProperties("eventBased");
}
 
Example 5
Source File: CoordinatesGenerationTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldPlaceTwoBoundaryEventsForSubProcess() {
  ProcessBuilder builder = Bpmn.createExecutableProcess();

  instance = builder
      .startEvent(START_EVENT_ID)
      .subProcess(SUB_PROCESS_ID)
      .boundaryEvent("boundary1")
      .moveToActivity(SUB_PROCESS_ID)
      .boundaryEvent("boundary2")
      .moveToActivity(SUB_PROCESS_ID)
      .endEvent()
      .done();

  Bounds boundaryEvent1Bounds = findBpmnShape("boundary1").getBounds();
  assertShapeCoordinates(boundaryEvent1Bounds, 343, 200);

  Bounds boundaryEvent2Bounds = findBpmnShape("boundary2").getBounds();
  assertShapeCoordinates(boundaryEvent2Bounds, 379, 200);

}
 
Example 6
Source File: CoordinatesGenerationTest.java    From camunda-bpmn-model with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldPlaceThreeBoundaryEventsForSubProcess() {
  ProcessBuilder builder = Bpmn.createExecutableProcess();

  instance = builder
      .startEvent(START_EVENT_ID)
      .subProcess(SUB_PROCESS_ID)
      .boundaryEvent("boundary1")
      .moveToActivity(SUB_PROCESS_ID)
      .boundaryEvent("boundary2")
      .moveToActivity(SUB_PROCESS_ID)
      .boundaryEvent("boundary3")
      .moveToActivity(SUB_PROCESS_ID)
      .endEvent()
      .done();

  Bounds boundaryEvent1Bounds = findBpmnShape("boundary1").getBounds();
  assertShapeCoordinates(boundaryEvent1Bounds, 343, 200);

  Bounds boundaryEvent2Bounds = findBpmnShape("boundary2").getBounds();
  assertShapeCoordinates(boundaryEvent2Bounds, 379, 200);

  Bounds boundaryEvent3Bounds = findBpmnShape("boundary3").getBounds();
  assertShapeCoordinates(boundaryEvent3Bounds, 307, 200);
}
 
Example 7
Source File: DiGeneratorForFlowNodesTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldGenerateShapeForCatchingIntermediateEvent() {

  // given
  ProcessBuilder processBuilder = Bpmn.createExecutableProcess();

  // when
  instance = processBuilder
                .startEvent(START_EVENT_ID)
                .intermediateCatchEvent(CATCH_ID)
                .endEvent(END_EVENT_ID)
                .done();

  // then
  Collection<BpmnShape> allShapes = instance.getModelElementsByType(BpmnShape.class);
  assertEquals(3, allShapes.size());

  assertEventShapeProperties(CATCH_ID);
}
 
Example 8
Source File: DiGeneratorForFlowNodesTest.java    From camunda-bpm-platform with Apache License 2.0 6 votes vote down vote up
@Test
public void shouldGenerateShapeForStartEvent() {

  // given
  ProcessBuilder processBuilder = Bpmn.createExecutableProcess();

  // when
  instance = processBuilder
                .startEvent(START_EVENT_ID)
                .endEvent(END_EVENT_ID)
                .done();

  // then
  Collection<BpmnShape> allShapes = instance.getModelElementsByType(BpmnShape.class);
  assertEquals(2, allShapes.size());

  assertEventShapeProperties(START_EVENT_ID);
}
 
Example 9
Source File: CoordinatesGenerationTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldPlaceTwoBranchesForEventBasedGateway() {
  ProcessBuilder builder = Bpmn.createExecutableProcess();

  instance = builder
      .startEvent(START_EVENT_ID)
      .eventBasedGateway()
        .id("id")
      .sequenceFlowId("s1")
      .userTask(USER_TASK_ID)
      .moveToNode("id")
      .sequenceFlowId("s2")
      .endEvent(END_EVENT_ID)
      .done();

  Bounds userTaskBounds = findBpmnShape(USER_TASK_ID).getBounds();
  assertShapeCoordinates(userTaskBounds, 286, 78);

  Bounds endEventBounds = findBpmnShape(END_EVENT_ID).getBounds();
  assertShapeCoordinates(endEventBounds, 286, 208);

  Collection<Waypoint> sequenceFlowWaypoints = findBpmnEdge("s2").getWaypoints();
  Iterator<Waypoint> iterator = sequenceFlowWaypoints.iterator();

  Waypoint waypoint = iterator.next();
  assertWaypointCoordinates(waypoint, 211, 143);

  while(iterator.hasNext()){
    waypoint = iterator.next();
  }

  assertWaypointCoordinates(waypoint, 286, 226);
}
 
Example 10
Source File: CoordinatesGenerationTest.java    From camunda-bpmn-model with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldPlaceServiceTask() {

  ProcessBuilder builder = Bpmn.createExecutableProcess();

  instance = builder
      .startEvent(START_EVENT_ID)
      .sequenceFlowId(SEQUENCE_FLOW_ID)
      .serviceTask(SERVICE_TASK_ID)
      .done();

  Bounds serviceTaskBounds = findBpmnShape(SERVICE_TASK_ID).getBounds();
  assertShapeCoordinates(serviceTaskBounds, 186, 78);

  Collection<Waypoint> sequenceFlowWaypoints = findBpmnEdge(SEQUENCE_FLOW_ID).getWaypoints();
  Iterator<Waypoint> iterator = sequenceFlowWaypoints.iterator();

  Waypoint waypoint = iterator.next();
  assertWaypointCoordinates(waypoint, 136, 118);

  while(iterator.hasNext()){
    waypoint = iterator.next();
  }

  assertWaypointCoordinates(waypoint, 186, 118);

}
 
Example 11
Source File: CoordinatesGenerationTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldPlaceThreeBranchesForInclusiveGateway() {
  ProcessBuilder builder = Bpmn.createExecutableProcess();

  instance = builder
      .startEvent(START_EVENT_ID)
      .inclusiveGateway("id")
      .userTask(USER_TASK_ID)
      .moveToNode("id")
      .endEvent(END_EVENT_ID)
      .moveToNode("id")
      .sequenceFlowId("s1")
      .serviceTask(SERVICE_TASK_ID)
      .done();

  Bounds userTaskBounds = findBpmnShape(USER_TASK_ID).getBounds();
  assertShapeCoordinates(userTaskBounds, 286, 78);

  Bounds endEventBounds = findBpmnShape(END_EVENT_ID).getBounds();
  assertShapeCoordinates(endEventBounds, 286, 208);

  Bounds serviceTaskBounds = findBpmnShape(SERVICE_TASK_ID).getBounds();
  assertShapeCoordinates(serviceTaskBounds, 286, 294);

  Collection<Waypoint> sequenceFlowWaypoints = findBpmnEdge("s1").getWaypoints();
  Iterator<Waypoint> iterator = sequenceFlowWaypoints.iterator();

  Waypoint waypoint = iterator.next();
  assertWaypointCoordinates(waypoint, 211, 143);

  while(iterator.hasNext()){
    waypoint = iterator.next();
  }

  assertWaypointCoordinates(waypoint, 286, 334);
}
 
Example 12
Source File: CoordinatesGenerationTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldAdjustSubProcessHeightWithEmbeddedProcess() {

  ProcessBuilder builder = Bpmn.createExecutableProcess();

  instance = builder
      .startEvent(START_EVENT_ID)
      .subProcess(SUB_PROCESS_ID)
        .embeddedSubProcess()
        .startEvent("innerStartEvent")
        .subProcess()
          .embeddedSubProcess()
            .startEvent()
            .exclusiveGateway("id")
            .userTask()
            .moveToNode("id")
            .endEvent()
        .subProcessDone()
        .endEvent("innerEndEvent")
      .subProcessDone()
      .endEvent()
      .done();

  Bounds subProcessBounds = findBpmnShape(SUB_PROCESS_ID).getBounds();
  assertThat(subProcessBounds.getY()).isEqualTo(-32);
  assertThat(subProcessBounds.getHeight()).isEqualTo(376);
}
 
Example 13
Source File: CoordinatesGenerationTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldPlaceManyBoundaryEventsForSubProcess() {
  ProcessBuilder builder = Bpmn.createExecutableProcess();

  instance = builder
      .startEvent(START_EVENT_ID)
      .subProcess(SUB_PROCESS_ID)
      .boundaryEvent("boundary1")
      .moveToActivity(SUB_PROCESS_ID)
      .boundaryEvent("boundary2")
      .moveToActivity(SUB_PROCESS_ID)
      .boundaryEvent("boundary3")
      .moveToActivity(SUB_PROCESS_ID)
      .boundaryEvent("boundary4")
      .moveToActivity(SUB_PROCESS_ID)
      .endEvent()
      .done();

  Bounds boundaryEvent1Bounds = findBpmnShape("boundary1").getBounds();
  assertShapeCoordinates(boundaryEvent1Bounds, 343, 200);

  Bounds boundaryEvent2Bounds = findBpmnShape("boundary2").getBounds();
  assertShapeCoordinates(boundaryEvent2Bounds, 379, 200);

  Bounds boundaryEvent3Bounds = findBpmnShape("boundary3").getBounds();
  assertShapeCoordinates(boundaryEvent3Bounds, 307, 200);

  Bounds boundaryEvent4Bounds = findBpmnShape("boundary4").getBounds();
  assertShapeCoordinates(boundaryEvent4Bounds, 343, 200);
}
 
Example 14
Source File: ExecutionListenerTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void testThrowBpmnErrorInEndListenerOfLastEventAndEventProcessWithCatch() {
  // given
  ProcessBuilder processBuilder = Bpmn.createExecutableProcess(PROCESS_KEY);
  BpmnModelInstance model = processBuilder
      .startEvent()
      .userTask("userTask1")
      .serviceTask("throw")
        .camundaExpression("${true}")
        .camundaExecutionListenerClass(ExecutionListener.EVENTNAME_END, ThrowBPMNErrorDelegate.class.getName())
      .done();

  processBuilder.eventSubProcess()
      .startEvent("errorEvent").error(ERROR_CODE)
      .userTask("afterCatch")
      .endEvent();

  testHelper.deploy(model);
  runtimeService.startProcessInstanceByKey(PROCESS_KEY);
  Task task = taskService.createTaskQuery().taskDefinitionKey("userTask1").singleResult();
  // when the listeners are invoked
  taskService.complete(task.getId());

  // then
  Task afterCatch = taskService.createTaskQuery().singleResult();
  assertNotNull(afterCatch);
  assertEquals("afterCatch", afterCatch.getName());
  assertEquals(1, ThrowBPMNErrorDelegate.INVOCATIONS);

  // and completing this task ends the process instance
  taskService.complete(afterCatch.getId());

  assertEquals(0, runtimeService.createExecutionQuery().count());
}
 
Example 15
Source File: CoordinatesGenerationTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldPlaceServiceTask() {

  ProcessBuilder builder = Bpmn.createExecutableProcess();

  instance = builder
      .startEvent(START_EVENT_ID)
      .sequenceFlowId(SEQUENCE_FLOW_ID)
      .serviceTask(SERVICE_TASK_ID)
      .done();

  Bounds serviceTaskBounds = findBpmnShape(SERVICE_TASK_ID).getBounds();
  assertShapeCoordinates(serviceTaskBounds, 186, 78);

  Collection<Waypoint> sequenceFlowWaypoints = findBpmnEdge(SEQUENCE_FLOW_ID).getWaypoints();
  Iterator<Waypoint> iterator = sequenceFlowWaypoints.iterator();

  Waypoint waypoint = iterator.next();
  assertWaypointCoordinates(waypoint, 136, 118);

  while(iterator.hasNext()){
    waypoint = iterator.next();
  }

  assertWaypointCoordinates(waypoint, 186, 118);

}
 
Example 16
Source File: CoordinatesGenerationTest.java    From camunda-bpm-platform with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldPlaceTwoBranchesForInclusiveGateway() {
  ProcessBuilder builder = Bpmn.createExecutableProcess();

  instance = builder
      .startEvent(START_EVENT_ID)
      .inclusiveGateway("id")
      .sequenceFlowId("s1")
      .userTask(USER_TASK_ID)
      .moveToNode("id")
      .sequenceFlowId("s2")
      .endEvent(END_EVENT_ID)
      .done();

  Bounds userTaskBounds = findBpmnShape(USER_TASK_ID).getBounds();
  assertShapeCoordinates(userTaskBounds, 286, 78);

  Bounds endEventBounds = findBpmnShape(END_EVENT_ID).getBounds();
  assertShapeCoordinates(endEventBounds, 286, 208);

  Collection<Waypoint> sequenceFlowWaypoints = findBpmnEdge("s2").getWaypoints();
  Iterator<Waypoint> iterator = sequenceFlowWaypoints.iterator();

  Waypoint waypoint = iterator.next();
  assertWaypointCoordinates(waypoint, 211, 143);

  while(iterator.hasNext()){
    waypoint = iterator.next();
  }

  assertWaypointCoordinates(waypoint, 286, 226);
}
 
Example 17
Source File: CoordinatesGenerationTest.java    From camunda-bpmn-model with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldPlaceExclusiveGateway() {

  ProcessBuilder builder = Bpmn.createExecutableProcess();

  instance = builder
      .startEvent(START_EVENT_ID)
      .sequenceFlowId(SEQUENCE_FLOW_ID)
      .exclusiveGateway("id")
      .done();

  Bounds gatewayBounds = findBpmnShape("id").getBounds();
  assertShapeCoordinates(gatewayBounds, 186, 93);

  Collection<Waypoint> sequenceFlowWaypoints = findBpmnEdge(SEQUENCE_FLOW_ID).getWaypoints();
  Iterator<Waypoint> iterator = sequenceFlowWaypoints.iterator();

  Waypoint waypoint = iterator.next();
  assertWaypointCoordinates(waypoint, 136, 118);

  while(iterator.hasNext()){
    waypoint = iterator.next();
  }

  assertWaypointCoordinates(waypoint, 186, 118);

}
 
Example 18
Source File: CoordinatesGenerationTest.java    From camunda-bpmn-model with Apache License 2.0 5 votes vote down vote up
@Test
public void shouldPlaceInclusiveGateway() {

  ProcessBuilder builder = Bpmn.createExecutableProcess();

  instance = builder
      .startEvent(START_EVENT_ID)
      .sequenceFlowId(SEQUENCE_FLOW_ID)
      .inclusiveGateway("id")
      .done();

  Bounds gatewayBounds = findBpmnShape("id").getBounds();
  assertShapeCoordinates(gatewayBounds, 186, 93);

  Collection<Waypoint> sequenceFlowWaypoints = findBpmnEdge(SEQUENCE_FLOW_ID).getWaypoints();
  Iterator<Waypoint> iterator = sequenceFlowWaypoints.iterator();

  Waypoint waypoint = iterator.next();
  assertWaypointCoordinates(waypoint, 136, 118);

  while(iterator.hasNext()){
    waypoint = iterator.next();
  }

  assertWaypointCoordinates(waypoint, 186, 118);

}
 
Example 19
Source File: ProcessModels.java    From camunda-external-task-client-java with Apache License 2.0 4 votes vote down vote up
public static ProcessBuilder newModel(String processKey) {
  return Bpmn.createExecutableProcess(processKey);
}
 
Example 20
Source File: TripBookingSaga.java    From trip-booking-saga-java with Apache License 2.0 4 votes vote down vote up
public static void main(String[] args) {
  // Configure and startup (in memory) engine
  ProcessEngine camunda = 
      new StandaloneInMemProcessEngineConfiguration()
        .buildProcessEngine();
  
  // define saga as BPMN process
  ProcessBuilder flow = Bpmn.createExecutableProcess("trip");
  
  // - flow of activities and compensating actions
  flow.startEvent()
      .serviceTask("car").name("Reserve car").camundaClass(ReserveCarAdapter.class)
        .boundaryEvent().compensateEventDefinition().compensateEventDefinitionDone()
        .compensationStart().serviceTask("CancelCar").camundaClass(CancelCarAdapter.class).compensationDone()
      .serviceTask("hotel").name("Book hotel").camundaClass(BookHotelAdapter.class)
        .boundaryEvent().compensateEventDefinition().compensateEventDefinitionDone()
        .compensationStart().serviceTask("CancelHotel").camundaClass(CancelHotelAdapter.class).compensationDone()
      .serviceTask("flight").name("Book flight").camundaClass(BookFlightAdapter.class)
        .boundaryEvent().compensateEventDefinition().compensateEventDefinitionDone()
        .compensationStart().serviceTask("CancelFlight").camundaClass(CancelFlightAdapter.class).compensationDone()
      .endEvent();
  
  // - trigger compensation in case of any exception (other triggers are possible)
  flow.eventSubProcess()
      .startEvent().error("java.lang.Throwable")
      .intermediateThrowEvent().compensateEventDefinition().compensateEventDefinitionDone()
      .endEvent();     
  
  // ready
  BpmnModelInstance saga = flow.done();
  // optional: Write to file to be able to open it in Camunda Modeler
  //Bpmn.writeModelToFile(new File("trip.bpmn"), saga);

  // finish Saga and deploy it to Camunda
  camunda.getRepositoryService().createDeployment() //
      .addModelInstance("trip.bpmn", saga) //
      .deploy();
  
  // now we can start running instances of our saga - its state will be persisted
  camunda.getRuntimeService().startProcessInstanceByKey("trip", Variables.putValue("name", "trip1"));
  camunda.getRuntimeService().startProcessInstanceByKey("trip", Variables.putValue("name", "trip2"));
}