@Test public void shouldNotCreateInstanceOfOldVersion() { // given testClient.deploy(createWorkflowWithOneMessageStartEvent()); // new version final ExecuteCommandResponse response = testClient.deployWithResponse(createWorkflowWithOneMessageStartEvent()); final long workflowKey2 = getFirstDeployedWorkflowKey(response); // wait until second subscription is opened assertThat( messageStartEventSubscriptionRecords(MessageStartEventSubscriptionIntent.OPENED) .limit(2) .count()) .isEqualTo(2); // when testClient.publishMessage(MESSAGE_NAME1, "order-123", asMsgPack("foo", "bar")); // then final List<Record<WorkflowInstanceRecordValue>> records = RecordingExporter.workflowInstanceRecords().limit(5).asList(); assertThat(records.stream().map(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() == workflowKey2); }
@Test public void shouldNotCreateInstanceOfOldVersion() { // given testClient.deploy(createWorkflowWithOneMessageStartEvent()); // new version final ExecuteCommandResponse response = testClient.deployWithResponse(createWorkflowWithOneMessageStartEvent()); final long workflowKey2 = getFirstDeployedWorkflowKey(response); // wait until second subscription is opened assertThat( messageStartEventSubscriptionRecords(MessageStartEventSubscriptionIntent.OPENED) .limit(2) .count()) .isEqualTo(2); // when testClient.publishMessage(MESSAGE_NAME1, "order-123", asMsgPack("foo", "bar")); // then final List<Record<WorkflowInstanceRecordValue>> records = RecordingExporter.workflowInstanceRecords().limit(5).asList(); assertThat(records.stream().map(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() == workflowKey2); }
@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 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 shouldCreateInstancesForMultipleMessagesOfSameName() { // 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")); testClient.publishMessage(MESSAGE_NAME1, "order-124", asMsgPack("foo", "bar")); // then // check if two instances are created final List<Record<WorkflowInstanceRecordValue>> records = RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_READY) .limit(2) .asList(); assertThat(records).allMatch(r -> r.getValue().getWorkflowKey() == workflowKey); final WorkflowInstanceRecordValue recordValue1 = records.get(0).getValue(); final WorkflowInstanceRecordValue recordValue2 = records.get(1).getValue(); assertThat(recordValue1.getWorkflowInstanceKey()) .isNotEqualTo(recordValue2.getWorkflowInstanceKey()); }
@Test public void shouldCreateInstancesForMultipleMessagesOfSameName() { // 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")); testClient.publishMessage(MESSAGE_NAME1, "order-124", asMsgPack("foo", "bar")); // then // check if two instances are created final List<Record<WorkflowInstanceRecordValue>> records = RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_ACTIVATING) .withElementType(BpmnElementType.PROCESS) .limit(2) .asList(); assertThat(records).allMatch(r -> r.getValue().getWorkflowKey() == workflowKey); final WorkflowInstanceRecordValue recordValue1 = records.get(0).getValue(); final WorkflowInstanceRecordValue recordValue2 = records.get(1).getValue(); assertThat(recordValue1.getWorkflowInstanceKey()) .isNotEqualTo(recordValue2.getWorkflowInstanceKey()); }
@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"); }
@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"); }
@Test public void shouldCorrelateMessageOnlyOnceIfEnteredBefore() { // given testClient.deploy(TWO_MESSAGES_WORKFLOW); testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("key", "123")); // when assertThat( RecordingExporter.workflowInstanceSubscriptionRecords( WorkflowInstanceSubscriptionIntent.OPENED) .exists()) .isTrue(); testClient.publishMessage("ping", "123", asMsgPack("nr", 1)); assertThat( RecordingExporter.workflowInstanceSubscriptionRecords( WorkflowInstanceSubscriptionIntent.OPENED) .limit(2) .count()) .isEqualTo(2); testClient.publishMessage("ping", "123", asMsgPack("nr", 2)); // then assertThat( RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_COMPLETED) .filter(r -> r.getValue().getElementId().startsWith("message")) .limit(2) .asList()) .extracting( r -> tuple(r.getValue().getElementId(), r.getValue().getPayloadAsMap().get("nr"))) .contains(tuple("message1", 1), tuple("message2", 2)); }
@Test public void shouldCorrelateMessageOnlyOnceIfEnteredBefore() { // given testClient.deploy(TWO_MESSAGES_WORKFLOW); testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("key", "123")); // when assertThat( RecordingExporter.workflowInstanceSubscriptionRecords( WorkflowInstanceSubscriptionIntent.OPENED) .exists()) .isTrue(); testClient.publishMessage("ping", "123", asMsgPack("nr", 1)); assertThat( RecordingExporter.workflowInstanceSubscriptionRecords( WorkflowInstanceSubscriptionIntent.OPENED) .limit(2) .count()) .isEqualTo(2); testClient.publishMessage("ping", "123", asMsgPack("nr", 2)); // then assertThat( RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.EVENT_TRIGGERED) .filter(r -> r.getValue().getElementId().startsWith("message")) .limit(2) .asList()) .extracting( r -> tuple(r.getValue().getElementId(), r.getValue().getPayloadAsMap().get("nr"))) .contains(tuple("message1", 1), tuple("message2", 2)); }
@Test public void shouldCorrelateOnlyOneMessagePerCatchElement() { // given testClient.deploy(TWO_MESSAGES_WORKFLOW); testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("key", "123")); assertThat( RecordingExporter.workflowInstanceSubscriptionRecords( WorkflowInstanceSubscriptionIntent.OPENED) .exists()) .isTrue(); // when testClient.publishMessage("ping", "123", asMsgPack("nr", 1)); testClient.publishMessage("ping", "123", asMsgPack("nr", 2)); // then assertThat( RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_COMPLETED) .filter(r -> r.getValue().getElementId().startsWith("message")) .limit(2) .asList()) .extracting( r -> tuple(r.getValue().getElementId(), r.getValue().getPayloadAsMap().get("nr"))) .contains(tuple("message1", 1), tuple("message2", 2)); }
@Test public void shouldCorrelateOnlyOneMessagePerCatchElement() { // given testClient.deploy(TWO_MESSAGES_WORKFLOW); testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("key", "123")); assertThat( RecordingExporter.workflowInstanceSubscriptionRecords( WorkflowInstanceSubscriptionIntent.OPENED) .exists()) .isTrue(); // when testClient.publishMessage("ping", "123", asMsgPack("nr", 1)); testClient.publishMessage("ping", "123", asMsgPack("nr", 2)); // then assertThat( RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.EVENT_TRIGGERED) .filter(r -> r.getValue().getElementId().startsWith("message")) .limit(2) .asList()) .extracting( r -> tuple(r.getValue().getElementId(), r.getValue().getPayloadAsMap().get("nr"))) .contains(tuple("message1", 1), tuple("message2", 2)); }
@Test public void shouldCorrelateMessageOnlyOnceIfPublishedBefore() { // given testClient.deploy(TWO_MESSAGES_WORKFLOW); testClient.publishMessage("ping", "123", asMsgPack("nr", 1)); testClient.publishMessage("ping", "123", asMsgPack("nr", 2)); // when testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("key", "123")); // then assertThat( RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.EVENT_TRIGGERED) .filter(r -> r.getValue().getElementId().startsWith("message")) .limit(2) .asList()) .extracting( r -> tuple(r.getValue().getElementId(), r.getValue().getPayloadAsMap().get("nr"))) .contains(tuple("message1", 1), tuple("message2", 2)); }
@Test public void shouldCorrelateMessageOnlyOnceIfPublishedBefore() { // given testClient.deploy(TWO_MESSAGES_WORKFLOW); testClient.publishMessage("ping", "123", asMsgPack("nr", 1)); testClient.publishMessage("ping", "123", asMsgPack("nr", 2)); // when testClient.createWorkflowInstance(PROCESS_ID, asMsgPack("key", "123")); // then assertThat( RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_COMPLETED) .filter(r -> r.getValue().getElementId().startsWith("message")) .limit(2) .asList()) .extracting( r -> tuple(r.getValue().getElementId(), r.getValue().getPayloadAsMap().get("nr"))) .contains(tuple("message1", 1), tuple("message2", 2)); }
@Test public void test() { // given testClient.deploy(scenario.modelInstance()); // when scenario.executeInstance(); // then final List<Record<WorkflowInstanceRecordValue>> records = RecordingExporter.workflowInstanceRecords() .withBpmnProcessId(scenario.processId()) .limitToWorkflowInstanceCompleted() .withElementId(scenario.elementId()) .asList(); assertThat(records) .extracting(r -> r.getValue().getBpmnElementType()) .isNotEmpty() .containsOnly(scenario.elementType()); }
@Test public void test() { // given testClient.deploy(scenario.modelInstance()); // when scenario.executeInstance(); // then final List<Record<WorkflowInstanceRecordValue>> records = RecordingExporter.workflowInstanceRecords() .withBpmnProcessId(scenario.processId()) .limitToWorkflowInstanceCompleted() .withElementId(scenario.elementId()) .asList(); assertThat(records) .extracting(r -> r.getValue().getBpmnElementType()) .isNotEmpty() .containsOnly(scenario.elementType()); }
.filter(r -> r.getValue().getElementId().startsWith("message")) .limit(2) .asList()) .extracting(r -> r.getValue().getPayloadAsMap().get("nr")) .contains(1, 2);
.filter(r -> r.getValue().getElementId().startsWith("message")) .limit(2) .asList()) .extracting(r -> r.getValue().getPayloadAsMap().get("nr")) .contains(1, 2);
.withElementId("msg1End") .limit(3) .asList();
.withElementId("msg1") .limit(3) .asList();