Search in sources :

Example 6 with WorkItem

use of org.kie.kogito.process.WorkItem in project kogito-runtimes by kiegroup.

the class AbstractProcessInstancesIT method testBasicTaskFlow.

@Test
void testBasicTaskFlow() {
    var factory = new TestProcessInstancesFactory(getDataSource(), false);
    BpmnProcess process = createProcess(factory, "BPMN2-UserTask.bpmn2");
    ProcessInstance<BpmnVariables> processInstance = process.createInstance(BpmnVariables.create(Collections.singletonMap("test", "test")));
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(STATE_ACTIVE);
    assertThat(processInstance.description()).isEqualTo("User Task");
    JDBCProcessInstances processInstances = (JDBCProcessInstances) process.instances();
    assertThat(processInstances.size()).isOne();
    assertThat(processInstances.exists(processInstance.id())).isTrue();
    verify(processInstances).create(any(), any());
    String testVar = (String) processInstance.variables().get("test");
    assertThat(testVar).isEqualTo("test");
    assertThat(processInstance.description()).isEqualTo("User Task");
    assertThat(process.instances().values().iterator().next().workItems(securityPolicy)).hasSize(1);
    WorkItem workItem = processInstance.workItems(securityPolicy).get(0);
    assertThat(workItem).isNotNull();
    assertThat(workItem.getParameters()).containsEntry("ActorId", "john");
    processInstance.completeWorkItem(workItem.getId(), null, securityPolicy);
    assertThat(processInstance.status()).isEqualTo(STATE_COMPLETED);
    processInstances = (JDBCProcessInstances) process.instances();
    verify(processInstances, times(2)).remove(processInstance.id());
    assertThat(processInstances.size()).isZero();
    assertThat(process.instances().values()).isEmpty();
}
Also used : JDBCProcessInstances(org.kie.kogito.persistence.jdbc.JDBCProcessInstances) BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) WorkItem(org.kie.kogito.process.WorkItem) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Example 7 with WorkItem

use of org.kie.kogito.process.WorkItem 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.event.process.ProcessInstanceEventBody) UserTaskInstanceDataEvent(org.kie.kogito.event.process.UserTaskInstanceDataEvent) VariableInstanceDataEvent(org.kie.kogito.event.process.VariableInstanceDataEvent) ProcessInstanceDataEvent(org.kie.kogito.event.process.ProcessInstanceDataEvent) DataEvent(org.kie.kogito.event.DataEvent) 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 8 with WorkItem

use of org.kie.kogito.process.WorkItem in project kogito-runtimes by kiegroup.

the class SignalEventIT method testIntermediateSignalEventWithData.

@Test
public void testIntermediateSignalEventWithData() throws Exception {
    Map<TYPE, List<String>> resourcesTypeMap = new HashMap<>();
    resourcesTypeMap.put(TYPE.PROCESS, Collections.singletonList("signalevent/IntermediateCatchEventSignal.bpmn2"));
    resourcesTypeMap.put(TYPE.RULES, Collections.singletonList("ruletask/BusinessRuleTask.drl"));
    Application app = generateCode(resourcesTypeMap);
    assertThat(app).isNotNull();
    Process<? extends Model> p = app.get(Processes.class).processById("IntermediateCatchEventSignal");
    Model m = p.createModel();
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    Set<EventDescription<?>> eventDescriptions = processInstance.events();
    assertThat(eventDescriptions).hasSize(1).extracting("event").contains("workItemCompleted");
    assertThat(eventDescriptions).extracting("eventType").contains("workItem");
    assertThat(eventDescriptions).extracting("processInstanceId").contains(processInstance.id());
    List<WorkItem> workItems = processInstance.workItems();
    assertThat(workItems).hasSize(1);
    processInstance.completeWorkItem(workItems.get(0).getId(), null);
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    eventDescriptions = processInstance.events();
    assertThat(eventDescriptions).hasSize(1).extracting("event").contains("MyMessage");
    assertThat(eventDescriptions).extracting("eventType").contains("signal");
    assertThat(eventDescriptions).extracting("processInstanceId").contains(processInstance.id());
    processInstance.send(Sig.of("MyMessage", "test"));
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
    Model result = (Model) processInstance.variables();
    assertThat(result.toMap()).hasSize(2).containsKey("x");
    assertThat(result.toMap().get("x")).isEqualTo("test");
    assertThat(p.instances().size()).isZero();
}
Also used : HashMap(java.util.HashMap) Processes(org.kie.kogito.process.Processes) WorkItem(org.kie.kogito.process.WorkItem) Model(org.kie.kogito.Model) List(java.util.List) Application(org.kie.kogito.Application) EventDescription(org.kie.kogito.process.EventDescription) Test(org.junit.jupiter.api.Test)

