use of org.kie.kogito.process.bpmn2.BpmnProcess in project kogito-runtimes by kiegroup.
the class MockCacheProcessInstancesTest method testBasicFlow.
@Test
public 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();
assertThat(processInstance.status()).isEqualTo(STATE_ACTIVE);
WorkItem workItem = processInstance.workItems(SecurityPolicy.of(new StaticIdentityProvider("john"))).get(0);
assertThat(workItem).isNotNull();
assertThat(workItem.getParameters().get("ActorId")).isEqualTo("john");
processInstance.completeWorkItem(workItem.getId(), null, SecurityPolicy.of(new StaticIdentityProvider("john")));
assertThat(processInstance.status()).isEqualTo(STATE_COMPLETED);
}
use of org.kie.kogito.process.bpmn2.BpmnProcess in project kogito-runtimes by kiegroup.
the class MockCacheProcessInstancesTest method testProcessInstanceNotFound.
@Test
public void testProcessInstanceNotFound() {
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();
assertThat(processInstance.status()).isEqualTo(STATE_ACTIVE);
mockCache.clear();
assertThatThrownBy(() -> processInstance.workItems().get(0)).isInstanceOf(ProcessInstanceNotFoundException.class);
Optional<? extends ProcessInstance<BpmnVariables>> loaded = process.instances().findById(processInstance.id());
assertThat(loaded).isNotPresent();
}
use of org.kie.kogito.process.bpmn2.BpmnProcess in project kogito-runtimes by kiegroup.
the class AbstractProcessInstancesIT method testBasicTaskFlow.
@Test
void testBasicTaskFlow() {
var factory = new TestProcessInstancesFactory(getDataSource(), false);
BpmnProcess process = createProcess(factory, "BPMN2-UserTask.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");
JDBCProcessInstances processInstances = (JDBCProcessInstances) process.instances();
assertThat(processInstances.size()).isOne();
assertThat(processInstances.exists(processInstance.id())).isTrue();
verify(processInstances).create(any(), any());
String testVar = (String) processInstance.variables().get("test");
assertThat(testVar).isEqualTo("test");
assertThat(processInstance.description()).isEqualTo("User Task");
assertThat(process.instances().values().iterator().next().workItems(securityPolicy)).hasSize(1);
WorkItem workItem = processInstance.workItems(securityPolicy).get(0);
assertThat(workItem).isNotNull();
assertThat(workItem.getParameters()).containsEntry("ActorId", "john");
processInstance.completeWorkItem(workItem.getId(), null, securityPolicy);
assertThat(processInstance.status()).isEqualTo(STATE_COMPLETED);
processInstances = (JDBCProcessInstances) process.instances();
verify(processInstances, times(2)).remove(processInstance.id());
assertThat(processInstances.size()).isZero();
assertThat(process.instances().values()).isEmpty();
}
use of org.kie.kogito.process.bpmn2.BpmnProcess in project kogito-runtimes by kiegroup.
the class AbstractProcessInstancesIT method testRemove.
@Test
public void testRemove() {
var factory = new TestProcessInstancesFactory(getDataSource(), true);
BpmnProcess process = createProcess(factory, "BPMN2-UserTask.bpmn2");
ProcessInstance<BpmnVariables> processInstance = process.createInstance(BpmnVariables.create(Collections.singletonMap("test", "test")));
processInstance.start();
JDBCProcessInstances processInstances = (JDBCProcessInstances) process.instances();
assertThat(processInstances.size()).isOne();
Optional<?> foundOne = processInstances.findById(processInstance.id());
BpmnProcessInstance instanceOne = (BpmnProcessInstance) foundOne.get();
foundOne = processInstances.findById(processInstance.id());
BpmnProcessInstance instanceTwo = (BpmnProcessInstance) foundOne.get();
assertEquals(1L, instanceOne.version());
assertEquals(1L, instanceTwo.version());
processInstances.remove(instanceOne.id());
try {
String id = instanceTwo.id();
processInstances.remove(id);
} catch (RuntimeException e) {
assertThat(e.getMessage()).isEqualTo("The document with ID: " + instanceOne.id() + " was deleted by other request.");
}
}
use of org.kie.kogito.process.bpmn2.BpmnProcess in project kogito-runtimes by kiegroup.
the class AbstractProcessInstancesIT method createProcess.
public static BpmnProcess createProcess(TestProcessInstancesFactory factory, String fileName) {
BpmnProcess process = BpmnProcess.from(new ClassPathResource(fileName)).get(0);
process.setProcessInstancesFactory(factory);
process.configure();
process.instances().values(ProcessInstanceReadMode.MUTABLE).forEach(p -> p.abort());
return process;
}
Aggregations