use of org.kie.kogito.persistence.jdbc.JDBCProcessInstances 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.persistence.jdbc.JDBCProcessInstances 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.persistence.jdbc.JDBCProcessInstances in project kogito-runtimes by kiegroup.
the class AbstractProcessInstancesIT method testUpdate.
@Test
public void testUpdate() {
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());
instanceOne.updateVariables(BpmnVariables.create(Collections.singletonMap("s", "test")));
try {
BpmnVariables testvar = BpmnVariables.create(Collections.singletonMap("ss", "test"));
instanceTwo.updateVariables(testvar);
} catch (RuntimeException e) {
assertThat(e.getMessage()).isEqualTo("The document with ID: " + instanceOne.id() + " was updated or deleted by other request.");
}
foundOne = processInstances.findById(processInstance.id());
instanceOne = (BpmnProcessInstance) foundOne.get();
assertEquals(2L, instanceOne.version());
processInstances.remove(processInstance.id());
assertThat(processInstances.size()).isZero();
assertThat(process.instances().values()).isEmpty();
}
use of org.kie.kogito.persistence.jdbc.JDBCProcessInstances in project kogito-runtimes by kiegroup.
the class AbstractProcessInstancesIT method testException.
@Test
void testException() {
BpmnProcess process = configure(false);
JDBCProcessInstances processInstances = (JDBCProcessInstances) process.instances();
assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> processInstances.findById(TEST_ID));
assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> processInstances.remove(TEST_ID));
}
use of org.kie.kogito.persistence.jdbc.JDBCProcessInstances in project kogito-runtimes by kiegroup.
the class AbstractProcessInstancesIT method testBasicFlow.
@Test
void testBasicFlow() {
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();
JDBCProcessInstances processInstances = (JDBCProcessInstances) process.instances();
assertThat(processInstances.size()).isOne();
Optional<?> foundOne = processInstances.findById(processInstance.id());
BpmnProcessInstance instanceOne = (BpmnProcessInstance) foundOne.get();
processInstances.update(processInstance.id(), instanceOne);
assertThat(processInstances.size()).isOne();
assertThat(processInstances.exists(TEST_ID)).isFalse();
Optional<?> foundTwo = processInstances.findById(TEST_ID);
assertThat(foundTwo).isEmpty();
processInstances.remove(processInstance.id());
assertThat(processInstances.size()).isZero();
assertThat(process.instances().values()).isEmpty();
}
Aggregations