@Test public void shouldCreateTaskWhenServiceTaskIsActivated() { // given testClient.deploy( Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .serviceTask("foo", t -> t.zeebeTaskType("bar").zeebeTaskRetries(5)) .endEvent() .done()); // when testClient.createWorkflowInstance(PROCESS_ID); // then final Record<WorkflowInstanceRecordValue> activityActivated = testClient.receiveElementInState("foo", WorkflowInstanceIntent.ELEMENT_ACTIVATED); final Record<JobRecordValue> createJobCmd = testClient.receiveFirstJobCommand(JobIntent.CREATE); assertThat(createJobCmd.getKey()).isEqualTo(ExecuteCommandResponseDecoder.keyNullValue()); assertThat(createJobCmd.getSourceRecordPosition()).isEqualTo(activityActivated.getPosition()); assertJobRecord(createJobCmd); }
@Test public void shouldCreateTaskWhenServiceTaskIsActivated() { // given testClient.deploy( Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .serviceTask("foo", t -> t.zeebeTaskType("bar").zeebeTaskRetries(5)) .endEvent() .done()); // when testClient.createWorkflowInstance(PROCESS_ID); // then final Record<WorkflowInstanceRecordValue> activityActivated = testClient.receiveElementInState("foo", WorkflowInstanceIntent.ELEMENT_ACTIVATED); final Record<JobRecordValue> createJobCmd = testClient.receiveFirstJobCommand(JobIntent.CREATE); assertThat(createJobCmd.getKey()).isEqualTo(ExecuteCommandResponseDecoder.keyNullValue()); assertThat(createJobCmd.getSourceRecordPosition()).isEqualTo(activityActivated.getPosition()); assertJobRecord(createJobCmd); }
@Test public void shouldActivateServiceTask() { // given final BpmnModelInstance model = Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .serviceTask("foo", t -> t.zeebeTaskType("bar")) .endEvent() .done(); testClient.deploy(model); // when final long workflowInstanceKey = testClient.createWorkflowInstance(PROCESS_ID); // then final Record<WorkflowInstanceRecordValue> activityReady = testClient.receiveElementInState("foo", WorkflowInstanceIntent.ELEMENT_READY); final Record<WorkflowInstanceRecordValue> activatedEvent = testClient.receiveElementInState("foo", WorkflowInstanceIntent.ELEMENT_ACTIVATED); assertThat(activatedEvent.getKey()).isGreaterThan(0).isNotEqualTo(workflowInstanceKey); assertThat(activatedEvent.getSourceRecordPosition()).isEqualTo(activityReady.getPosition()); assertWorkflowInstanceRecord(workflowInstanceKey, "foo", activatedEvent); }
@Test public void shouldActivateJobsWithLongCustomHeaders() { // given final BpmnModelInstance modelInstance = Bpmn.createExecutableProcess("processId") .startEvent() .serviceTask( "task", b -> { b.zeebeTaskType("taskType").zeebeTaskHeader("foo", LONG_CUSTOM_HEADER_VALUE); }) .endEvent() .done(); apiRule.partitionClient().deployWithResponse(Bpmn.convertToString(modelInstance).getBytes()); apiRule.partitionClient().createWorkflowInstance("processId"); // when apiRule.partitionClient().completeJobOfType("taskType"); // then final JobRecordValue jobRecord = RecordingExporter.jobRecords(JobIntent.ACTIVATED).limit(1).getFirst().getValue(); assertThat(jobRecord.getCustomHeaders().get("foo")).isEqualTo(LONG_CUSTOM_HEADER_VALUE); }
@Test public void shouldCompleteInstanceAfterParallelSplit() { // given testClient.deploy( Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .parallelGateway() .serviceTask("task-1", t -> t.zeebeTaskType("task-1")) .endEvent("end-1") .moveToLastGateway() .serviceTask("task-2", t -> t.zeebeTaskType("task-2")) .endEvent("end-2") .done()); testClient.createWorkflowInstance(PROCESS_ID); // when testClient.completeJobOfType("task-1"); testClient.completeJobOfType("task-2"); // then assertThatWorkflowInstanceCompletedAfter("end-2", WorkflowInstanceIntent.EVENT_ACTIVATED); }
@Test public void shouldApplyInputMappings() { // given testClient.deploy( Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .serviceTask( "service", builder -> { builder.zeebeTaskType("test"); mappings.accept(builder); }) .endEvent() .done()); // when testClient.createWorkflowInstance(PROCESS_ID, initialPayload); // then final Record<JobRecordValue> jobCreated = RecordingExporter.jobRecords(JobIntent.CREATED).getFirst(); JsonUtil.assertEquality(jobCreated.getValue().getPayload(), expectedPayload); }
@Test public void shouldApplyInputMappings() { // given testClient.deploy( Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .serviceTask( "service", builder -> { builder.zeebeTaskType("test"); mappings.accept(builder); }) .endEvent() .done()); // when testClient.createWorkflowInstance(PROCESS_ID, initialPayload); // then final Record<JobRecordValue> jobCreated = RecordingExporter.jobRecords(JobIntent.CREATED).getFirst(); JsonUtil.assertEquality(jobCreated.getValue().getPayload(), expectedPayload); }
@Test public void shouldCompleteInstanceAfterNonInterruptingBoundaryEventTriggered() { // given testClient.deploy( Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .serviceTask("task-1", t -> t.zeebeTaskType("task-1")) .endEvent("end-1") .moveToActivity("task-1") .boundaryEvent("timeout", b -> b.cancelActivity(false).timerWithCycle("R1/PT0.1S")) .serviceTask("task-2", t -> t.zeebeTaskType("task-2")) .endEvent("end-2") .done()); testClient.createWorkflowInstance(PROCESS_ID); // when testClient.completeJobOfType("task-2"); testClient.completeJobOfType("task-1"); // then assertThatWorkflowInstanceCompletedAfter("end-1", WorkflowInstanceIntent.EVENT_ACTIVATED); assertThatWorkflowInstanceCompletedAfter("end-2", WorkflowInstanceIntent.EVENT_ACTIVATED); }
@Test public void shouldCreateJobWithWorkflowInstanceAndCustomHeaders() { // given testClient.deploy( Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .serviceTask( "foo", t -> t.zeebeTaskType("bar").zeebeTaskHeader("a", "b").zeebeTaskHeader("c", "d")) .endEvent() .done()); // when final long workflowInstanceKey = testClient.createWorkflowInstance(PROCESS_ID); // then final Record<JobRecordValue> event = testClient.receiveFirstJobCommand(JobIntent.CREATE); assertJobHeaders(workflowInstanceKey, "foo", event); final Map<String, Object> customHeaders = event.getValue().getCustomHeaders(); assertThat(customHeaders).containsEntry("a", "b").containsEntry("c", "d"); }
@Test public void shouldCompleteInstanceAfterInterruptingBoundaryEventTriggered() { // given testClient.deploy( Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .serviceTask("task", t -> t.zeebeTaskType("task")) .endEvent("end-1") .moveToActivity("task") .boundaryEvent("timeout", b -> b.cancelActivity(true).timerWithDuration("PT0.1S")) .endEvent("end-2") .done()); testClient.createWorkflowInstance(PROCESS_ID); // when brokerRule.getClock().addTime(Duration.ofSeconds(1)); // then assertThatWorkflowInstanceCompletedAfter("end-2", WorkflowInstanceIntent.EVENT_ACTIVATED); }
@Test public void shouldCompleteInstanceAfterInterruptingBoundaryEventTriggered() { // given testClient.deploy( Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .serviceTask("task", t -> t.zeebeTaskType("task")) .endEvent("end-1") .moveToActivity("task") .boundaryEvent("timeout", b -> b.cancelActivity(true).timerWithDuration("PT0.1S")) .endEvent("end-2") .done()); testClient.createWorkflowInstance(PROCESS_ID); // when brokerRule.getClock().addTime(Duration.ofSeconds(1)); // then assertThatWorkflowInstanceCompletedAfter("end-2", WorkflowInstanceIntent.ELEMENT_COMPLETED); }
@Test public void shouldCreateJobWithWorkflowInstanceAndCustomHeaders() { // given testClient.deploy( Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .serviceTask( "foo", t -> t.zeebeTaskType("bar").zeebeTaskHeader("a", "b").zeebeTaskHeader("c", "d")) .endEvent() .done()); // when final long workflowInstanceKey = testClient.createWorkflowInstance(PROCESS_ID); // then final Record<JobRecordValue> event = testClient.receiveFirstJobCommand(JobIntent.CREATE); assertJobHeaders(workflowInstanceKey, "foo", event); final Map<String, Object> customHeaders = event.getValue().getCustomHeaders(); assertThat(customHeaders).containsEntry("a", "b").containsEntry("c", "d"); }
@Test public void shouldNotCompleteInstanceAfterIncidentIsRaisedOnActivity() { // given testClient.deploy( Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .parallelGateway() .serviceTask("task-1", t -> t.zeebeTaskType("task-1")) .endEvent("end-1") .moveToLastGateway() .serviceTask("task-2", t -> t.zeebeTaskType("task-2").zeebeOutput("$.result", "$.r")) .endEvent("end-2") .done()); testClient.createWorkflowInstance(PROCESS_ID); // when testClient.completeJobOfType("task-2"); final Record<IncidentRecordValue> incident = RecordingExporter.incidentRecords(IncidentIntent.CREATED).getFirst(); testClient.completeJobOfType("task-1"); testClient.updatePayload(incident.getValue().getElementInstanceKey(), "{'result':'123'}"); testClient.resolveIncident(incident.getKey()); // then assertThatWorkflowInstanceCompletedAfter("end-2", WorkflowInstanceIntent.EVENT_ACTIVATED); }
@Test public void shouldCompleteInstanceAfterTimerIntermediateCatchEvent() { // given brokerRule.getClock().pinCurrentTime(); testClient.deploy( Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .parallelGateway() .serviceTask("task", t -> t.zeebeTaskType("task")) .endEvent("end-1") .moveToLastGateway() .intermediateCatchEvent("catch", e -> e.timerWithDuration("PT0.1S")) .endEvent("end-2") .done()); testClient.createWorkflowInstance(PROCESS_ID); // when testClient.completeJobOfType("task"); brokerRule.getClock().addTime(Duration.ofSeconds(1)); // then assertThatWorkflowInstanceCompletedAfter("end-2", WorkflowInstanceIntent.EVENT_ACTIVATED); }
public static DeploymentRecord creatingDeploymentRecord() { final BpmnModelInstance modelInstance = Bpmn.createExecutableProcess("processId") .startEvent() .serviceTask( "test", task -> { task.zeebeTaskType("type"); }) .endEvent() .done(); final DeploymentRecord deploymentRecord = new DeploymentRecord(); deploymentRecord .resources() .add() .setResourceName(wrapString("process.bpmn")) .setResource(wrapString(Bpmn.convertToString(modelInstance))) .setResourceType(ResourceType.BPMN_XML); return deploymentRecord; } }
private void creatingDeployment(final long key) { final BpmnModelInstance modelInstance = Bpmn.createExecutableProcess("processId") .startEvent() .serviceTask( "test", task -> { task.zeebeTaskType("type"); }) .endEvent() .done(); final DeploymentRecord deploymentRecord = new DeploymentRecord(); deploymentRecord .resources() .add() .setResourceName(wrapString("process.bpmn")) .setResource(wrapString(Bpmn.convertToString(modelInstance))) .setResourceType(ResourceType.BPMN_XML); rule.writeCommand(key, DeploymentIntent.CREATE, deploymentRecord); } }
@Test public void shouldUpdateVariableByOutputMapping() { // given testClient.deploy( Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .serviceTask("task", t -> t.zeebeTaskType("test").zeebeOutput("$.x", "$.y")) .endEvent() .done()); final long workflowInstanceKey = testClient.createWorkflowInstance(PROCESS_ID, "{'y':1}"); // when testClient.completeJobOfType("test", "{'x':2}"); // then final Record<VariableRecordValue> variableRecord = RecordingExporter.variableRecords(VariableIntent.UPDATED).getFirst(); Assertions.assertThat(variableRecord.getValue()) .hasScopeInstanceKey(workflowInstanceKey) .hasName("y") .hasValue("2"); }
@Test public void shouldCreateVariableByOutputMapping() { // given testClient.deploy( Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .serviceTask("task", t -> t.zeebeTaskType("test").zeebeOutput("$.x", "$.y")) .endEvent() .done()); final long workflowInstanceKey = testClient.createWorkflowInstance(PROCESS_ID); // when testClient.completeJobOfType("test", "{'x':1}"); // then final Record<VariableRecordValue> variableRecord = RecordingExporter.variableRecords(VariableIntent.CREATED).withName("y").getFirst(); Assertions.assertThat(variableRecord.getValue()) .hasScopeInstanceKey(workflowInstanceKey) .hasName("y") .hasValue("1"); }
@Test public void shouldCreateVariableByOutputMapping() { // given testClient.deploy( Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .serviceTask("task", t -> t.zeebeTaskType("test").zeebeOutput("$.x", "$.y")) .endEvent() .done()); final long workflowInstanceKey = testClient.createWorkflowInstance(PROCESS_ID); // when testClient.completeJobOfType("test", "{'x':1}"); // then final Record<VariableRecordValue> variableRecord = RecordingExporter.variableRecords(VariableIntent.CREATED).withName("y").getFirst(); Assertions.assertThat(variableRecord.getValue()) .hasScopeKey(workflowInstanceKey) .hasName("y") .hasValue("1"); }
@Test public void shouldCompleteInstanceAfterMessageIntermediateCatchEvent() { // given testClient.deploy( Bpmn.createExecutableProcess(PROCESS_ID) .startEvent() .parallelGateway() .serviceTask("task", t -> t.zeebeTaskType("task")) .endEvent("end-1") .moveToLastGateway() .intermediateCatchEvent( "catch", e -> e.message(m -> m.name("msg").zeebeCorrelationKey("$.key"))) .endEvent("end-2") .done()); testClient.createWorkflowInstance(PROCESS_ID, "{'key':'123'}"); // when testClient.completeJobOfType("task"); testClient.publishMessage("msg", "123"); // then assertThatWorkflowInstanceCompletedAfter("end-2", WorkflowInstanceIntent.EVENT_ACTIVATED); }