/** * An entry point for WorkflowInstanceRecordValueAssert to follow AssertJ standard <code>assertThat()</code> statements.<br> * With a static import, one can write directly: <code>assertThat(myWorkflowInstanceRecordValue)</code> and get specific assertion with code completion. * @param actual the WorkflowInstanceRecordValue we want to make assertions on. * @return a new <code>{@link WorkflowInstanceRecordValueAssert}</code> */ @org.assertj.core.util.CheckReturnValue public static WorkflowInstanceRecordValueAssert assertThat(WorkflowInstanceRecordValue actual) { return new WorkflowInstanceRecordValueAssert(actual); } }
public static void assertWorkflowInstanceRecord( long workflowKey, int version, long workflowInstanceKey, String elementId, Record<WorkflowInstanceRecordValue> workflowInstanceCanceledEvent) { Assertions.assertThat(workflowInstanceCanceledEvent.getValue()) .hasBpmnProcessId(PROCESS_ID) .hasWorkflowKey(workflowKey) .hasVersion(version) .hasWorkflowInstanceKey(workflowInstanceKey) .hasElementId(elementId); }
@Test public void shouldCompleteWorkflow() { // when final ExecuteCommandResponse response = testClient.deployWithResponse(SIMPLE_MODEL); final DeploymentRecordValue deploymentRecord = testClient .receiveFirstDeploymentEvent(DeploymentIntent.CREATED, response.getKey()) .getValue(); // then assertThat(RecordingExporter.timerRecords(TimerIntent.CREATED).exists()).isTrue(); brokerRule.getClock().addTime(Duration.ofSeconds(1)); final WorkflowInstanceRecordValue instanceCompleted = RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_COMPLETED) .getFirst() .getValue(); Assertions.assertThat(instanceCompleted) .hasBpmnProcessId("process") .hasVersion(1) .hasWorkflowKey(deploymentRecord.getDeployedWorkflows().get(0).getWorkflowKey()); }
@Test public void shouldReplaceTimerStartWithNoneStart() { // when testClient.deploy(REPEATING_MODEL); assertThat(RecordingExporter.timerRecords(TimerIntent.CREATED).exists()).isTrue(); brokerRule.getClock().addTime(Duration.ofSeconds(1)); // then assertThat(RecordingExporter.timerRecords(TimerIntent.TRIGGERED).exists()).isTrue(); // when final BpmnModelInstance nonTimerModel = Bpmn.createExecutableProcess("process").startEvent("start_4").endEvent("end_4").done(); testClient.deploy(nonTimerModel); assertThat(RecordingExporter.deploymentRecords(DeploymentIntent.CREATED).limit(2).count()) .isEqualTo(2); brokerRule.getClock().addTime(Duration.ofSeconds(2)); // then assertThat(RecordingExporter.timerRecords(TimerIntent.CANCELED).exists()).isTrue(); assertThat(RecordingExporter.timerRecords(TimerIntent.TRIGGERED).exists()).isTrue(); final long workflowInstanceKey = testClient.createWorkflowInstance("process"); final WorkflowInstanceRecordValue lastRecord = RecordingExporter.workflowInstanceRecords(EVENT_ACTIVATED) .withElementId("end_4") .getFirst() .getValue(); Assertions.assertThat(lastRecord) .hasVersion(2) .hasBpmnProcessId("process") .hasWorkflowInstanceKey(workflowInstanceKey); }
@Test public void shouldCorrelateMessageToStartEvent() { // given final ExecuteCommandResponse response = testClient.deployWithResponse(createWorkflowWithOneMessageStartEvent()); final long workflowKey = getFirstDeployedWorkflowKey(response); // wait until subscription is opened assertThat( messageStartEventSubscriptionRecords(MessageStartEventSubscriptionIntent.OPENED) .exists()) .isTrue(); // when testClient.publishMessage(MESSAGE_NAME1, "order-123", asMsgPack("foo", "bar")); // then final Record<WorkflowInstanceRecordValue> record = RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.EVENT_OCCURRED).getFirst(); assertThat(record.getValue()).hasWorkflowKey(workflowKey).hasElementId(EVENT_ID1); }
@Test public void shouldCreateInstancesForDifferentMessages() { // given final ExecuteCommandResponse response = testClient.deployWithResponse(createWorkflowWithTwoMessageStartEvent()); final long workflowKey = getFirstDeployedWorkflowKey(response); // check if two subscriptions are opened assertThat( messageStartEventSubscriptionRecords(MessageStartEventSubscriptionIntent.OPENED) .limit(2) .count()) .isEqualTo(2); // when testClient.publishMessage(MESSAGE_NAME1, "order-123", asMsgPack("foo", "bar")); testClient.publishMessage(MESSAGE_NAME2, "order-124", asMsgPack("foo", "bar")); // then // check if two instances are created final List<Record<WorkflowInstanceRecordValue>> records = RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_COMPLETING) .limit(2) .asList(); assertThat(records.size()).isEqualTo(2); assertThat(records).allMatch(r -> r.getValue().getWorkflowKey() == workflowKey); assertThat(records.get(0).getValue()) .hasElementId(EVENT_ID1); // Message 1 triggers start event 1 assertThat(records.get(1).getValue()) .hasElementId(EVENT_ID2); // Message 2 triggers start event 2 }
@Test public void shouldWriteEntireEventOnCancel() { // given testClient.deploy(WORKFLOW); final long workflowInstanceKey = testClient.createWorkflowInstance(PROCESS_ID); final io.zeebe.exporter.record.Record<WorkflowInstanceRecordValue> activatedEvent = RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_ACTIVATED) .withElementId(PROCESS_ID) .getFirst(); // when final ExecuteCommandResponse response = cancelWorkflowInstance(workflowInstanceKey); // then MsgPackUtil.assertEqualityExcluding( response.getRawValue(), activatedEvent.getValue().toJson(), "payload"); final io.zeebe.exporter.record.Record<WorkflowInstanceRecordValue> cancelingEvent = RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_TERMINATING) .withElementId(PROCESS_ID) .getFirst(); assertThat(cancelingEvent.getValue()).isEqualTo(activatedEvent.getValue()); }
@Test public void shouldCompleteWorkflow() { // when final ExecuteCommandResponse response = testClient.deployWithResponse(SIMPLE_MODEL); final DeploymentRecordValue deploymentRecord = testClient .receiveFirstDeploymentEvent(DeploymentIntent.CREATED, response.getKey()) .getValue(); // then assertThat(RecordingExporter.timerRecords(TimerIntent.CREATED).exists()).isTrue(); brokerRule.getClock().addTime(Duration.ofSeconds(1)); final WorkflowInstanceRecordValue instanceCompleted = RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_COMPLETED) .getFirst() .getValue(); Assertions.assertThat(instanceCompleted) .hasBpmnProcessId("process") .hasVersion(1) .hasWorkflowKey(deploymentRecord.getDeployedWorkflows().get(0).getWorkflowKey()); }
@Test public void shouldReplaceTimerStartWithNoneStart() { // when testClient.deploy(REPEATING_MODEL); assertThat(RecordingExporter.timerRecords(TimerIntent.CREATED).exists()).isTrue(); brokerRule.getClock().addTime(Duration.ofSeconds(1)); // then assertThat(RecordingExporter.timerRecords(TimerIntent.TRIGGERED).exists()).isTrue(); // when final BpmnModelInstance nonTimerModel = Bpmn.createExecutableProcess("process").startEvent("start_4").endEvent("end_4").done(); testClient.deploy(nonTimerModel); assertThat(RecordingExporter.deploymentRecords(DeploymentIntent.CREATED).limit(2).count()) .isEqualTo(2); brokerRule.getClock().addTime(Duration.ofSeconds(2)); // then assertThat(RecordingExporter.timerRecords(TimerIntent.CANCELED).exists()).isTrue(); assertThat(RecordingExporter.timerRecords(TimerIntent.TRIGGERED).exists()).isTrue(); final long workflowInstanceKey = testClient.createWorkflowInstance("process"); final WorkflowInstanceRecordValue lastRecord = RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_ACTIVATED) .withElementId("end_4") .getFirst() .getValue(); Assertions.assertThat(lastRecord) .hasVersion(2) .hasBpmnProcessId("process") .hasWorkflowInstanceKey(workflowInstanceKey); }
@Test public void shouldCorrelateMessageToStartEvent() { // given final ExecuteCommandResponse response = testClient.deployWithResponse(createWorkflowWithOneMessageStartEvent()); final long workflowKey = getFirstDeployedWorkflowKey(response); // wait until subscription is opened assertThat( messageStartEventSubscriptionRecords(MessageStartEventSubscriptionIntent.OPENED) .exists()) .isTrue(); // when testClient.publishMessage(MESSAGE_NAME1, "order-123", asMsgPack("foo", "bar")); // then final Record<WorkflowInstanceRecordValue> record = RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.EVENT_OCCURRED).getFirst(); assertThat(record.getValue()).hasWorkflowKey(workflowKey).hasElementId(EVENT_ID1); }
@Test public void shouldCreateInstancesForDifferentMessages() { // given final ExecuteCommandResponse response = testClient.deployWithResponse(createWorkflowWithTwoMessageStartEvent()); final long workflowKey = getFirstDeployedWorkflowKey(response); // check if two subscriptions are opened assertThat( messageStartEventSubscriptionRecords(MessageStartEventSubscriptionIntent.OPENED) .limit(2) .count()) .isEqualTo(2); // when testClient.publishMessage(MESSAGE_NAME1, "order-123", asMsgPack("foo", "bar")); testClient.publishMessage(MESSAGE_NAME2, "order-124", asMsgPack("foo", "bar")); // then // check if two instances are created final List<Record<WorkflowInstanceRecordValue>> records = RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.EVENT_TRIGGERING) .limit(2) .asList(); assertThat(records.size()).isEqualTo(2); assertThat(records).allMatch(r -> r.getValue().getWorkflowKey() == workflowKey); assertThat(records.get(0).getValue()) .hasElementId(EVENT_ID1); // Message 1 triggers start event 1 assertThat(records.get(1).getValue()) .hasElementId(EVENT_ID2); // Message 2 triggers start event 2 }
@Test public void shouldWriteEntireEventOnCancel() { // given testClient.deploy(WORKFLOW); final long workflowInstanceKey = testClient.createWorkflowInstance(PROCESS_ID); final io.zeebe.exporter.record.Record<WorkflowInstanceRecordValue> activatedEvent = RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_ACTIVATED) .withElementId(PROCESS_ID) .getFirst(); // when final ExecuteCommandResponse response = cancelWorkflowInstance(workflowInstanceKey); // then MsgPackUtil.assertEqualityExcluding( response.getRawValue(), activatedEvent.getValue().toJson(), "payload"); final io.zeebe.exporter.record.Record<WorkflowInstanceRecordValue> cancelingEvent = RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_TERMINATING) .withElementId(PROCESS_ID) .getFirst(); assertThat(cancelingEvent.getValue()).isEqualTo(activatedEvent.getValue()); }
public static void assertWorkflowInstanceRecord( long workflowKey, int version, long workflowInstanceKey, String elementId, Record<WorkflowInstanceRecordValue> workflowInstanceCanceledEvent) { Assertions.assertThat(workflowInstanceCanceledEvent.getValue()) .hasBpmnProcessId(PROCESS_ID) .hasWorkflowKey(workflowKey) .hasVersion(version) .hasWorkflowInstanceKey(workflowInstanceKey) .hasElementId(elementId); }
@Test public void shouldCreateInstanceOnMessage() { // given final ExecuteCommandResponse response = testClient.deployWithResponse(createWorkflowWithOneMessageStartEvent()); final long workflowKey = getFirstDeployedWorkflowKey(response); // wait until subscription is opened assertThat( messageStartEventSubscriptionRecords(MessageStartEventSubscriptionIntent.OPENED) .exists()) .isTrue(); // when testClient.publishMessage(MESSAGE_NAME1, "order-123", asMsgPack("foo", "bar")); // then final List<Record<WorkflowInstanceRecordValue>> records = RecordingExporter.workflowInstanceRecords().limit(5).asList(); assertThat(records) .extracting(r -> r.getMetadata().getIntent()) .containsExactly( WorkflowInstanceIntent.EVENT_OCCURRED, // message WorkflowInstanceIntent.ELEMENT_READY, // workflow instance WorkflowInstanceIntent.ELEMENT_ACTIVATED, WorkflowInstanceIntent.EVENT_TRIGGERING, // start event WorkflowInstanceIntent.EVENT_TRIGGERED); assertThat(records).allMatch(r -> r.getValue().getWorkflowKey() == workflowKey); assertThat(records.get(3).getValue()).hasElementId(EVENT_ID1); final WorkflowInstanceRecordValue eventTriggeredRecord = records.get(4).getValue(); assertThat(eventTriggeredRecord.getPayloadAsMap()).containsEntry("foo", "bar"); }
/** * Creates a new instance of <code>{@link io.zeebe.exporter.record.value.WorkflowInstanceRecordValueAssert}</code>. * * @param actual the actual value. * @return the created assertion object. */ @org.assertj.core.util.CheckReturnValue public static io.zeebe.exporter.record.value.WorkflowInstanceRecordValueAssert assertThat(io.zeebe.exporter.record.value.WorkflowInstanceRecordValue actual) { return new io.zeebe.exporter.record.value.WorkflowInstanceRecordValueAssert(actual); }
public static void assertWorkflowInstanceRecord( String bpmnId, int version, long workflowInstanceKey, String elementId, Record<WorkflowInstanceRecordValue> workflowInstanceCanceledEvent) { Assertions.assertThat(workflowInstanceCanceledEvent.getValue()) .hasBpmnProcessId(bpmnId) .hasVersion(version) .hasWorkflowInstanceKey(workflowInstanceKey) .hasElementId(elementId); }
@Test public void shouldCreateInstanceOnMessage() { // given final ExecuteCommandResponse response = testClient.deployWithResponse(createWorkflowWithOneMessageStartEvent()); final long workflowKey = getFirstDeployedWorkflowKey(response); // wait until subscription is opened assertThat( messageStartEventSubscriptionRecords(MessageStartEventSubscriptionIntent.OPENED) .exists()) .isTrue(); // when testClient.publishMessage(MESSAGE_NAME1, "order-123", asMsgPack("foo", "bar")); // then final List<Record<WorkflowInstanceRecordValue>> records = RecordingExporter.workflowInstanceRecords().limit(5).asList(); assertThat(records) .extracting(r -> r.getMetadata().getIntent()) .containsExactly( WorkflowInstanceIntent.EVENT_OCCURRED, // message WorkflowInstanceIntent.ELEMENT_ACTIVATING, // workflow instance WorkflowInstanceIntent.ELEMENT_ACTIVATED, WorkflowInstanceIntent.ELEMENT_ACTIVATING, // start event WorkflowInstanceIntent.ELEMENT_ACTIVATED); assertThat(records).allMatch(r -> r.getValue().getWorkflowKey() == workflowKey); assertThat(records.get(3).getValue()).hasElementId(EVENT_ID1); final WorkflowInstanceRecordValue eventTriggeredRecord = records.get(4).getValue(); assertThat(eventTriggeredRecord.getPayloadAsMap()).containsEntry("foo", "bar"); }
public static void assertWorkflowInstanceRecord( String bpmnId, int version, long workflowInstanceKey, String elementId, Record<WorkflowInstanceRecordValue> workflowInstanceCanceledEvent) { Assertions.assertThat(workflowInstanceCanceledEvent.getValue()) .hasBpmnProcessId(bpmnId) .hasVersion(version) .hasWorkflowInstanceKey(workflowInstanceKey) .hasElementId(elementId); }
public static void assertWorkflowInstanceRecord( long workflowInstanceKey, String elementId, Record<WorkflowInstanceRecordValue> workflowInstanceCanceledEvent) { Assertions.assertThat(workflowInstanceCanceledEvent.getValue()) .hasBpmnProcessId(PROCESS_ID) .hasVersion(1) .hasWorkflowInstanceKey(workflowInstanceKey) .hasElementId(elementId); }
public static void assertWorkflowInstanceRecord( long workflowInstanceKey, String elementId, Record<WorkflowInstanceRecordValue> workflowInstanceCanceledEvent) { Assertions.assertThat(workflowInstanceCanceledEvent.getValue()) .hasBpmnProcessId(PROCESS_ID) .hasVersion(1) .hasWorkflowInstanceKey(workflowInstanceKey) .hasElementId(elementId); }