Example 9 with WorkItem

use of org.kie.kogito.process.WorkItem in project kogito-runtimes by kiegroup.

the class UserTaskIT method testBasicUserTaskProcessReleaseAndCompletePhases.

@Test
public void testBasicUserTaskProcessReleaseAndCompletePhases() 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);
    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());
    final String wiId = wi.getId();
    assertThrows(InvalidTransitionException.class, () -> processInstance.transitionWorkItem(wiId, new HumanTaskTransition(Release.ID, null, 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(Active.ID, wi.getPhase());
    assertEquals(Active.STATUS, wi.getPhaseStatus());
    assertEquals(0, wi.getResults().size());
    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);
}
Also used : HumanTaskTransition(org.jbpm.process.instance.impl.humantask.HumanTaskTransition) HashMap(java.util.HashMap) Model(org.kie.kogito.Model) Processes(org.kie.kogito.process.Processes) Application(org.kie.kogito.Application) WorkItem(org.kie.kogito.process.WorkItem) Test(org.junit.jupiter.api.Test)

Example 10 with WorkItem

use of org.kie.kogito.process.WorkItem in project kogito-runtimes by kiegroup.

the class UserTaskIT method testBasicUserTaskProcessPhases.

@Test
public void testBasicUserTaskProcessPhases() 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);
    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());
    String workItemId = workItems.get(0).getId();
    processInstance.transitionWorkItem(workItemId, 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());
    processInstance.transitionWorkItem(workItems.get(0).getId(), new HumanTaskTransition(Complete.ID, null, securityPolicy));
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
}
Also used : HumanTaskTransition(org.jbpm.process.instance.impl.humantask.HumanTaskTransition) HashMap(java.util.HashMap) Model(org.kie.kogito.Model) Processes(org.kie.kogito.process.Processes) Application(org.kie.kogito.Application) WorkItem(org.kie.kogito.process.WorkItem) Test(org.junit.jupiter.api.Test)

Aggregations

WorkItem (org.kie.kogito.process.WorkItem)41 Test (org.junit.jupiter.api.Test)38 HashMap (java.util.HashMap)27 Model (org.kie.kogito.Model)26 Application (org.kie.kogito.Application)24 Processes (org.kie.kogito.process.Processes)24 BpmnProcess (org.kie.kogito.process.bpmn2.BpmnProcess)14 BpmnVariables (org.kie.kogito.process.bpmn2.BpmnVariables)14 HumanTaskTransition (org.jbpm.process.instance.impl.humantask.HumanTaskTransition)11 StaticIdentityProvider (org.kie.kogito.services.identity.StaticIdentityProvider)9 ArrayList (java.util.ArrayList)7 ClassPathResource (org.drools.util.io.ClassPathResource)7 SecurityPolicy (org.kie.kogito.auth.SecurityPolicy)5 List (java.util.List)4 Person (org.kie.kogito.codegen.data.Person)3 ProcessConfig (org.kie.kogito.process.ProcessConfig)3 UnitOfWork (org.kie.kogito.uow.UnitOfWork)3 Optional (java.util.Optional)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 ActionNode (org.jbpm.workflow.core.node.ActionNode)2