Search in sources :

Example 6 with ProcessWorkItemTransitionEvent

use of io.automatiko.engine.api.event.process.ProcessWorkItemTransitionEvent in project automatiko-engine by automatiko-io.

the class UserTaskTest method testBasicUserTaskProcessClaimAndCompletePhasesWithIdentity.

@Test
public void testBasicUserTaskProcessClaimAndCompletePhasesWithIdentity() throws Exception {
    Application app = generateCodeProcessesOnly("usertask/UserTasksProcess.bpmn2");
    assertThat(app).isNotNull();
    final List<String> workItemTransitionEvents = new ArrayList<>();
    ((DefaultProcessEventListenerConfig) app.config().process().processEventListeners()).listeners().add(new DefaultProcessEventListener() {

        @Override
        public void beforeWorkItemTransition(ProcessWorkItemTransitionEvent event) {
            workItemTransitionEvents.add("BEFORE:: " + event);
        }

        @Override
        public void afterWorkItemTransition(ProcessWorkItemTransitionEvent event) {
            workItemTransitionEvents.add("AFTER:: " + event);
        }
    });
    Process<? extends Model> p = app.processes().processById("UserTasksProcess");
    Model m = p.createModel();
    Map<String, Object> parameters = new HashMap<>();
    m.fromMap(parameters);
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    List<WorkItem> workItems = processInstance.workItems(securityPolicy);
    assertEquals(1, workItems.size());
    WorkItem wi = workItems.get(0);
    assertEquals("FirstTask", wi.getName());
    assertEquals(Active.ID, wi.getPhase());
    assertEquals(Active.STATUS, wi.getPhaseStatus());
    assertEquals(0, wi.getResults().size());
    processInstance.transitionWorkItem(workItems.get(0).getId(), new HumanTaskTransition(Claim.ID, Collections.singletonMap("test", "value"), securityPolicy));
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    workItems = processInstance.workItems(securityPolicy);
    assertEquals(1, workItems.size());
    wi = workItems.get(0);
    assertEquals("FirstTask", wi.getName());
    assertEquals(Claim.ID, wi.getPhase());
    assertEquals(Claim.STATUS, wi.getPhaseStatus());
    assertEquals(2, wi.getResults().size());
    assertEquals("value", wi.getResults().get("test"));
    assertEquals("john", wi.getResults().get("ActorId"));
    processInstance.transitionWorkItem(workItems.get(0).getId(), new HumanTaskTransition(Complete.ID, null, securityPolicy));
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    workItems = processInstance.workItems(securityPolicy);
    assertEquals(1, workItems.size());
    wi = workItems.get(0);
    assertEquals("SecondTask", wi.getName());
    assertEquals(Active.ID, wi.getPhase());
    assertEquals(Active.STATUS, wi.getPhaseStatus());
    assertEquals(0, wi.getResults().size());
    processInstance.abort();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ABORTED);
    assertThat(workItemTransitionEvents).hasSize(10);
}
Also used : HashMap(java.util.HashMap) ProcessWorkItemTransitionEvent(io.automatiko.engine.api.event.process.ProcessWorkItemTransitionEvent) ArrayList(java.util.ArrayList) WorkItem(io.automatiko.engine.api.workflow.WorkItem) HumanTaskTransition(io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskTransition) Model(io.automatiko.engine.api.Model) DefaultProcessEventListener(io.automatiko.engine.api.event.process.DefaultProcessEventListener) Application(io.automatiko.engine.api.Application) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Test(org.junit.jupiter.api.Test)

Aggregations

ProcessWorkItemTransitionEvent (io.automatiko.engine.api.event.process.ProcessWorkItemTransitionEvent)6 ArrayList (java.util.ArrayList)6 Application (io.automatiko.engine.api.Application)3 Model (io.automatiko.engine.api.Model)3 DefaultProcessEventListener (io.automatiko.engine.api.event.process.DefaultProcessEventListener)3 ProcessCompletedEvent (io.automatiko.engine.api.event.process.ProcessCompletedEvent)3 ProcessNodeLeftEvent (io.automatiko.engine.api.event.process.ProcessNodeLeftEvent)3 ProcessNodeTriggeredEvent (io.automatiko.engine.api.event.process.ProcessNodeTriggeredEvent)3 ProcessVariableChangedEvent (io.automatiko.engine.api.event.process.ProcessVariableChangedEvent)3 NodeInstance (io.automatiko.engine.api.runtime.process.NodeInstance)3 ProcessInstance (io.automatiko.engine.api.runtime.process.ProcessInstance)3 WorkItem (io.automatiko.engine.api.runtime.process.WorkItem)3 WorkUnit (io.automatiko.engine.api.uow.WorkUnit)3 WorkItem (io.automatiko.engine.api.workflow.WorkItem)3 AbstractCodegenTest (io.automatiko.engine.codegen.AbstractCodegenTest)3 HashMap (java.util.HashMap)3 List (java.util.List)3 Test (org.junit.jupiter.api.Test)3 DelayedExecution (io.automatiko.engine.api.event.process.DelayedExecution)2 ProcessEventListener (io.automatiko.engine.api.event.process.ProcessEventListener)2