Search in sources :

Example 1 with VariableInstanceEventBody

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);
}
Also used : HashMap(java.util.HashMap) VariableInstanceDataEvent(org.kie.kogito.services.event.VariableInstanceDataEvent) BsonString(org.bson.BsonString) VariableInstanceEventBody(org.kie.kogito.services.event.impl.VariableInstanceEventBody) Date(java.util.Date) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with VariableInstanceEventBody

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();
}
Also used : UnitOfWork(org.kie.kogito.uow.UnitOfWork) HashMap(java.util.HashMap) ProcessInstanceEventBody(org.kie.kogito.services.event.impl.ProcessInstanceEventBody) UserTaskInstanceDataEvent(org.kie.kogito.services.event.UserTaskInstanceDataEvent) ProcessInstanceDataEvent(org.kie.kogito.services.event.ProcessInstanceDataEvent) DataEvent(org.kie.kogito.event.DataEvent) VariableInstanceDataEvent(org.kie.kogito.services.event.VariableInstanceDataEvent) Processes(org.kie.kogito.process.Processes) VariableInstanceDataEvent(org.kie.kogito.services.event.VariableInstanceDataEvent) Model(org.kie.kogito.Model) ArrayList(java.util.ArrayList) List(java.util.List) ProcessInstanceDataEvent(org.kie.kogito.services.event.ProcessInstanceDataEvent) Application(org.kie.kogito.Application) Person(org.kie.kogito.codegen.data.Person) VariableInstanceEventBody(org.kie.kogito.services.event.impl.VariableInstanceEventBody) Test(org.junit.jupiter.api.Test)

Aggregations

HashMap (java.util.HashMap)2 VariableInstanceDataEvent (org.kie.kogito.services.event.VariableInstanceDataEvent)2 VariableInstanceEventBody (org.kie.kogito.services.event.impl.VariableInstanceEventBody)2 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 List (java.util.List)1 BsonString (org.bson.BsonString)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Test (org.junit.jupiter.api.Test)1 Application (org.kie.kogito.Application)1 Model (org.kie.kogito.Model)1 Person (org.kie.kogito.codegen.data.Person)1 DataEvent (org.kie.kogito.event.DataEvent)1 Processes (org.kie.kogito.process.Processes)1 ProcessInstanceDataEvent (org.kie.kogito.services.event.ProcessInstanceDataEvent)1 UserTaskInstanceDataEvent (org.kie.kogito.services.event.UserTaskInstanceDataEvent)1 ProcessInstanceEventBody (org.kie.kogito.services.event.impl.ProcessInstanceEventBody)1 UnitOfWork (org.kie.kogito.uow.UnitOfWork)1