use of org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener in project kogito-runtimes by kiegroup.
the class BusinessRuleTaskIT method testBasicBusinessRuleTaskControlledByUnitOfWork.
@Test
public void testBasicBusinessRuleTaskControlledByUnitOfWork() throws Exception {
Map<AbstractCodegenIT.TYPE, List<String>> resourcesTypeMap = new HashMap<>();
resourcesTypeMap.put(TYPE.PROCESS, Collections.singletonList("ruletask/BusinessRuleTask.bpmn2"));
resourcesTypeMap.put(TYPE.RULES, Collections.singletonList("ruletask/BusinessRuleTask.drl"));
Application app = generateCode(resourcesTypeMap);
assertThat(app).isNotNull();
final List<String> startedProcesses = new ArrayList<>();
// add custom event listener that collects data
app.config().get(ProcessConfig.class).processEventListeners().listeners().add(new DefaultKogitoProcessEventListener() {
@Override
public void beforeProcessStarted(ProcessStartedEvent event) {
startedProcesses.add(((KogitoProcessInstance) event.getProcessInstance()).getStringId());
}
});
UnitOfWork uow = app.unitOfWorkManager().newUnitOfWork();
uow.start();
Process<? extends Model> p = app.get(Processes.class).processById("BusinessRuleTask");
Model m = p.createModel();
m.fromMap(Collections.singletonMap("person", new Person("john", 25)));
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
Model result = (Model) processInstance.variables();
assertThat(result.toMap()).hasSize(1).containsKey("person");
assertThat(result.toMap().get("person")).isNotNull().hasFieldOrPropertyWithValue("adult", true);
// since the unit of work has not been finished yet not listeners where invoked
assertThat(startedProcesses).hasSize(0);
uow.end();
// after unit of work has been ended listeners are invoked
assertThat(startedProcesses).hasSize(1);
}
use of org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener in project kogito-runtimes by kiegroup.
the class UserTaskIT method testBasicUserTaskProcessClaimAndCompletePhasesWithIdentity.
@Test
public void testBasicUserTaskProcessClaimAndCompletePhasesWithIdentity() throws Exception {
Application app = generateCodeProcessesOnly("usertask/UserTasksProcess.bpmn2");
assertThat(app).isNotNull();
final List<String> workItemTransitionEvents = new ArrayList<>();
app.config().get(ProcessConfig.class).processEventListeners().listeners().add(new DefaultKogitoProcessEventListener() {
@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.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());
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);
}
use of org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener in project kogito-runtimes by kiegroup.
the class UserTaskIT method testBasicUserTaskProcess.
@Test
public void testBasicUserTaskProcess() throws Exception {
Application app = generateCodeProcessesOnly("usertask/UserTasksProcess.bpmn2");
assertThat(app).isNotNull();
final List<String> workItemTransitionEvents = new ArrayList<>();
app.config().get(ProcessConfig.class).processEventListeners().listeners().add(new DefaultKogitoProcessEventListener() {
@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.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(KogitoProcessInstance.STATE_ACTIVE);
List<WorkItem> workItems = processInstance.workItems(securityPolicy);
assertEquals(1, workItems.size());
assertEquals("FirstTask", workItems.get(0).getName());
processInstance.completeWorkItem(workItems.get(0).getId(), null, securityPolicy);
assertThat(processInstance.status()).isEqualTo(KogitoProcessInstance.STATE_ACTIVE);
workItems = processInstance.workItems(securityPolicy);
assertEquals(1, workItems.size());
assertEquals("SecondTask", workItems.get(0).getName());
processInstance.completeWorkItem(workItems.get(0).getId(), null, securityPolicy);
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
assertThat(workItemTransitionEvents).hasSize(8);
}
use of org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener in project kogito-runtimes by kiegroup.
the class ActivityTest method testMinimalProcessMetaData.
@Test
public void testMinimalProcessMetaData() throws Exception {
kruntime = createKogitoProcessRuntime("BPMN2-MinimalProcessMetaData.bpmn2");
final List<String> list1 = new ArrayList<>();
final List<String> list2 = new ArrayList<>();
final List<String> list3 = new ArrayList<>();
final List<String> list4 = new ArrayList<>();
kruntime.getProcessEventManager().addEventListener(new DefaultKogitoProcessEventListener() {
@Override
public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) {
logger.debug("before node");
Map<String, Object> metaData = event.getNodeInstance().getNode().getMetaData();
for (Map.Entry<String, Object> entry : metaData.entrySet()) {
logger.debug(entry.getKey() + " " + entry.getValue());
}
String customTag = (String) metaData.get("customTag");
if (customTag != null) {
list1.add(customTag);
}
String customTag2 = (String) metaData.get("customTag2");
if (customTag2 != null) {
list2.add(customTag2);
}
}
@Override
public void afterVariableChanged(ProcessVariableChangedEvent event) {
logger.debug("after variable");
VariableScope variableScope = (VariableScope) ((org.jbpm.process.core.impl.ProcessImpl) event.getProcessInstance().getProcess()).resolveContext(VariableScope.VARIABLE_SCOPE, event.getVariableId());
if (variableScope == null) {
return;
}
Map<String, Object> metaData = variableScope.findVariable(event.getVariableId()).getMetaData();
for (Map.Entry<String, Object> entry : metaData.entrySet()) {
logger.debug(entry.getKey() + " " + entry.getValue());
}
String customTag = (String) metaData.get("customTagVar");
if (customTag != null) {
list3.add(customTag);
}
}
@Override
public void afterProcessStarted(ProcessStartedEvent event) {
logger.debug("after process");
Map<String, Object> metaData = event.getProcessInstance().getProcess().getMetaData();
for (Map.Entry<String, Object> entry : metaData.entrySet()) {
logger.debug(entry.getKey() + " " + entry.getValue());
}
String customTag = (String) metaData.get("customTagProcess");
if (customTag != null) {
list4.add(customTag);
}
}
});
Map<String, Object> params = new HashMap<>();
params.put("x", "krisv");
KogitoProcessInstance processInstance = kruntime.startProcess("Minimal", params);
assertProcessInstanceCompleted(processInstance);
assertEquals(3, list1.size());
assertEquals(2, list2.size());
assertEquals(1, list3.size());
assertEquals(1, list4.size());
}
use of org.kie.kogito.internal.process.event.DefaultKogitoProcessEventListener in project kogito-runtimes by kiegroup.
the class ActivityTest method testCallActivityWithTransformation.
@Test
@Disabled("Transformer has been disabled")
public void testCallActivityWithTransformation() throws Exception {
kruntime = createKogitoProcessRuntime("BPMN2-CallActivityWithTransformation.bpmn2", "BPMN2-CallActivitySubProcess.bpmn2");
final List<KogitoProcessInstance> instances = new ArrayList<>();
kruntime.getProcessEventManager().addEventListener(new DefaultKogitoProcessEventListener() {
@Override
public void beforeProcessStarted(ProcessStartedEvent event) {
instances.add((KogitoProcessInstance) event.getProcessInstance());
}
});
Map<String, Object> params = new HashMap<>();
params.put("x", "oldValue");
KogitoProcessInstance processInstance = kruntime.startProcess("ParentProcess", params);
assertProcessInstanceCompleted(processInstance);
assertEquals(2, instances.size());
// assert variables of parent process, first in start (input transformation, then on end output transformation)
assertEquals("oldValue", ((KogitoWorkflowProcessInstance) instances.get(0)).getVariable("x"));
assertEquals("NEW VALUE", ((KogitoWorkflowProcessInstance) instances.get(0)).getVariable("y"));
// assert variables of subprocess, first in start (input transformation, then on end output transformation)
assertEquals("OLDVALUE", ((KogitoWorkflowProcessInstance) instances.get(1)).getVariable("subX"));
assertEquals("new value", ((KogitoWorkflowProcessInstance) instances.get(1)).getVariable("subY"));
}
Aggregations