use of org.kie.kogito.event.process.ProcessDataEvent in project kogito-runtimes by kiegroup.
the class ProcessEventIT method testSaveTask.
@Test
void testSaveTask() throws InterruptedException {
Traveller traveller = new Traveller("pepe", "rubiales", "pepe.rubiales@gmail.com", "Spanish");
final int count = 7;
final CountDownLatch countDownLatch = new CountDownLatch(count);
kafkaClient.consume(Set.of(KOGITO_PROCESSINSTANCES_EVENTS, KOGITO_USERTASKINSTANCES_EVENTS, KOGITO_VARIABLE_EVENTS), s -> {
LOGGER.info("Received from kafka: {}", s);
try {
ProcessDataEvent event = mapper.readValue(s, ProcessDataEvent.class);
LinkedHashMap data = (LinkedHashMap) event.getData();
if (data.get("processId") == "handleApprovals") {
switch(event.getType()) {
case "ProcessInstanceEvent":
Assertions.assertEquals("ProcessInstanceEvent", event.getType());
Assertions.assertEquals("/handleApprovals", event.getSource().toString());
Assertions.assertEquals("handleApprovals", data.get("processId"));
break;
case "UserTaskInstanceEvent":
Assertions.assertEquals("UserTaskInstanceEvent", event.getType());
Assertions.assertEquals("/handleApprovals", event.getSource().toString());
Assertions.assertEquals("handleApprovals", data.get("processId"));
break;
case "VariableInstanceEvent":
Assertions.assertEquals("VariableInstanceEvent", event.getType());
Assertions.assertEquals("/handleApprovals", event.getSource().toString());
Assertions.assertEquals("handleApprovals", data.get("processId"));
break;
}
}
countDownLatch.countDown();
} catch (Exception e) {
LOGGER.error("Error parsing {}", s, e);
fail(e);
}
});
String processId = given().contentType(ContentType.JSON).when().body(Collections.singletonMap("traveller", traveller)).post("/handleApprovals").then().statusCode(201).extract().path("id");
String taskId = given().contentType(ContentType.JSON).queryParam("user", "admin").queryParam("group", "managers").pathParam("processId", processId).when().get("/handleApprovals/{processId}/tasks").then().statusCode(200).extract().path("[0].id");
Map<String, Object> model = Collections.singletonMap("approved", true);
Assertions.assertEquals(model, given().contentType(ContentType.JSON).when().queryParam("user", "admin").queryParam("group", "managers").pathParam("processId", processId).pathParam("taskId", taskId).body(model).put("/handleApprovals/{processId}/firstLineApproval/{taskId}").then().statusCode(200).extract().as(Map.class));
Assertions.assertEquals(true, given().contentType(ContentType.JSON).when().queryParam("user", "admin").queryParam("group", "managers").pathParam("processId", processId).pathParam("taskId", taskId).get("/handleApprovals/{processId}/firstLineApproval/{taskId}").then().statusCode(200).extract().path("results.approved"));
String humanTaskId = given().contentType(ContentType.JSON).queryParam("user", "admin").queryParam("group", "managers").pathParam("processId", processId).when().get("/handleApprovals/{processId}/tasks").then().statusCode(200).extract().path("[1].id");
countDownLatch.await(10, TimeUnit.SECONDS);
Assertions.assertEquals(0, countDownLatch.getCount());
}
Aggregations