use of io.automatiko.engine.api.event.process.DefaultProcessEventListener in project automatiko-engine by automatiko-io.
the class UserTaskTest 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().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());
assertEquals("FirstTask", workItems.get(0).getName());
processInstance.completeWorkItem(workItems.get(0).getId(), null, securityPolicy);
assertThat(processInstance.status()).isEqualTo(ProcessInstance.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 io.automatiko.engine.api.event.process.DefaultProcessEventListener in project automatiko-engine by automatiko-io.
the class VariableTagsTest method testProcessWithCustomVariableTag.
@Test
public void testProcessWithCustomVariableTag() throws Exception {
TestWorkItemHandler workItemHandler = new TestWorkItemHandler("Human Task");
DefaultProcessEventListener listener = new DefaultProcessEventListener() {
@Override
public void beforeVariableChanged(ProcessVariableChangedEvent event) {
if (event.hasTag("onlyAdmin")) {
throw new VariableViolationException(event.getProcessInstance().getId(), event.getVariableId(), "Variable can only be set by admins");
}
}
};
ProcessConfig config = config(Collections.singletonList(workItemHandler), Collections.singletonList(listener));
BpmnProcess process = create(config, "variable-tags/approval-with-custom-variable-tags.bpmn2");
Map<String, Object> parameters = new HashMap<>();
parameters.put("approver", "john");
assertThrows(VariableViolationException.class, () -> process.createInstance(BpmnVariables.create(parameters)));
}
use of io.automatiko.engine.api.event.process.DefaultProcessEventListener in project automatiko-engine by automatiko-io.
the class ActivityTest method testMinimalProcessMetaData.
@Test
public void testMinimalProcessMetaData() throws Exception {
final List<String> list1 = new ArrayList<String>();
final List<String> list2 = new ArrayList<String>();
final List<String> list3 = new ArrayList<String>();
final List<String> list4 = new ArrayList<String>();
DefaultProcessEventListener listener = new DefaultProcessEventListener() {
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);
}
}
public void afterVariableChanged(ProcessVariableChangedEvent event) {
logger.debug("after variable");
VariableScope variableScope = (VariableScope) ((io.automatiko.engine.workflow.base.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);
}
}
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);
}
}
};
ProcessConfig config = config(listener);
BpmnProcess process = create(config, "BPMN2-MinimalProcessMetaData.bpmn2");
Map<String, Object> params = new HashMap<String, Object>();
params.put("x", "krisv");
ProcessInstance<BpmnVariables> instance = process.createInstance(BpmnVariables.create(params));
instance.start();
assertEquals(STATE_COMPLETED, instance.status());
assertEquals(3, list1.size());
assertEquals(2, list2.size());
assertEquals(1, list3.size());
assertEquals(1, list4.size());
}
use of io.automatiko.engine.api.event.process.DefaultProcessEventListener in project automatiko-engine by automatiko-io.
the class UserTaskTest method testBasicUserTaskProcessVersioned.
@Test
public void testBasicUserTaskProcessVersioned() throws Exception {
Application app = generateCodeProcessesOnly("usertask/UserTasksProcessVersion.bpmn2", "usertask/UserTasksProcessVersion2.bpmn2");
assertThat(app).isNotNull();
final List<String> workItemTransitionEvents = new ArrayList<>();
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);
}
});
// verify that both versions have corresponding process definitions
assertThat(app.processes().processById("UserTasksProcess_2")).isNotNull();
Process<? extends Model> p = app.processes().processById("UserTasksProcess_1");
assertThat(p).isNotNull();
// verify that both version have corresponding data model classes
Class<?> model1Class = Class.forName("org.kie.kogito.test.UserTasksProcess_1Model", true, testClassLoader());
assertNotNull(model1Class);
Class<?> model2Class = Class.forName("org.kie.kogito.test.UserTasksProcess_2Model", true, testClassLoader());
assertNotNull(model2Class);
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());
assertEquals("FirstTask", workItems.get(0).getName());
processInstance.completeWorkItem(workItems.get(0).getId(), null, securityPolicy);
assertThat(processInstance.status()).isEqualTo(ProcessInstance.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 io.automatiko.engine.api.event.process.DefaultProcessEventListener 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);
}
Aggregations