Search in sources :

Example 1 with ProcessInstanceDataEvent

use of org.kie.kogito.services.event.ProcessInstanceDataEvent 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 ProcessInstanceDataEvent

use of org.kie.kogito.services.event.ProcessInstanceDataEvent 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 ProcessInstanceDataEvent

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

the class PublishEventIT method testProcessWithMilestoneEvents.

@Test
public void testProcessWithMilestoneEvents() throws Exception {
    Application app = generateCodeProcessesOnly("cases/milestones/SimpleMilestone.bpmn");
    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("TestCase.SimpleMilestone");
    ProcessInstance<?> processInstance = p.createInstance(p.createModel());
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
    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("TestCase.SimpleMilestone");
    assertThat(processDataEvent.getKogitoProcessinstanceState()).isEqualTo("2");
    assertThat(processDataEvent.getSource().toString()).isEqualTo("http://myhost/SimpleMilestone");
    Set<MilestoneEventBody> milestones = ((ProcessInstanceDataEvent) event).getData().getMilestones();
    assertThat(milestones).hasSize(2).extracting(e -> e.getName(), e -> e.getStatus()).containsExactlyInAnyOrder(tuple("AutoStartMilestone", Status.COMPLETED.name()), tuple("SimpleMilestone", Status.COMPLETED.name()));
}
Also used : UnitOfWork(org.kie.kogito.uow.UnitOfWork) ZonedDateTime(java.time.ZonedDateTime) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) UserTaskInstanceEventBody(org.kie.kogito.services.event.impl.UserTaskInstanceEventBody) HashMap(java.util.HashMap) Status(org.kie.kogito.process.flexible.ItemDescription.Status) Person(org.kie.kogito.codegen.data.Person) ArrayList(java.util.ArrayList) AbstractCodegenIT(org.kie.kogito.codegen.AbstractCodegenIT) VariableInstanceEventBody(org.kie.kogito.services.event.impl.VariableInstanceEventBody) Map(java.util.Map) UserTaskInstanceDataEvent(org.kie.kogito.services.event.UserTaskInstanceDataEvent) Process(org.kie.kogito.process.Process) ProcessInstanceDataEvent(org.kie.kogito.services.event.ProcessInstanceDataEvent) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Assertions.tuple(org.assertj.core.api.Assertions.tuple) StaticIdentityProvider(org.kie.kogito.services.identity.StaticIdentityProvider) Collection(java.util.Collection) Set(java.util.Set) MilestoneEventBody(org.kie.kogito.services.event.impl.MilestoneEventBody) ProcessInstanceEventBody(org.kie.kogito.services.event.impl.ProcessInstanceEventBody) SecurityPolicy(org.kie.kogito.auth.SecurityPolicy) Application(org.kie.kogito.Application) Test(org.junit.jupiter.api.Test) List(java.util.List) ProcessInstance(org.kie.kogito.process.ProcessInstance) Model(org.kie.kogito.Model) EventPublisher(org.kie.kogito.event.EventPublisher) ProcessError(org.kie.kogito.process.ProcessError) DataEvent(org.kie.kogito.event.DataEvent) VariableInstanceDataEvent(org.kie.kogito.services.event.VariableInstanceDataEvent) Processes(org.kie.kogito.process.Processes) Collections(java.util.Collections) WorkItem(org.kie.kogito.process.WorkItem) UnitOfWork(org.kie.kogito.uow.UnitOfWork) 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) MilestoneEventBody(org.kie.kogito.services.event.impl.MilestoneEventBody) ProcessInstanceDataEvent(org.kie.kogito.services.event.ProcessInstanceDataEvent) Application(org.kie.kogito.Application) Test(org.junit.jupiter.api.Test)

Example 4 with ProcessInstanceDataEvent

use of org.kie.kogito.services.event.ProcessInstanceDataEvent 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)

Example 5 with ProcessInstanceDataEvent

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

the class MongoDBEventPublisherTest method testPublishEvents_withTransaction.

@Test
void testPublishEvents_withTransaction() {
    ClientSession clientSession = mock(ClientSession.class);
    when(transactionManager.getClientSession()).thenReturn(clientSession);
    when(transactionManager.enabled()).thenReturn(true);
    publisher.configure();
    List<DataEvent<?>> events = new ArrayList<>();
    events.add(processInstanceDataEvent);
    events.add(userTaskInstanceDataEvent);
    events.add(variableInstanceDataEvent);
    events.add(event);
    publisher.publish(events);
    verify(mongoCollection, times(3)).insertOne(eq(clientSession), any(AbstractDataEvent.class));
    verify(mongoCollection, times(3)).deleteOne(eq(clientSession), any());
    verify(mongoCollection).insertOne(eq(clientSession), eq(processInstanceDataEvent));
    verify(mongoCollection).deleteOne(eq(clientSession), eq(Filters.eq(ID, "testProcessInstanceEvent")));
    verify(mongoCollection).insertOne(eq(clientSession), eq(userTaskInstanceDataEvent));
    verify(mongoCollection).deleteOne(eq(clientSession), eq(Filters.eq(ID, "testUserTaskInstanceEvent")));
    verify(mongoCollection).insertOne(eq(clientSession), eq(variableInstanceDataEvent));
    verify(mongoCollection).deleteOne(eq(clientSession), eq(Filters.eq(ID, "testVariableInstanceEvent")));
}
Also used : ClientSession(com.mongodb.client.ClientSession) ArrayList(java.util.ArrayList) AbstractDataEvent(org.kie.kogito.event.AbstractDataEvent) UserTaskInstanceDataEvent(org.kie.kogito.services.event.UserTaskInstanceDataEvent) DataEvent(org.kie.kogito.event.DataEvent) ProcessInstanceDataEvent(org.kie.kogito.services.event.ProcessInstanceDataEvent) VariableInstanceDataEvent(org.kie.kogito.services.event.VariableInstanceDataEvent) AbstractDataEvent(org.kie.kogito.event.AbstractDataEvent) Test(org.junit.jupiter.api.Test)

Aggregations

ProcessInstanceDataEvent (org.kie.kogito.services.event.ProcessInstanceDataEvent)11 ProcessInstanceEventBody (org.kie.kogito.services.event.impl.ProcessInstanceEventBody)9 DataEvent (org.kie.kogito.event.DataEvent)8 UserTaskInstanceDataEvent (org.kie.kogito.services.event.UserTaskInstanceDataEvent)8 VariableInstanceDataEvent (org.kie.kogito.services.event.VariableInstanceDataEvent)8 HashMap (java.util.HashMap)7 Test (org.junit.jupiter.api.Test)7 ArrayList (java.util.ArrayList)6 Application (org.kie.kogito.Application)6 Model (org.kie.kogito.Model)6 Processes (org.kie.kogito.process.Processes)6 UnitOfWork (org.kie.kogito.uow.UnitOfWork)6 List (java.util.List)5 Person (org.kie.kogito.codegen.data.Person)3 Collection (java.util.Collection)2 Map (java.util.Map)2 Set (java.util.Set)2 VariableInstanceEventBody (org.kie.kogito.services.event.impl.VariableInstanceEventBody)2 ClientSession (com.mongodb.client.ClientSession)1 ZonedDateTime (java.time.ZonedDateTime)1