diff --git a/assertions/src/main/java/io/camunda/zeebe/process/test/assertions/ProcessInstanceAssert.java b/assertions/src/main/java/io/camunda/zeebe/process/test/assertions/ProcessInstanceAssert.java index f535521c..cfa78ca4 100644 --- a/assertions/src/main/java/io/camunda/zeebe/process/test/assertions/ProcessInstanceAssert.java +++ b/assertions/src/main/java/io/camunda/zeebe/process/test/assertions/ProcessInstanceAssert.java @@ -24,6 +24,7 @@ import io.camunda.zeebe.protocol.record.Record; import io.camunda.zeebe.protocol.record.RejectionType; import io.camunda.zeebe.protocol.record.intent.IncidentIntent; +import io.camunda.zeebe.protocol.record.intent.JobIntent; import io.camunda.zeebe.protocol.record.intent.ProcessInstanceIntent; import io.camunda.zeebe.protocol.record.intent.ProcessMessageSubscriptionIntent; import io.camunda.zeebe.protocol.record.value.BpmnElementType; @@ -605,6 +606,31 @@ public ProcessInstanceAssert hasCalledProcess(final String processId) { return this; } + /** + * Asserts whether this process has thrown an error for this element + * + * @param elementId The id of the element that should have thrown error + * @return this {@link ProcessInstanceAssert} + */ + public ProcessInstanceAssert hasProcessInstanceThrownError(final String elementId) { + + final long count = + StreamFilter.jobRecords(recordStream) + .withIntent(JobIntent.ERROR_THROWN) + .withElementId(elementId) + .stream() + .filter(r -> r.getValue().getProcessInstanceKey() == actual) + .count(); + + assertThat(count) + .withFailMessage( + "Expected element with id %s to have thrown %s error(s), but was %s", + elementId, 1, count) + .isEqualTo(1); + + return this; + } + private ProcessInstanceRecordStreamFilter getCalledProcessRecords() { return StreamFilter.processInstance(recordStream).withParentProcessInstanceKey(actual); }