Hi guys,
a quick question, we are doing some testing with Camunda 8 and ZeebeSpringTest (see code below). Is there a way, that we can also can check the contents of the variables that we put in the process when we complete a ServiceTask?
When we complete our ServiceTask, we add a variable “personOnboardingResponse” and in the main-test-method we would also like to verify the contents of this variable. Is that possible? I tried to get the variable via the event, but this does not have a method for it. Is that possible some other way?
@Test
void testExecution() throws IOException, InterruptedException, TimeoutException, JSONException {
ProcessInstanceEvent event = client.newCreateInstanceCommand()
.bpmnProcessId("process_ID")
.latestVersion()
.variables(new FileInputStream("src/test/resources/request.json"))
.send()
.join();
ProcessInstanceAssert assertions = BpmnAssert.assertThat(event);
waitForIdleState(Duration.ofSeconds(1));
completeServiceTasks("generateDummyResponseDataWorker", 1);
waitForIdleState(Duration.ofSeconds(1));
completeServiceTasks("endSubprocessWorker", 1);
waitForIdleState(Duration.ofSeconds(1));
BpmnAssert.assertThat(event)
.hasPassedElement("Activity_0836ag6")
.hasVariable("personOnboardingResponse")
.isCompleted();
}
private void completeServiceTasks(final String jobType, final int count)
throws InterruptedException, TimeoutException {
final var activateJobsResponse =
client.newActivateJobsCommand().jobType(jobType).maxJobsToActivate(count).send().join();
final int activatedJobCount = activateJobsResponse.getJobs().size();
if (activatedJobCount < count) {
Assertions.fail(
"Unable to activate %d jobs, because only %d were activated."
.formatted(count, activatedJobCount));
}
ObjectMapper mapper = new ObjectMapper();
ObjectNode rootNode = mapper.createObjectNode();
ObjectNode childNode1 = mapper.createObjectNode();
childNode1.put("name1", "val1");
childNode1.put("name2", "val2");
rootNode.set("personOnboardingResponse", childNode1);
for (int i = 0; i < count; i++) {
final var job = activateJobsResponse.getJobs().get(i);
client.newCompleteCommand(job.getKey()).variables(rootNode).send().join();
}
waitForIdleState(Duration.ofSeconds(1));
}