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();
}
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");
}
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();
}
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);
}
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);
}
Aggregations