use of io.automatiko.engine.workflow.bpmn2.BpmnVariables in project kogito-runtimes by kiegroup.
the class KafkaProcessInstancesIT method testFindByIdReadMode.
@Test
void testFindByIdReadMode() {
BpmnProcess process = BpmnProcess.from(new ClassPathResource("BPMN2-UserTask-Script.bpmn2")).get(0);
listener.setKafkaStreams(createStreams(process));
process.setProcessInstancesFactory(factory);
process.configure();
listener.getKafkaStreams().start();
ProcessInstances<BpmnVariables> instances = process.instances();
assertThat(instances.size()).isZero();
ProcessInstance<BpmnVariables> mutablePi = process.createInstance(BpmnVariables.create(singletonMap("var", "value")));
mutablePi.start();
assertThat(mutablePi.status()).isEqualTo(STATE_ERROR);
assertThat(mutablePi.error()).hasValueSatisfying(error -> {
assertThat(error.errorMessage()).contains("java.lang.NullPointerException");
assertThat(error.failedNodeId()).isEqualTo("ScriptTask_1");
});
assertThat(mutablePi.variables().toMap()).containsExactly(entry("var", "value"));
await().until(() -> instances.values().size() == 1);
ProcessInstance<BpmnVariables> pi = instances.findById(mutablePi.id(), ProcessInstanceReadMode.READ_ONLY).get();
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> pi.abort());
ProcessInstance<BpmnVariables> readOnlyPi = instances.findById(mutablePi.id(), ProcessInstanceReadMode.READ_ONLY).get();
assertThat(readOnlyPi.status()).isEqualTo(STATE_ERROR);
assertThat(readOnlyPi.error()).hasValueSatisfying(error -> {
assertThat(error.errorMessage()).contains("java.lang.NullPointerException");
assertThat(error.failedNodeId()).isEqualTo("ScriptTask_1");
});
assertThat(readOnlyPi.variables().toMap()).containsExactly(entry("var", "value"));
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> readOnlyPi.abort());
instances.findById(mutablePi.id()).get().abort();
assertThat(instances.size()).isZero();
}
use of io.automatiko.engine.workflow.bpmn2.BpmnVariables in project kogito-runtimes by kiegroup.
the class KafkaProcessInstancesIT method testValuesReadMode.
@Test
void testValuesReadMode() {
BpmnProcess process = BpmnProcess.from(new ClassPathResource("BPMN2-UserTask.bpmn2")).get(0);
listener.setKafkaStreams(createStreams(process));
process.setProcessInstancesFactory(factory);
process.configure();
listener.getKafkaStreams().start();
ProcessInstances<BpmnVariables> instances = process.instances();
assertThat(instances.size()).isZero();
ProcessInstance<BpmnVariables> processInstance = process.createInstance(BpmnVariables.create(singletonMap("test", "test")));
processInstance.start();
await().until(() -> instances.values().size() == 1);
ProcessInstance<BpmnVariables> pi = instances.values().stream().findFirst().get();
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> pi.abort());
instances.values(ProcessInstanceReadMode.MUTABLE).stream().findFirst().get().abort();
assertThat(instances.size()).isZero();
}
use of io.automatiko.engine.workflow.bpmn2.BpmnVariables in project kogito-runtimes by kiegroup.
the class DocumentProcessInstanceMarshallerTest method testUnmarshalProcessInstance.
@Test
void testUnmarshalProcessInstance() {
ProcessInstance<BpmnVariables> processInstance = (ProcessInstance<BpmnVariables>) marshaller.unmarshallProcessInstance(doc.toJson().getBytes(), process);
assertNotNull(processInstance, "Unmarshalled value should not be null");
assertThat(processInstance.id()).isEqualTo(doc.get("id"));
assertThat(processInstance.description()).isEqualTo(doc.get("description"));
assertThat(processInstance.description()).isEqualTo("User Task");
Collection<? extends ProcessInstance<BpmnVariables>> values = process.instances().values();
assertThat(values).isNotEmpty();
BpmnVariables variables = processInstance.variables();
String testVar = (String) variables.get("test");
assertThat(testVar).isEqualTo("testValue");
}
use of io.automatiko.engine.workflow.bpmn2.BpmnVariables in project kogito-runtimes by kiegroup.
the class MongoDBProcessInstancesIT method testFindByIdReadMode.
void testFindByIdReadMode(MongoDBTransactionManager transactionManager) {
BpmnProcess process = BpmnProcess.from(new ClassPathResource("BPMN2-UserTask-Script.bpmn2")).get(0);
// workaround as BpmnProcess does not compile the scripts but just reads the xml
for (Node node : ((WorkflowProcess) process.get()).getNodes()) {
if (node instanceof ActionNode) {
DroolsAction a = ((ActionNode) node).getAction();
a.setMetaData("Action", (Action) kcontext -> {
System.out.println("The variable value is " + kcontext.getVariable("s") + " about to call toString on it");
kcontext.getVariable("s").toString();
});
}
}
process.setProcessInstancesFactory(new MongoDBProcessInstancesFactory(mongoClient, transactionManager));
process.configure();
ProcessInstance<BpmnVariables> mutablePi = process.createInstance(BpmnVariables.create(Collections.singletonMap("var", "value")));
mutablePi.start();
assertThat(mutablePi.status()).isEqualTo(STATE_ERROR);
assertThat(mutablePi.error()).hasValueSatisfying(error -> {
assertThat(error.errorMessage()).contains("java.lang.NullPointerException");
assertThat(error.failedNodeId()).isEqualTo("ScriptTask_1");
});
assertThat(mutablePi.variables().toMap()).containsExactly(entry("var", "value"));
ProcessInstances<BpmnVariables> instances = process.instances();
assertThat(instances.size()).isOne();
ProcessInstance<BpmnVariables> pi = instances.findById(mutablePi.id(), ProcessInstanceReadMode.READ_ONLY).get();
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> pi.abort());
ProcessInstance<BpmnVariables> readOnlyPi = instances.findById(mutablePi.id(), ProcessInstanceReadMode.READ_ONLY).get();
assertThat(readOnlyPi.status()).isEqualTo(STATE_ERROR);
assertThat(readOnlyPi.error()).hasValueSatisfying(error -> {
assertThat(error.errorMessage()).contains("java.lang.NullPointerException");
assertThat(error.failedNodeId()).isEqualTo("ScriptTask_1");
});
assertThat(readOnlyPi.variables().toMap()).containsExactly(entry("var", "value"));
assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> readOnlyPi.abort());
instances.findById(mutablePi.id()).get().abort();
assertThat(instances.size()).isZero();
}
use of io.automatiko.engine.workflow.bpmn2.BpmnVariables in project kogito-runtimes by kiegroup.
the class MongoDBProcessInstancesIT method test.
private void test(MongoDBTransactionManager transactionManager) {
BpmnProcess process = BpmnProcess.from(new ClassPathResource("BPMN2-UserTask.bpmn2")).get(0);
process.setProcessInstancesFactory(new MongoDBProcessInstancesFactory(mongoClient, transactionManager));
process.configure();
testIndexCreation(process);
Map<String, Object> parameters = new HashMap<>();
parameters.put("test", "test");
parameters.put("integerVar", 10);
parameters.put("booleanVar", true);
parameters.put("doubleVar", 10.11);
parameters.put("floatVar", 3.5f);
parameters.put("address", new Address("main street", "Boston", "10005", "US"));
PersonWithAddresses pa = new PersonWithAddresses("bob", 16);
List<Address> list = new ArrayList<>();
list.add(new Address("main street", "Boston", "10005", "US"));
list.add(new Address("new Street", "Charlotte", "28200", "US"));
pa.setAddresses(list);
parameters.put("pa", pa);
parameters.put("addresslist", list);
Map<Object, Object> map = new HashMap<>();
map.put("addresslist", list);
map.put(1, "ss");
map.put("2", "kk");
Map<Object, Object> testMap = new HashMap<>();
testMap.put("addresslist", list);
testMap.put(1, "integer");
testMap.put("2", "string");
testMap.put("map", map);
parameters.put("testMap", testMap);
ProcessInstance<BpmnVariables> processInstance = process.createInstance(BpmnVariables.create(parameters));
processInstance.start();
assertThat(processInstance.status()).isEqualTo(STATE_ACTIVE);
assertThat(processInstance.description()).isEqualTo("User Task");
Collection<? extends ProcessInstance<BpmnVariables>> values = process.instances().values();
assertThat(values).hasSize(1);
String testVar = (String) processInstance.variables().get("test");
assertThat(testVar).isEqualTo("test");
Object addr = processInstance.variables().get("address");
assertThat(addr.getClass().getName()).isEqualTo("org.kie.kogito.mongodb.Address");
Object flt = processInstance.variables().get("floatVar");
assertThat(flt.getClass().getName()).isEqualTo("java.lang.Float");
assertThat(processInstance.description()).isEqualTo("User Task");
List<WorkItem> workItems = processInstance.workItems(securityPolicy);
assertThat(workItems).hasSize(1);
WorkItem workItem = workItems.get(0);
assertEquals("john", workItem.getParameters().get("ActorId"));
processInstance.completeWorkItem(workItem.getId(), null, securityPolicy);
assertEquals(STATE_COMPLETED, processInstance.status());
assertThat(process.instances().size()).isZero();
}
Aggregations