Search in sources :

Example 1 with ProcessInstanceEventBody

use of io.automatiko.engine.services.event.impl.ProcessInstanceEventBody in project automatiko-engine by automatiko-io.

the class PublishEventTest method testBasicUserTaskProcessWithSecurityRoles.

@Test
public void testBasicUserTaskProcessWithSecurityRoles() throws Exception {
    Application app = generateCodeProcessesOnly("usertask/UserTasksProcessWithSecurityRoles.bpmn2");
    assertThat(app).isNotNull();
    Process<? extends Model> p = app.processes().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
    assertThat(body.getNodeInstances()).extractingResultOf("getLeaveTime").containsNull();
    // thus null for leave
    // time
    assertUserTaskInstanceEvent(events.get(1), "First Task", null, "1", "Ready", "UserTasksProcess");
}
Also used : UnitOfWork(io.automatiko.engine.api.uow.UnitOfWork) HashMap(java.util.HashMap) ProcessInstanceEventBody(io.automatiko.engine.services.event.impl.ProcessInstanceEventBody) DataEvent(io.automatiko.engine.api.event.DataEvent) UserTaskInstanceDataEvent(io.automatiko.engine.services.event.UserTaskInstanceDataEvent) ProcessInstanceDataEvent(io.automatiko.engine.services.event.ProcessInstanceDataEvent) Model(io.automatiko.engine.api.Model) Application(io.automatiko.engine.api.Application) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Test(org.junit.jupiter.api.Test)

Example 2 with ProcessInstanceEventBody

use of io.automatiko.engine.services.event.impl.ProcessInstanceEventBody in project automatiko-engine by automatiko-io.

the class PublishEventTest method assertProcessInstanceEventWithParentId.

protected ProcessInstanceEventBody assertProcessInstanceEventWithParentId(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) {
        assertThat(body.getEndDate()).isNull();
    } else {
        assertThat(body.getEndDate()).isNotNull();
    }
    assertThat(body.getParentInstanceId()).isNotNull();
    assertThat(body.getRootInstanceId()).isNotNull();
    assertThat(body.getProcessId()).isEqualTo(processId);
    assertThat(body.getProcessName()).isEqualTo(processName);
    assertThat(body.getState()).isEqualTo(state);
    return body;
}
Also used : ProcessInstanceEventBody(io.automatiko.engine.services.event.impl.ProcessInstanceEventBody) ProcessInstanceDataEvent(io.automatiko.engine.services.event.ProcessInstanceDataEvent)

Example 3 with ProcessInstanceEventBody

use of io.automatiko.engine.services.event.impl.ProcessInstanceEventBody in project automatiko-engine by automatiko-io.

the class PublishEventTest 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.processes().processById("ServiceProcessDifferentOperations_1_0");
    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
    assertThat(body.getNodeInstances()).extractingResultOf("getLeaveTime").containsNull();
    // thus null for leave
    // time
    assertThat(body.getErrors()).hasSize(1);
    assertThat(body.getErrors().get(0).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.getErrors()).hasSize(1);
    assertThat(body.getErrors().get(0).getNodeDefinitionId()).isEqualTo("_38E04E27-3CCA-47F9-927B-E37DC4B8CE25");
    uow = app.unitOfWorkManager().newUnitOfWork();
    uow.start();
    if (processInstance.errors().isPresent()) {
        ((ProcessErrors) processInstance.errors().get()).retrigger();
    }
    uow.end();
    events = publisher.extract();
    assertThat(events).isNotNull().hasSize(1);
    body = assertProcessInstanceEvent(events.get(0), "ServiceProcessDifferentOperations", "Service Process", 2);
    assertThat(body.getErrors()).isEmpty();
    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(io.automatiko.engine.api.uow.UnitOfWork) HashMap(java.util.HashMap) ProcessInstanceEventBody(io.automatiko.engine.services.event.impl.ProcessInstanceEventBody) DataEvent(io.automatiko.engine.api.event.DataEvent) UserTaskInstanceDataEvent(io.automatiko.engine.services.event.UserTaskInstanceDataEvent) ProcessInstanceDataEvent(io.automatiko.engine.services.event.ProcessInstanceDataEvent) ProcessErrors(io.automatiko.engine.api.workflow.ProcessErrors) Model(io.automatiko.engine.api.Model) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) Application(io.automatiko.engine.api.Application) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Test(org.junit.jupiter.api.Test)

Example 4 with ProcessInstanceEventBody

use of io.automatiko.engine.services.event.impl.ProcessInstanceEventBody in project automatiko-engine by automatiko-io.

the class PublishEventTest 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()).isEqualTo("http://myhost/" + processId);
    assertThat(event.getTime()).doesNotContain("[");
    return body;
}
Also used : ProcessInstanceEventBody(io.automatiko.engine.services.event.impl.ProcessInstanceEventBody) ProcessInstanceDataEvent(io.automatiko.engine.services.event.ProcessInstanceDataEvent)

Example 5 with ProcessInstanceEventBody

use of io.automatiko.engine.services.event.impl.ProcessInstanceEventBody in project automatiko-engine by automatiko-io.

the class PublishEventTest 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.processes().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);
    ProcessInstanceEventBody body = assertProcessInstanceEvent(events.get(0), "ExclusiveSplit", "Basic process with gateway decision", 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(io.automatiko.engine.api.uow.UnitOfWork) HashMap(java.util.HashMap) ProcessInstanceEventBody(io.automatiko.engine.services.event.impl.ProcessInstanceEventBody) DataEvent(io.automatiko.engine.api.event.DataEvent) UserTaskInstanceDataEvent(io.automatiko.engine.services.event.UserTaskInstanceDataEvent) ProcessInstanceDataEvent(io.automatiko.engine.services.event.ProcessInstanceDataEvent) Model(io.automatiko.engine.api.Model) Application(io.automatiko.engine.api.Application) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Test(org.junit.jupiter.api.Test)

Aggregations

ProcessInstanceDataEvent (io.automatiko.engine.services.event.ProcessInstanceDataEvent)8 ProcessInstanceEventBody (io.automatiko.engine.services.event.impl.ProcessInstanceEventBody)8 Application (io.automatiko.engine.api.Application)6 Model (io.automatiko.engine.api.Model)6 DataEvent (io.automatiko.engine.api.event.DataEvent)6 UnitOfWork (io.automatiko.engine.api.uow.UnitOfWork)6 AbstractCodegenTest (io.automatiko.engine.codegen.AbstractCodegenTest)6 UserTaskInstanceDataEvent (io.automatiko.engine.services.event.UserTaskInstanceDataEvent)6 HashMap (java.util.HashMap)6 Test (org.junit.jupiter.api.Test)6 WorkItem (io.automatiko.engine.api.workflow.WorkItem)3 StaticIdentityProvider (io.automatiko.engine.services.identity.StaticIdentityProvider)3 ProcessErrors (io.automatiko.engine.api.workflow.ProcessErrors)1 ProcessInstance (io.automatiko.engine.api.workflow.ProcessInstance)1