Search in sources :

Example 1 with ProcessInstanceEventBody

use of org.kie.kogito.services.event.impl.ProcessInstanceEventBody in project kogito-runtimes by kiegroup.

the class PublishEventIT method testExclusiveGatewayStartToEnd.

@Test
public void testExclusiveGatewayStartToEnd() throws Exception {
    Application app = generateCodeProcessesOnly("gateway/ExclusiveSplit.bpmn2");
    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("ExclusiveSplit");
    Map<String, Object> params = new HashMap<>();
    params.put("x", "First");
    params.put("y", "None");
    Model m = p.createModel();
    m.fromMap(params);
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
    Model result = (Model) processInstance.variables();
    assertThat(result.toMap()).hasSize(2).containsKeys("x", "y");
    uow.end();
    List<DataEvent<?>> events = publisher.extract();
    assertThat(events).isNotNull().hasSize(1);
    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("ExclusiveSplit");
    assertThat(processDataEvent.getKogitoProcessinstanceState()).isEqualTo("2");
    ProcessInstanceEventBody body = assertProcessInstanceEvent(events.get(0), "ExclusiveSplit", "Test", 2);
    assertThat(body.getNodeInstances()).hasSize(6).extractingResultOf("getNodeType").contains("StartNode", "ActionNode", "Split", "Join", "EndNode", "WorkItemNode");
    assertThat(body.getNodeInstances()).extractingResultOf("getTriggerTime").allMatch(v -> v != null);
    assertThat(body.getNodeInstances()).extractingResultOf("getLeaveTime").allMatch(v -> v != null);
}
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) Model(org.kie.kogito.Model) ProcessInstanceDataEvent(org.kie.kogito.services.event.ProcessInstanceDataEvent) Application(org.kie.kogito.Application) Test(org.junit.jupiter.api.Test)

Example 2 with ProcessInstanceEventBody

use of org.kie.kogito.services.event.impl.ProcessInstanceEventBody in project kogito-runtimes by kiegroup.

the class PublishEventIT method assertProcessInstanceEvent.

/*
     * Helper methods
     */
protected ProcessInstanceEventBody assertProcessInstanceEvent(DataEvent<?> event, String processId, String processName, Integer state) {
    assertThat(event).isInstanceOf(ProcessInstanceDataEvent.class);
    ProcessInstanceEventBody body = ((ProcessInstanceDataEvent) event).getData();
    assertThat(body).isNotNull();
    assertThat(body.getId()).isNotNull();
    assertThat(body.getStartDate()).isNotNull();
    if (state == ProcessInstance.STATE_ACTIVE || state == ProcessInstance.STATE_ERROR) {
        assertThat(body.getEndDate()).isNull();
    } else {
        assertThat(body.getEndDate()).isNotNull();
    }
    assertThat(body.getParentInstanceId()).isNull();
    assertThat(body.getRootInstanceId()).isNull();
    assertThat(body.getProcessId()).isEqualTo(processId);
    assertThat(body.getProcessName()).isEqualTo(processName);
    assertThat(body.getState()).isEqualTo(state);
    assertThat(event.getSource().toString()).isEqualTo("http://myhost/" + processId);
    assertThat(event.getTime()).isBeforeOrEqualTo(ZonedDateTime.now().toOffsetDateTime());
    assertThat(((ProcessInstanceDataEvent) event).getKogitoAddons()).isEqualTo("test");
    return body;
}
Also used : ProcessInstanceEventBody(org.kie.kogito.services.event.impl.ProcessInstanceEventBody) ProcessInstanceDataEvent(org.kie.kogito.services.event.ProcessInstanceDataEvent)

Example 3 with ProcessInstanceEventBody

use of org.kie.kogito.services.event.impl.ProcessInstanceEventBody in project kogito-runtimes by kiegroup.

the class PublishEventIT method testBasicUserTaskProcessAbort.

@Test
public void testBasicUserTaskProcessAbort() 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.abort();
    uow.end();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ABORTED);
    events = publisher.extract();
    assertThat(events).isNotNull().hasSize(2);
    body = assertProcessInstanceEvent(events.get(0), "UserTasksProcess", "UserTasksProcess", ProcessInstance.STATE_ABORTED);
    assertThat(body.getNodeInstances()).hasSize(1).extractingResultOf("getNodeType").contains("HumanTaskNode");
    assertThat(body.getNodeInstances()).extractingResultOf("getTriggerTime").allMatch(v -> v != null);
    assertThat(body.getNodeInstances()).extractingResultOf("getLeaveTime").allMatch(v -> v != null);
    assertUserTaskInstanceEvent(events.get(1), "FirstTask", null, "1", "Aborted", "UserTasksProcess", "First Task");
}
Also used : StaticIdentityProvider(org.kie.kogito.services.identity.StaticIdentityProvider) 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) WorkItem(org.kie.kogito.process.WorkItem) Model(org.kie.kogito.Model) Application(org.kie.kogito.Application) Test(org.junit.jupiter.api.Test)

Example 4 with ProcessInstanceEventBody

use of org.kie.kogito.services.event.impl.ProcessInstanceEventBody in project kogito-runtimes by kiegroup.

