Skip to content

Commit

Permalink
camunda#771 assert for error thrown
Browse files Browse the repository at this point in the history
  • Loading branch information
muraliweb9 committed Jun 5, 2023
1 parent 89ceb43 commit 43529e9
Showing 1 changed file with 26 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
Expand Down

0 comments on commit 43529e9

Please sign in to comment.