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 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 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 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; }
/** * @return stream with only records for the workflow instance (i.e. root scope of the instance) */ public WorkflowInstanceRecordStream filterRootScope() { return filter(r -> r.getKey() == r.getValue().getWorkflowInstanceKey()); } }
/** * @return stream with only records for the workflow instance (i.e. root scope of the instance) */ public WorkflowInstanceRecordStream filterRootScope() { return filter(r -> r.getKey() == r.getValue().getWorkflowInstanceKey()); } }
/** * Blocks and wait until the workflow identified by the key has been completed. * * @param workflowInstanceKey ID of the workflow */ public void awaitWorkflowCompletion(long workflowInstanceKey) { TestUtil.waitUntil( () -> workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_COMPLETED) .filter(r -> r.getKey() == workflowInstanceKey) .exists()); }
/** * Blocks and wait until the workflow identified by the key has been completed. * * @param workflowInstanceKey ID of the workflow */ public void awaitWorkflowCompletion(long workflowInstanceKey) { TestUtil.waitUntil( () -> workflowInstanceRecords(WorkflowInstanceIntent.ELEMENT_COMPLETED) .filter(r -> r.getKey() == workflowInstanceKey) .exists()); }
public WorkflowInstanceAssert hasPayload(String key, Object expectedValue) { final Optional<Record<WorkflowInstanceRecordValue>> record = RecordingExporter.workflowInstanceRecords() .withWorkflowInstanceKey(workflowInstanceKey) .withKey(workflowInstanceKey) .filter(intent(INSTANCE_ENDED_INTENTS)) .findFirst(); if (record.isPresent()) { hasPayload(record.get(), key, expectedValue); } else { failWithMessage("Expected workflow instance to contain payload but instance is not ended"); } return this; }
public WorkflowInstanceAssert hasElementPayload( String elementId, String key, Object expectedValue) { final Optional<Record<WorkflowInstanceRecordValue>> record = RecordingExporter.workflowInstanceRecords() .withWorkflowInstanceKey(workflowInstanceKey) .withElementId(elementId) .filter(r -> ELEMENT_PASSED_INTENTS.contains(r.getMetadata().getIntent())) .findFirst(); if (record.isPresent()) { hasPayload(record.get(), key, expectedValue); } else { failWithMessage("Expected <%s> to contain payload but element was not passed", elementId); } return this; }
public WorkflowInstanceAssert hasPayload(String key, Object expectedValue) { final Optional<Record<WorkflowInstanceRecordValue>> record = RecordingExporter.workflowInstanceRecords() .withWorkflowInstanceKey(workflowInstanceKey) .withKey(workflowInstanceKey) .filter(intent(INSTANCE_ENDED_INTENTS)) .findFirst(); if (record.isPresent()) { hasPayload(record.get(), key, expectedValue); } else { failWithMessage("Expected workflow instance to contain payload but instance is not ended"); } return this; }
public WorkflowInstanceAssert hasElementPayload( String elementId, String key, Object expectedValue) { final Optional<Record<WorkflowInstanceRecordValue>> record = RecordingExporter.workflowInstanceRecords() .withWorkflowInstanceKey(workflowInstanceKey) .withElementId(elementId) .filter(r -> ELEMENT_PASSED_INTENTS.contains(r.getMetadata().getIntent())) .findFirst(); if (record.isPresent()) { hasPayload(record.get(), key, expectedValue); } else { failWithMessage("Expected <%s> to contain payload but element was not passed", elementId); } return this; }
public WorkflowInstanceAssert isEnded() { final boolean isEnded = exists( RecordingExporter.workflowInstanceRecords() .withWorkflowInstanceKey(workflowInstanceKey) .withKey(workflowInstanceKey) .filter(intent(INSTANCE_ENDED_INTENTS))); if (!isEnded) { failWithMessage("Expected workflow instance to be <ended> but was <active>"); } return this; }
public WorkflowInstanceAssert isEnded() { final boolean isEnded = exists( RecordingExporter.workflowInstanceRecords() .withWorkflowInstanceKey(workflowInstanceKey) .withKey(workflowInstanceKey) .filter(intent(INSTANCE_ENDED_INTENTS))); if (!isEnded) { failWithMessage("Expected workflow instance to be <ended> but was <active>"); } return this; }
@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 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 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)); }