private static Predicate<Record<WorkflowInstanceRecordValue>> elementId(List<String> elementIds) { return record -> { final String elementId = record.getValue().getElementId(); return elementIds.contains(elementId); }; } }
private static Predicate<Record<WorkflowInstanceRecordValue>> elementId(List<String> elementIds) { return record -> { final String elementId = record.getValue().getElementId(); return elementIds.contains(elementId); }; } }
public WorkflowInstanceRecordStream withElementId(final String elementId) { return valueFilter(v -> elementId.equals(v.getElementId())); }
public WorkflowInstanceRecordStream withElementId(final String elementId) { return valueFilter(v -> elementId.equals(v.getElementId())); }
public WorkflowInstanceAssert hasEntered(String... elementIds) { final List<String> ids = Arrays.asList(elementIds); final List<String> enteredElements = RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_ACTIVATED) .withWorkflowInstanceKey(workflowInstanceKey) .filter(elementId(ids)) .map(r -> r.getValue().getElementId()) .limit(ids.size()) .collect(Collectors.toList()); if (enteredElements.size() < ids.size()) { final List<String> notEntered = new ArrayList<>(ids); notEntered.removeAll(enteredElements); failWithMessage("Expected <%s> to be entered but could not find <%s>", ids, notEntered); } return this; }
public WorkflowInstanceAssert hasCompleted(String... elementIds) { final List<String> ids = Arrays.asList(elementIds); final List<String> completedElements = RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_COMPLETED) .withWorkflowInstanceKey(workflowInstanceKey) .filter(elementId(ids)) .map(r -> r.getValue().getElementId()) .limit(ids.size()) .collect(Collectors.toList()); if (completedElements.size() < ids.size()) { final List<String> notCompleted = new ArrayList<>(ids); notCompleted.removeAll(completedElements); failWithMessage("Expected <%s> to be completed but could not find <%s>", ids, notCompleted); } return this; }
public WorkflowInstanceAssert hasEntered(String... elementIds) { final List<String> ids = Arrays.asList(elementIds); final List<String> enteredElements = RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_ACTIVATED) .withWorkflowInstanceKey(workflowInstanceKey) .filter(elementId(ids)) .map(r -> r.getValue().getElementId()) .limit(ids.size()) .collect(Collectors.toList()); if (enteredElements.size() < ids.size()) { final List<String> notEntered = new ArrayList<>(ids); notEntered.removeAll(enteredElements); failWithMessage("Expected <%s> to be entered but could not find <%s>", ids, notEntered); } return this; }
public WorkflowInstanceAssert hasCompleted(String... elementIds) { final List<String> ids = Arrays.asList(elementIds); final List<String> completedElements = RecordingExporter.workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_COMPLETED) .withWorkflowInstanceKey(workflowInstanceKey) .filter(elementId(ids)) .map(r -> r.getValue().getElementId()) .limit(ids.size()) .collect(Collectors.toList()); if (completedElements.size() < ids.size()) { final List<String> notCompleted = new ArrayList<>(ids); notCompleted.removeAll(completedElements); failWithMessage("Expected <%s> to be completed but could not find <%s>", ids, notCompleted); } return this; }
public WorkflowInstanceAssert hasPassed(String... elementIds) { final List<String> ids = Arrays.asList(elementIds); final List<String> passedElements = RecordingExporter.workflowInstanceRecords() .withWorkflowInstanceKey(workflowInstanceKey) .filter(intent(ELEMENT_PASSED_INTENTS)) .filter(elementId(ids)) .map(r -> r.getValue().getElementId()) .limit(ids.size()) .collect(Collectors.toList()); if (passedElements.size() < ids.size()) { final List<String> notPassed = new ArrayList<>(ids); notPassed.removeAll(passedElements); failWithMessage("Expected <%s> to be passed but could not find <%s>", ids, notPassed); } return this; }
public WorkflowInstanceAssert hasPassed(String... elementIds) { final List<String> ids = Arrays.asList(elementIds); final List<String> passedElements = RecordingExporter.workflowInstanceRecords() .withWorkflowInstanceKey(workflowInstanceKey) .filter(intent(ELEMENT_PASSED_INTENTS)) .filter(elementId(ids)) .map(r -> r.getValue().getElementId()) .limit(ids.size()) .collect(Collectors.toList()); if (passedElements.size() < ids.size()) { final List<String> notPassed = new ArrayList<>(ids); notPassed.removeAll(passedElements); failWithMessage("Expected <%s> to be passed but could not find <%s>", ids, notPassed); } return this; }
/** * Verifies that the actual WorkflowInstanceRecordValue's elementId is equal to the given one. * @param elementId the given elementId to compare the actual WorkflowInstanceRecordValue's elementId to. * @return this assertion object. * @throws AssertionError - if the actual WorkflowInstanceRecordValue's elementId is not equal to the given one. */ public S hasElementId(String elementId) { // check that actual WorkflowInstanceRecordValue we want to make assertions on is not null. isNotNull(); // overrides the default error message with a more explicit one String assertjErrorMessage = "\nExpecting elementId of:\n <%s>\nto be:\n <%s>\nbut was:\n <%s>"; // null safe check String actualElementId = actual.getElementId(); if (!Objects.areEqual(actualElementId, elementId)) { failWithMessage(assertjErrorMessage, actual, elementId, actualElementId); } // return the current assertion for method chaining return myself; }
@Test public void shouldActivateTasksOnParallelBranches() { // given testClient.deploy(FORK_PROCESS); // when testClient.createWorkflowInstance(PROCESS_ID); // then final List<Record<WorkflowInstanceRecordValue>> taskEvents = testClient .receiveWorkflowInstances() .withIntent(WorkflowInstanceIntent.ELEMENT_ACTIVATED) .filter(e -> isServiceTaskInProcess(e.getValue().getElementId(), FORK_PROCESS)) .limit(2) .collect(Collectors.toList()); assertThat(taskEvents).hasSize(2); assertThat(taskEvents) .extracting(e -> e.getValue().getElementId()) .containsExactlyInAnyOrder("task1", "task2"); assertThat(taskEvents.get(0).getKey()).isNotEqualTo(taskEvents.get(1).getKey()); }
@Test public void shouldActivateTasksOnParallelBranches() { // given testClient.deploy(FORK_PROCESS); // when testClient.createWorkflowInstance(PROCESS_ID); // then final List<Record<WorkflowInstanceRecordValue>> taskEvents = testClient .receiveWorkflowInstances() .withIntent(WorkflowInstanceIntent.ELEMENT_ACTIVATED) .filter(e -> isServiceTaskInProcess(e.getValue().getElementId(), FORK_PROCESS)) .limit(2) .collect(Collectors.toList()); assertThat(taskEvents).hasSize(2); assertThat(taskEvents) .extracting(e -> e.getValue().getElementId()) .containsExactlyInAnyOrder("task1", "task2"); assertThat(taskEvents.get(0).getKey()).isNotEqualTo(taskEvents.get(1).getKey()); }
@Test public void shouldCompleteScopeWhenAllPathsCompleted() { // given testClient.deploy(FORK_PROCESS); testClient.createWorkflowInstance(PROCESS_ID); testClient.completeJobOfType("type1"); // when testClient.completeJobOfType("type2"); // then final List<Record<WorkflowInstanceRecordValue>> completedEvents = testClient.receiveElementInstancesInState( WorkflowInstanceIntent.ELEMENT_COMPLETED, BpmnElementType.END_EVENT, 2); assertThat(completedEvents) .extracting(e -> e.getValue().getElementId()) .containsExactly("end1", "end2"); assertThat( testClient.receiveElementInState(PROCESS_ID, WorkflowInstanceIntent.ELEMENT_COMPLETED)) .isNotNull(); }
@Test public void shouldCompleteScopeWhenAllPathsCompleted() { // given testClient.deploy(FORK_PROCESS); testClient.createWorkflowInstance(PROCESS_ID); testClient.completeJobOfType("type1"); // when testClient.completeJobOfType("type2"); // then final List<Record<WorkflowInstanceRecordValue>> completedEvents = testClient.receiveElementInstancesInState(WorkflowInstanceIntent.ELEMENT_COMPLETED, 3); assertThat(completedEvents) .extracting(e -> e.getValue().getElementId()) .containsExactly("task1", "task2", PROCESS_ID); }
@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 shouldPropagatePayloadOnSplit() { // given testClient.deploy(FORK_PROCESS); final byte[] payload = BufferUtil.bufferAsArray(MsgPackUtil.asMsgPack("key", "val")); // when testClient.createWorkflowInstance(PROCESS_ID, payload); // then final List<Record<WorkflowInstanceRecordValue>> taskEvents = testClient .receiveWorkflowInstances() .withIntent(WorkflowInstanceIntent.ELEMENT_ACTIVATED) .filter(e -> isServiceTaskInProcess(e.getValue().getElementId(), FORK_PROCESS)) .limit(2) .collect(Collectors.toList()); assertThat(taskEvents) .extracting(e -> MsgPackUtil.asMsgPackReturnArray(e.getValue().getPayload())) .allSatisfy(p -> p.equals(payload)); }
@Test public void shouldPropagatePayloadOnSplit() { // given testClient.deploy(FORK_PROCESS); final byte[] payload = BufferUtil.bufferAsArray(MsgPackUtil.asMsgPack("key", "val")); // when testClient.createWorkflowInstance(PROCESS_ID, payload); // then final List<Record<WorkflowInstanceRecordValue>> taskEvents = testClient .receiveWorkflowInstances() .withIntent(WorkflowInstanceIntent.ELEMENT_ACTIVATED) .filter(e -> isServiceTaskInProcess(e.getValue().getElementId(), FORK_PROCESS)) .limit(2) .collect(Collectors.toList()); assertThat(taskEvents) .extracting(e -> MsgPackUtil.asMsgPackReturnArray(e.getValue().getPayload())) .allSatisfy(p -> p.equals(payload)); }
@Test public void shouldSplitIfDefaultFlowIsDeclaredFirst() { final BpmnModelInstance workflowDefinition = Bpmn.createExecutableProcess("workflow") .startEvent() .exclusiveGateway() .defaultFlow() .endEvent("a") .moveToLastExclusiveGateway() .condition("$.foo < 5") .endEvent("b") .done(); testClient.deploy(workflowDefinition); // when testClient.createWorkflowInstance("workflow", MsgPackUtil.asMsgPack("foo", 10)); // then final List<Record<WorkflowInstanceRecordValue>> completedEvents = RecordingExporter.workflowInstanceRecords() .limitToWorkflowInstanceCompleted() .withIntent(WorkflowInstanceIntent.EVENT_ACTIVATED) .collect(Collectors.toList()); assertThat(completedEvents).extracting(r -> r.getValue().getElementId()).containsExactly("a"); }