use of org.drools.util.io.ClassPathResource in project kogito-runtimes by kiegroup.
the class FileSystemProcessInstancesTest method createProcess.
private BpmnProcess createProcess(String fileName) {
BpmnProcess process = BpmnProcess.from(new ClassPathResource(fileName)).get(0);
process.setProcessInstancesFactory(new FileSystemProcessInstancesFactory());
process.configure();
process.instances().values(ProcessInstanceReadMode.MUTABLE).forEach(p -> p.abort());
return process;
}
use of org.drools.util.io.ClassPathResource in project kogito-runtimes by kiegroup.
the class CacheProcessInstancesIT method testBasicFlow.
@Test
void testBasicFlow() {
BpmnProcess process = BpmnProcess.from(new ClassPathResource("BPMN2-UserTask.bpmn2")).get(0);
process.setProcessInstancesFactory(new CacheProcessInstancesFactory(cacheManager));
process.configure();
ProcessInstance<BpmnVariables> processInstance = process.createInstance(BpmnVariables.create(Collections.singletonMap("test", "test")));
processInstance.start();
assertEquals(STATE_ACTIVE, processInstance.status());
assertThat(process.instances().size()).isOne();
SecurityPolicy asJohn = SecurityPolicy.of(new StaticIdentityProvider("john"));
assertThat(process.instances().values().iterator().next().workItems(asJohn)).hasSize(1);
List<WorkItem> workItems = processInstance.workItems(asJohn);
assertThat(workItems).hasSize(1);
WorkItem workItem = workItems.get(0);
assertEquals("john", workItem.getParameters().get("ActorId"));
processInstance.completeWorkItem(workItem.getId(), null, asJohn);
assertEquals(STATE_COMPLETED, processInstance.status());
assertThat(process.instances().size()).isZero();
}
use of org.drools.util.io.ClassPathResource in project kogito-runtimes by kiegroup.
the class CacheProcessInstancesWithLockIT method createProcess.
private BpmnProcess createProcess(String fileName) {
BpmnProcess process = BpmnProcess.from(new ClassPathResource(fileName)).get(0);
AbstractProcessInstancesFactory factory = mock(AbstractProcessInstancesFactory.class);
process.setProcessInstancesFactory(factory);
process.configure();
return process;
}
use of org.drools.util.io.ClassPathResource in project kogito-runtimes by kiegroup.
the class MockCacheProcessInstancesTest method testFindByIdReadMode.
@Test
void testFindByIdReadMode() {
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 CacheProcessInstancesFactory(cacheManager));
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 org.drools.util.io.ClassPathResource in project kogito-runtimes by kiegroup.
the class MockCacheProcessInstancesTest method testBasicFlowNoActors.
@Test
public void testBasicFlowNoActors() {
BpmnProcess process = BpmnProcess.from(new ClassPathResource("BPMN2-UserTask-NoActors.bpmn2")).get(0);
process.setProcessInstancesFactory(new CacheProcessInstancesFactory(cacheManager));
process.configure();
ProcessInstance<BpmnVariables> processInstance = process.createInstance(BpmnVariables.create(Collections.singletonMap("test", "test")));
processInstance.start();
assertThat(processInstance.status()).isEqualTo(STATE_ACTIVE);
WorkItem workItem = processInstance.workItems().get(0);
assertThat(workItem).isNotNull();
assertThat(workItem.getParameters().get("ActorId")).isNull();
List<WorkItem> workItems = processInstance.workItems(SecurityPolicy.of(new StaticIdentityProvider("john")));
assertThat(workItems).hasSize(1);
processInstance.completeWorkItem(workItem.getId(), null);
assertThat(processInstance.status()).isEqualTo(STATE_COMPLETED);
}
Aggregations