Skip to content

Commit

Permalink
refactor: ThrowError test case
Browse files Browse the repository at this point in the history
Avoid nested assertion to produce a better failure message if the verification is not fulfilled.
  • Loading branch information
saig0 committed Feb 8, 2024
1 parent bc858f8 commit 9298f7a
Showing 1 changed file with 34 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -783,10 +783,10 @@ void shouldThrowErrorOnJob() {
.newCreateInstanceCommand()
.bpmnProcessId("simpleProcess")
.latestVersion()
.variables(Map.of("test", 1))
.send()
.join();

// when
Awaitility.await()
.untilAsserted(
() -> {
Expand All @@ -797,60 +797,57 @@ void shouldThrowErrorOnJob() {
.maxJobsToActivate(32)
.timeout(Duration.ofMinutes(1))
.workerName("yolo")
.fetchVariables(List.of("test"))
.send()
.join();

final List<ActivatedJob> jobs = activateJobsResponse.getJobs();
assertThat(jobs).isNotEmpty();
final ActivatedJob job = jobs.get(0);

// when - then
zeebeClient
.newThrowErrorCommand(job.getKey())
.errorCode("0xCAFE")
.errorMessage("What just happened.")
.variable("error_var", "Out of coffee")
.send()
.join();
});

Awaitility.await()
.untilAsserted(
() -> {
final Optional<Record<ProcessInstanceRecordValue>> boundaryEvent =
StreamSupport.stream(
RecordStream.of(zeebeEngine.getRecordStreamSource())
.processInstanceRecords()
.spliterator(),
false)
.filter(
r -> r.getIntent() == ProcessInstanceIntent.ELEMENT_COMPLETED)
.filter(
r ->
r.getValue().getBpmnElementType()
== BpmnElementType.BOUNDARY_EVENT)
.filter(r -> r.getValue().getBpmnEventType() == BpmnEventType.ERROR)
.findFirst();
// then
Awaitility.await()
.untilAsserted(
() -> {
final Optional<Record<ProcessInstanceRecordValue>> boundaryEvent =
StreamSupport.stream(
RecordStream.of(zeebeEngine.getRecordStreamSource())
.processInstanceRecords()
.spliterator(),
false)
.filter(r -> r.getIntent() == ProcessInstanceIntent.ELEMENT_COMPLETED)
.filter(
r -> r.getValue().getBpmnElementType() == BpmnElementType.BOUNDARY_EVENT)
.filter(r -> r.getValue().getBpmnEventType() == BpmnEventType.ERROR)
.findFirst();

assertThat(boundaryEvent).isNotEmpty();
assertThat(boundaryEvent)
.describedAs("Expect that the error boundary event is completed")
.isNotEmpty();

final var errorVariable =
StreamSupport.stream(
RecordStream.of(zeebeEngine.getRecordStreamSource())
.variableRecords()
.spliterator(),
false)
.filter(r -> r.getValue().getName().equals("error_var"))
.findFirst();
final var errorVariable =
StreamSupport.stream(
RecordStream.of(zeebeEngine.getRecordStreamSource())
.variableRecords()
.spliterator(),
false)
.filter(r -> r.getValue().getName().equals("error_var"))
.findFirst();

assertThat(errorVariable)
.describedAs("Expect that the error variable is set")
.isPresent()
.hasValueSatisfying(
record ->
assertThat(record.getValue().getValue())
.isEqualTo("\"Out of coffee\""));
});
assertThat(errorVariable)
.describedAs("Expect that the error variable is set")
.isPresent()
.hasValueSatisfying(
record ->
assertThat(record.getValue().getValue()).isEqualTo("\"Out of coffee\""));
});
}

Expand Down

0 comments on commit 9298f7a

Please sign in to comment.