use of org.kie.kogito.event.DataEvent in project kogito-runtimes by kiegroup.
the class PublishEventIT method testBusinessRuleProcessStartToEndWithVariableTracked.
@Test
public void testBusinessRuleProcessStartToEndWithVariableTracked() throws Exception {
Map<TYPE, List<String>> resourcesTypeMap = new HashMap<>();
resourcesTypeMap.put(TYPE.PROCESS, Collections.singletonList("ruletask/BusinessRuleTaskVariableTags.bpmn2"));
resourcesTypeMap.put(TYPE.RULES, Collections.singletonList("ruletask/BusinessRuleTask.drl"));
Application app = generateCode(resourcesTypeMap);
assertThat(app).isNotNull();
TestEventPublisher publisher = new TestEventPublisher();
app.unitOfWorkManager().eventManager().setService("http://myhost");
app.unitOfWorkManager().eventManager().addPublisher(publisher);
UnitOfWork uow = app.unitOfWorkManager().newUnitOfWork();
uow.start();
Process<? extends Model> p = app.get(Processes.class).processById("BusinessRuleTask");
Model m = p.createModel();
m.fromMap(Collections.singletonMap("person", new Person("john", 25)));
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
Model result = (Model) processInstance.variables();
assertThat(result.toMap()).hasSize(1).containsKey("person");
assertThat(result.toMap().get("person")).isNotNull().hasFieldOrPropertyWithValue("adult", true);
uow.end();
List<DataEvent<?>> events = publisher.extract();
assertThat(events).isNotNull().hasSize(3);
DataEvent<?> event = events.get(0);
assertThat(event).isInstanceOf(ProcessInstanceDataEvent.class);
ProcessInstanceDataEvent processDataEvent = (ProcessInstanceDataEvent) event;
assertThat(processDataEvent.getKogitoProcessinstanceId()).isNotNull();
assertThat(processDataEvent.getKogitoParentProcessinstanceId()).isNull();
assertThat(processDataEvent.getKogitoRootProcessinstanceId()).isNull();
assertThat(processDataEvent.getKogitoProcessId()).isEqualTo("BusinessRuleTask");
assertThat(processDataEvent.getKogitoProcessinstanceState()).isEqualTo("2");
assertThat(processDataEvent.getSource().toString()).isEqualTo("http://myhost/BusinessRuleTask");
ProcessInstanceEventBody body = assertProcessInstanceEvent(events.get(0), "BusinessRuleTask", "Default Process", 2);
assertThat(body.getNodeInstances()).hasSize(3).extractingResultOf("getNodeType").contains("StartNode", "RuleSetNode", "EndNode");
assertThat(body.getNodeInstances()).extractingResultOf("getTriggerTime").allMatch(v -> v != null);
assertThat(body.getNodeInstances()).extractingResultOf("getLeaveTime").allMatch(v -> v != null);
assertThat(body.getVariables()).hasSize(1).containsKey("person");
assertThat(body.getVariables().get("person")).isNotNull().hasFieldOrPropertyWithValue("adult", true);
event = events.get(1);
assertThat(event).isInstanceOf(VariableInstanceDataEvent.class);
VariableInstanceDataEvent variableDataEvent = (VariableInstanceDataEvent) event;
assertThat(variableDataEvent.getKogitoProcessinstanceId()).isNotNull();
assertThat(variableDataEvent.getKogitoRootProcessId()).isNull();
assertThat(variableDataEvent.getKogitoRootProcessinstanceId()).isNull();
assertThat(variableDataEvent.getKogitoProcessId()).isEqualTo("BusinessRuleTask");
// first is event created based on process start so no node associated
VariableInstanceEventBody variableEventBody = variableDataEvent.getData();
assertThat(variableEventBody).isNotNull();
assertThat(variableEventBody.getChangeDate()).isNotNull();
assertThat(variableEventBody.getProcessInstanceId()).isEqualTo(variableDataEvent.getKogitoProcessinstanceId());
assertThat(variableEventBody.getProcessId()).isEqualTo("BusinessRuleTask");
assertThat(variableEventBody.getRootProcessId()).isNull();
assertThat(variableEventBody.getRootProcessInstanceId()).isNull();
assertThat(variableEventBody.getVariableName()).isEqualTo("person");
assertThat(variableEventBody.getVariableValue()).isNotNull();
assertThat(variableEventBody.getVariablePreviousValue()).isNull();
assertThat(variableEventBody.getChangedByNodeId()).isNull();
assertThat(variableEventBody.getChangedByNodeName()).isNull();
assertThat(variableEventBody.getChangedByNodeType()).isNull();
assertThat(variableEventBody.getChangedByUser()).isNull();
event = events.get(2);
assertThat(event).isInstanceOf(VariableInstanceDataEvent.class);
variableDataEvent = (VariableInstanceDataEvent) event;
assertThat(variableDataEvent.getKogitoProcessinstanceId()).isNotNull();
assertThat(variableDataEvent.getKogitoRootProcessId()).isNull();
assertThat(variableDataEvent.getKogitoRootProcessinstanceId()).isNull();
assertThat(variableDataEvent.getKogitoProcessId()).isEqualTo("BusinessRuleTask");
// next is event created based on business rule task so node associated
variableEventBody = variableDataEvent.getData();
assertThat(variableEventBody).isNotNull();
assertThat(variableEventBody.getChangeDate()).isNotNull();
assertThat(variableEventBody.getProcessInstanceId()).isEqualTo(variableDataEvent.getKogitoProcessinstanceId());
assertThat(variableEventBody.getProcessId()).isEqualTo("BusinessRuleTask");
assertThat(variableEventBody.getRootProcessId()).isNull();
assertThat(variableEventBody.getRootProcessInstanceId()).isNull();
assertThat(variableEventBody.getVariableName()).isEqualTo("person");
assertThat(variableEventBody.getVariableValue()).isNotNull();
assertThat(variableEventBody.getVariablePreviousValue()).isNotNull();
assertThat(variableEventBody.getChangedByNodeId()).isEqualTo("BusinessRuleTask_2");
assertThat(variableEventBody.getChangedByNodeName()).isEqualTo("Business Rule Task");
assertThat(variableEventBody.getChangedByNodeType()).isEqualTo("RuleSetNode");
assertThat(variableEventBody.getChangedByUser()).isNull();
}
use of org.kie.kogito.event.DataEvent in project kogito-runtimes by kiegroup.
the class PublishEventIT method testBasicUserTaskProcess.
@Test
public void testBasicUserTaskProcess() throws Exception {
Application app = generateCodeProcessesOnly("usertask/UserTasksProcess.bpmn2");
assertThat(app).isNotNull();
Process<? extends Model> p = app.get(Processes.class).processById("UserTasksProcess");
Model m = p.createModel();
Map<String, Object> parameters = new HashMap<>();
m.fromMap(parameters);
TestEventPublisher publisher = new TestEventPublisher();
app.unitOfWorkManager().eventManager().setService("http://myhost");
app.unitOfWorkManager().eventManager().addPublisher(publisher);
UnitOfWork uow = app.unitOfWorkManager().newUnitOfWork();
uow.start();
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start();
uow.end();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
List<DataEvent<?>> events = publisher.extract();
assertThat(events).isNotNull().hasSize(2);
ProcessInstanceEventBody body = assertProcessInstanceEvent(events.get(0), "UserTasksProcess", "UserTasksProcess", 1);
assertThat(body.getNodeInstances()).hasSize(2).extractingResultOf("getNodeType").contains("StartNode", "HumanTaskNode");
assertThat(body.getNodeInstances()).extractingResultOf("getTriggerTime").allMatch(v -> v != null);
// human task is active thus null for leave time
assertThat(body.getNodeInstances()).extractingResultOf("getLeaveTime").containsNull();
assertUserTaskInstanceEvent(events.get(1), "FirstTask", null, "1", "Ready", "UserTasksProcess", "First Task");
List<WorkItem> workItems = processInstance.workItems(SecurityPolicy.of(new StaticIdentityProvider("john")));
assertEquals(1, workItems.size());
assertEquals("FirstTask", workItems.get(0).getName());
uow = app.unitOfWorkManager().newUnitOfWork();
uow.start();
processInstance.completeWorkItem(workItems.get(0).getId(), null, SecurityPolicy.of(new StaticIdentityProvider("john")));
uow.end();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
events = publisher.extract();
assertThat(events).isNotNull().hasSize(3);
body = assertProcessInstanceEvent(events.get(0), "UserTasksProcess", "UserTasksProcess", 1);
assertThat(body.getNodeInstances()).hasSize(2).extractingResultOf("getNodeType").contains("HumanTaskNode", "HumanTaskNode");
assertThat(body.getNodeInstances()).extractingResultOf("getTriggerTime").allMatch(v -> v != null);
// human task is active thus null for leave time
assertThat(body.getNodeInstances()).extractingResultOf("getLeaveTime").containsNull();
assertUserTaskInstanceEvent(events.get(1), "SecondTask", null, "1", "Ready", "UserTasksProcess", "Second Task");
assertUserTaskInstanceEvent(events.get(2), "FirstTask", null, "1", "Completed", "UserTasksProcess", "First Task");
workItems = processInstance.workItems(SecurityPolicy.of(new StaticIdentityProvider("john")));
assertEquals(1, workItems.size());
assertEquals("SecondTask", workItems.get(0).getName());
uow = app.unitOfWorkManager().newUnitOfWork();
uow.start();
processInstance.completeWorkItem(workItems.get(0).getId(), null, SecurityPolicy.of(new StaticIdentityProvider("john")));
uow.end();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
events = publisher.extract();
assertThat(events).isNotNull().hasSize(2);
body = assertProcessInstanceEvent(events.get(0), "UserTasksProcess", "UserTasksProcess", 2);
assertThat(body.getNodeInstances()).hasSize(2).extractingResultOf("getNodeType").contains("HumanTaskNode", "EndNode");
assertThat(body.getNodeInstances()).extractingResultOf("getTriggerTime").allMatch(v -> v != null);
assertThat(body.getNodeInstances()).extractingResultOf("getLeaveTime").allMatch(v -> v != null);
assertUserTaskInstanceEvent(events.get(1), "SecondTask", null, "1", "Completed", "UserTasksProcess", "Second Task");
}
use of org.kie.kogito.event.DataEvent in project kogito-runtimes by kiegroup.
the class PublishEventIT method testBusinessRuleProcessStartToEndAbortOfUoW.
@Test
public void testBusinessRuleProcessStartToEndAbortOfUoW() throws Exception {
Map<TYPE, List<String>> resourcesTypeMap = new HashMap<>();
resourcesTypeMap.put(TYPE.PROCESS, Collections.singletonList("ruletask/BusinessRuleTask.bpmn2"));
resourcesTypeMap.put(TYPE.RULES, Collections.singletonList("ruletask/BusinessRuleTask.drl"));
Application app = generateCode(resourcesTypeMap);
assertThat(app).isNotNull();
TestEventPublisher publisher = new TestEventPublisher();
app.unitOfWorkManager().eventManager().setService("http://myhost");
app.unitOfWorkManager().eventManager().addPublisher(publisher);
UnitOfWork uow = app.unitOfWorkManager().newUnitOfWork();
uow.start();
Process<? extends Model> p = app.get(Processes.class).processById("BusinessRuleTask");
Model m = p.createModel();
m.fromMap(Collections.singletonMap("person", new Person("john", 25)));
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
Model result = (Model) processInstance.variables();
assertThat(result.toMap()).hasSize(1).containsKey("person");
assertThat(result.toMap().get("person")).isNotNull().hasFieldOrPropertyWithValue("adult", true);
uow.abort();
List<DataEvent<?>> events = publisher.extract();
assertThat(events).isNotNull().hasSize(0);
}
use of org.kie.kogito.event.DataEvent in project kogito-runtimes by kiegroup.
the class PublishEventIT method testBasicUserTaskProcessWithSecurityRoles.
@Test
public void testBasicUserTaskProcessWithSecurityRoles() throws Exception {
Application app = generateCodeProcessesOnly("usertask/UserTasksProcessWithSecurityRoles.bpmn2");
assertThat(app).isNotNull();
Process<? extends Model> p = app.get(Processes.class).processById("UserTasksProcess");
Model m = p.createModel();
Map<String, Object> parameters = new HashMap<>();
m.fromMap(parameters);
TestEventPublisher publisher = new TestEventPublisher();
app.unitOfWorkManager().eventManager().setService("http://myhost");
app.unitOfWorkManager().eventManager().addPublisher(publisher);
UnitOfWork uow = app.unitOfWorkManager().newUnitOfWork();
uow.start();
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start();
uow.end();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
List<DataEvent<?>> events = publisher.extract();
assertThat(events).isNotNull().hasSize(2);
ProcessInstanceEventBody body = assertProcessInstanceEvent(events.get(0), "UserTasksProcess", "UserTasksProcess", 1);
assertThat(body.getRoles()).hasSize(2).contains("employees", "managers");
assertThat(body.getNodeInstances()).hasSize(2).extractingResultOf("getNodeType").contains("StartNode", "HumanTaskNode");
assertThat(body.getNodeInstances()).extractingResultOf("getTriggerTime").allMatch(v -> v != null);
// human task is active thus null for leave time
assertThat(body.getNodeInstances()).extractingResultOf("getLeaveTime").containsNull();
assertUserTaskInstanceEvent(events.get(1), "FirstTask", null, "1", "Ready", "UserTasksProcess", "First Task");
}
use of org.kie.kogito.event.DataEvent in project kogito-runtimes by kiegroup.
the class PublishEventIT method testCompensationProcess.
@Test
public void testCompensationProcess() throws Exception {
Map<TYPE, List<String>> resourcesTypeMap = new HashMap<>();
resourcesTypeMap.put(TYPE.PROCESS, Collections.singletonList("compensation/compensateAll.bpmn2"));
Application app = generateCode(resourcesTypeMap);
assertThat(app).isNotNull();
TestEventPublisher publisher = new TestEventPublisher();
app.unitOfWorkManager().eventManager().setService("http://myhost");
app.unitOfWorkManager().eventManager().addPublisher(publisher);
UnitOfWork uow = app.unitOfWorkManager().newUnitOfWork();
uow.start();
Process<? extends Model> p = app.get(Processes.class).processById("compensateAll");
ProcessInstance<?> processInstance = p.createInstance(p.createModel());
processInstance.start();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
Model result = (Model) processInstance.variables();
assertThat(result.toMap()).hasSize(2).containsKeys("counter", "counter2");
uow.end();
List<DataEvent<?>> events = publisher.extract();
Optional<DataEvent<?>> event = events.stream().filter(ProcessInstanceDataEvent.class::isInstance).findFirst();
assertTrue(event.isPresent(), "There is no process instance event being published");
ProcessInstanceDataEvent processDataEvent = (ProcessInstanceDataEvent) event.orElseThrow();
assertThat(processDataEvent.getKogitoProcessinstanceId()).isNotNull();
assertThat(processDataEvent.getKogitoParentProcessinstanceId()).isNull();
assertThat(processDataEvent.getKogitoRootProcessinstanceId()).isNull();
assertThat(processDataEvent.getKogitoProcessId()).isEqualTo("compensateAll");
assertThat(processDataEvent.getKogitoProcessinstanceState()).isEqualTo("2");
assertThat(processDataEvent.getSource().toString()).isEqualTo("http://myhost/compensateAll");
ProcessInstanceEventBody body = assertProcessInstanceEvent(events.get(0), "compensateAll", "Compensate All", 2);
assertThat(body.getNodeInstances()).hasSize(9).extractingResultOf("getNodeType").contains("StartNode", "ActionNode", "BoundaryEventNode", "EndNode");
assertThat(body.getNodeInstances()).extractingResultOf("getTriggerTime").allMatch(v -> v != null);
assertThat(body.getNodeInstances()).extractingResultOf("getLeaveTime").allMatch(v -> v != null);
assertThat(body.getVariables()).hasSize(2).containsEntry("counter", 2).containsEntry("counter2", 2);
}
Aggregations