use of org.kie.kogito.services.event.impl.VariableInstanceEventBody in project kogito-runtimes by kiegroup.
the class VariableInstanceDataEventCodecTest method setUp.
@BeforeEach
void setUp() {
codec = new VariableInstanceDataEventCodec();
String source = "testSource";
String kogitoAddons = "testKogitoAddons";
Map<String, String> metaData = new HashMap<>();
metaData.put(ProcessInstanceEventBody.ID_META_DATA, "testKogitoProcessinstanceId");
metaData.put(ProcessInstanceEventBody.ROOT_ID_META_DATA, "testKogitoRootProcessinstanceId");
metaData.put(ProcessInstanceEventBody.PROCESS_ID_META_DATA, "testKogitoProcessId");
metaData.put(ProcessInstanceEventBody.ROOT_PROCESS_ID_META_DATA, "testKogitoRootProcessId");
VariableInstanceEventBody body = VariableInstanceEventBody.create().changeDate(new Date()).changedByNodeId("testChangedByNodeId").changedByNodeName("testChangedByNodeName").changedByNodeType("testChangedByNodeType").changedByUser("testChangedByUser").processId("testKogitoProcessId").processInstanceId("testKogitoProcessinstanceId").rootProcessId("testKogitoRootProcessId").rootProcessInstanceId("testKogitoRootProcessinstanceId").variableName("testVariableName").variablePreviousValue("testVariablePreviousValue").variableValue("testVariableValue").build();
event = new VariableInstanceDataEvent(source, kogitoAddons, metaData, body);
}
use of org.kie.kogito.services.event.impl.VariableInstanceEventBody 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();
}
Aggregations