the class PublishEventIT method testServiceTaskProcessWithError.

@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testServiceTaskProcessWithError() throws Exception {
    Application app = generateCodeProcessesOnly("servicetask/ServiceProcessDifferentOperations.bpmn2");
    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("ServiceProcessDifferentOperations");
    Model m = p.createModel();
    Map<String, Object> parameters = new HashMap<>();
    m.fromMap(parameters);
    ProcessInstance processInstance = p.createInstance(m);
    processInstance.start();
    uow.end();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ERROR);
    List<DataEvent<?>> events = publisher.extract();
    assertThat(events).isNotNull().hasSize(1);
    ProcessInstanceEventBody body = assertProcessInstanceEvent(events.get(0), "ServiceProcessDifferentOperations", "Service Process", 5);
    assertThat(body.getNodeInstances()).hasSize(2).extractingResultOf("getNodeType").contains("StartNode", "WorkItemNode");
    assertThat(body.getNodeInstances()).extractingResultOf("getTriggerTime").allMatch(v -> v != null);
    // human task is active thus null for leave time
    assertThat(body.getNodeInstances()).extractingResultOf("getLeaveTime").containsNull();
    assertThat(body.getError()).isNotNull();
    assertThat(body.getError().getErrorMessage()).contains("java.lang.NullPointerException");
    assertThat(body.getError().getNodeDefinitionId()).isEqualTo("_38E04E27-3CCA-47F9-927B-E37DC4B8CE25");
    parameters.put("s", "john");
    m.fromMap(parameters);
    uow = app.unitOfWorkManager().newUnitOfWork();
    uow.start();
    processInstance.updateVariables(m);
    uow.end();
    events = publisher.extract();
    assertThat(events).isNotNull().hasSize(1);
    body = assertProcessInstanceEvent(events.get(0), "ServiceProcessDifferentOperations", "Service Process", 5);
    assertThat(body.getError()).isNotNull();
    assertThat(body.getError().getErrorMessage()).contains("java.lang.NullPointerException");
    assertThat(body.getError().getNodeDefinitionId()).isEqualTo("_38E04E27-3CCA-47F9-927B-E37DC4B8CE25");
    uow = app.unitOfWorkManager().newUnitOfWork();
    uow.start();
    if (processInstance.error().isPresent()) {
        ((ProcessError) processInstance.error().get()).retrigger();
    }
    uow.end();
    events = publisher.extract();
    assertThat(events).isNotNull().hasSize(1);
    body = assertProcessInstanceEvent(events.get(0), "ServiceProcessDifferentOperations", "Service Process", 2);
    assertThat(body.getError()).isNull();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
    Model result = (Model) processInstance.variables();
    assertThat(result.toMap()).hasSize(1).containsKeys("s");
    assertThat(result.toMap().get("s")).isNotNull().isEqualTo("Goodbye Hello john!!");
}
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) ProcessError(org.kie.kogito.process.ProcessError) Model(org.kie.kogito.Model) ProcessInstance(org.kie.kogito.process.ProcessInstance) Application(org.kie.kogito.Application) Test(org.junit.jupiter.api.Test)

Example 5 with ProcessInstanceEventBody

use of org.kie.kogito.services.event.impl.ProcessInstanceEventBody in project kogito-runtimes by kiegroup.

the class ProcessInstanceDataEventCodecTest method setUp.

@BeforeEach
void setUp() {
    codec = new ProcessInstanceDataEventCodec();
    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");
    metaData.put(ProcessInstanceEventBody.PARENT_ID_META_DATA, "testKogitoParentProcessinstanceId");
    metaData.put(ProcessInstanceEventBody.STATE_META_DATA, "testKogitoProcessinstanceState");
    ProcessInstanceEventBody body = ProcessInstanceEventBody.create().id("testId").parentInstanceId("testKogitoParentProcessinstanceId").rootInstanceId("testKogitoRootProcessinstanceId").processId("testKogitoProcessId").rootProcessId("testKogitoRootProcessId").processName("testProcessName").startDate(new Date()).endDate(new Date()).state(1).businessKey("testBusinessKey").error(ProcessErrorEventBody.create().errorMessage("testErrorMessage").nodeDefinitionId("testNodeDefinitionId").build()).nodeInstance(NodeInstanceEventBody.create().id("testId").nodeId("testNodeId").nodeDefinitionId("testNodeDefinitionId").nodeName("testNodeName").nodeType("testNodeType").triggerTime(new Date()).leaveTime(new Date()).build()).variables(Collections.singletonMap("testVariableKey", "testVariableValue")).roles("testRole").milestones(Collections.singleton(MilestoneEventBody.create().id("testId").name("testName").status("testStatus").build())).build();
    event = new ProcessInstanceDataEvent(source, kogitoAddons, metaData, body);
}
Also used : HashMap(java.util.HashMap) ProcessInstanceEventBody(org.kie.kogito.services.event.impl.ProcessInstanceEventBody) BsonString(org.bson.BsonString) ProcessInstanceDataEvent(org.kie.kogito.services.event.ProcessInstanceDataEvent) Date(java.util.Date) BeforeEach(org.junit.jupiter.api.BeforeEach)

Aggregations

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