use of io.automatiko.engine.workflow.bpmn2.BpmnVariables in project automatiko-engine by automatiko-io.
the class VariableTagsTest method testProcessWithReadonlyVariable.
@Test
public void testProcessWithReadonlyVariable() throws Exception {
TestWorkItemHandler workItemHandler = new TestWorkItemHandler("Human Task");
ProcessConfig config = config(workItemHandler);
BpmnProcess process = create(config, "variable-tags/approval-with-readonly-variable-tags.bpmn2");
Map<String, Object> parameters = new HashMap<>();
parameters.put("approver", "john");
ProcessInstance<BpmnVariables> instance = process.createInstance(BpmnVariables.create(parameters));
instance.start();
assertEquals(STATE_ACTIVE, instance.status());
WorkItem workItem = workItemHandler.getWorkItem();
assertNotNull(workItem);
assertThrows(VariableViolationException.class, () -> instance.completeWorkItem(workItem.getId(), Collections.singletonMap("ActorId", "john")));
instance.abort();
assertEquals(STATE_ABORTED, instance.status());
}
use of io.automatiko.engine.workflow.bpmn2.BpmnVariables in project automatiko-engine by automatiko-io.
the class ActivityTest method testMinimalProcess.
@Test
public void testMinimalProcess() throws Exception {
BpmnProcess process = create("BPMN2-MinimalProcess.bpmn2");
ProcessInstance<BpmnVariables> instance = process.createInstance(BpmnVariables.create());
instance.start();
assertEquals(STATE_COMPLETED, instance.status());
}
use of io.automatiko.engine.workflow.bpmn2.BpmnVariables 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.workflow.bpmn2.BpmnVariables in project automatiko-engine by automatiko-io.
the class FileSystemProcessInstancesTest method testBasicFlowControlledByUnitOfWork.
@Test
void testBasicFlowControlledByUnitOfWork() {
UnitOfWorkManager uowManager = new DefaultUnitOfWorkManager(new CollectingUnitOfWorkFactory());
ProcessConfig config = new StaticProcessConfig(new DefaultWorkItemHandlerConfig(), new DefaultProcessEventListenerConfig(), uowManager, null, new DefaultVariableInitializer(), new FileSystemProcessInstancesFactory());
BpmnProcess process = createProcess(config, "BPMN2-UserTask.bpmn2");
process.configure();
ProcessInstance<BpmnVariables> processInstance = process.createInstance(BpmnVariables.create(Collections.singletonMap("test", "test")));
UnitOfWork uow = uowManager.newUnitOfWork();
uow.start();
processInstance.start();
uow.end();
assertThat(processInstance.status()).isEqualTo(STATE_ACTIVE);
assertThat(processInstance.description()).isEqualTo("User Task");
assertThat(process.instances().values(1, 10)).hasSize(1);
FileSystemProcessInstances fileSystemBasedStorage = (FileSystemProcessInstances) process.instances();
verify(fileSystemBasedStorage, times(2)).create(any(), any());
verify(fileSystemBasedStorage, times(1)).setMetadata(any(), eq(FileSystemProcessInstances.PI_DESCRIPTION), eq("User Task"));
verify(fileSystemBasedStorage, times(1)).setMetadata(any(), eq(FileSystemProcessInstances.PI_STATUS), eq("1"));
String testVar = (String) processInstance.variables().get("test");
assertThat(testVar).isEqualTo("test");
assertThat(processInstance.description()).isEqualTo("User Task");
WorkItem workItem = processInstance.workItems(securityPolicy).get(0);
assertThat(workItem).isNotNull();
assertThat(workItem.getParameters().get("ActorId")).isEqualTo("john");
uow = uowManager.newUnitOfWork();
uow.start();
processInstance.completeWorkItem(workItem.getId(), null, securityPolicy);
uow.end();
assertThat(processInstance.status()).isEqualTo(STATE_COMPLETED);
fileSystemBasedStorage = (FileSystemProcessInstances) process.instances();
verify(fileSystemBasedStorage, times(1)).remove(any(), any());
assertThat(fileSystemBasedStorage.size()).isZero();
}
use of io.automatiko.engine.workflow.bpmn2.BpmnVariables in project automatiko-engine by automatiko-io.
the class FileSystemProcessInstancesTest method testBasicFlowVersionedProcess.
@Test
void testBasicFlowVersionedProcess() {
BpmnProcess process = createProcess(null, "BPMN2-UserTaskVersioned.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");
FileSystemProcessInstances fileSystemBasedStorage = (FileSystemProcessInstances) process.instances();
assertThat(fileSystemBasedStorage.size()).isOne();
verify(fileSystemBasedStorage, times(2)).create(any(), any());
verify(fileSystemBasedStorage, times(1)).setMetadata(any(), eq(FileSystemProcessInstances.PI_DESCRIPTION), eq("User Task"));
verify(fileSystemBasedStorage, times(1)).setMetadata(any(), eq(FileSystemProcessInstances.PI_STATUS), eq("1"));
String testVar = (String) processInstance.variables().get("test");
assertThat(testVar).isEqualTo("test");
assertThat(processInstance.description()).isEqualTo("User Task");
assertThat(process.instances().values(1, 10).iterator().next().workItems(securityPolicy)).hasSize(1);
WorkItem workItem = processInstance.workItems(securityPolicy).get(0);
assertThat(workItem).isNotNull();
assertThat(workItem.getParameters().get("ActorId")).isEqualTo("john");
processInstance.completeWorkItem(workItem.getId(), null, securityPolicy);
assertThat(processInstance.status()).isEqualTo(STATE_COMPLETED);
fileSystemBasedStorage = (FileSystemProcessInstances) process.instances();
verify(fileSystemBasedStorage, times(2)).remove(any(), any());
assertThat(fileSystemBasedStorage.size()).isZero();
}
Aggregations