Search in sources :

Example 1 with PostgreProcessInstances

use of org.kie.kogito.persistence.postgresql.PostgreProcessInstances in project kogito-runtimes by kiegroup.

the class PostgreProcessInstancesIT method testBasicFlow.

@Test
void testBasicFlow() {
    BpmnProcess process = createProcess("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");
    PostgreProcessInstances processInstances = (PostgreProcessInstances) process.instances();
    assertThat(processInstances.size()).isOne();
    assertThat(processInstances.exists(processInstance.id())).isTrue();
    ProcessInstance<?> readOnlyPI = process.instances().findById(processInstance.id(), ProcessInstanceReadMode.READ_ONLY).get();
    assertThat(readOnlyPI.status()).isEqualTo(STATE_ACTIVE);
    assertThat(process.instances().values(ProcessInstanceReadMode.READ_ONLY).size()).isOne();
    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().get("ActorId")).isEqualTo("john");
    processInstance.completeWorkItem(workItem.getId(), null, securityPolicy);
    assertThat(processInstance.status()).isEqualTo(STATE_COMPLETED);
    processInstances = (PostgreProcessInstances) process.instances();
    verify(processInstances, times(2)).remove(processInstance.id());
    assertThat(processInstances.size()).isZero();
    assertThat(process.instances().values()).isEmpty();
}
Also used : BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) PostgreProcessInstances(org.kie.kogito.persistence.postgresql.PostgreProcessInstances) WorkItem(org.kie.kogito.process.WorkItem) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Example 2 with PostgreProcessInstances

use of org.kie.kogito.persistence.postgresql.PostgreProcessInstances in project kogito-runtimes by kiegroup.

the class PostgreProcessInstancesWithLockIT method testUpdate.

@Test
public void testUpdate() {
    BpmnProcess process = createProcess("BPMN2-UserTask.bpmn2");
    ProcessInstance<BpmnVariables> processInstance = process.createInstance(BpmnVariables.create(Collections.singletonMap("test", "test")));
    processInstance.start();
    PostgreProcessInstances processInstances = (PostgreProcessInstances) 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("Error updating process instance " + instanceOne.id());
    }
    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();
}
Also used : BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) PostgreProcessInstances(org.kie.kogito.persistence.postgresql.PostgreProcessInstances) BpmnProcessInstance(org.kie.kogito.process.bpmn2.BpmnProcessInstance) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Example 3 with PostgreProcessInstances

use of org.kie.kogito.persistence.postgresql.PostgreProcessInstances in project kogito-runtimes by kiegroup.

the class PostgreProcessInstancesWithLockIT method testBasic.

@Test
public void testBasic() {
    BpmnProcess process = createProcess("BPMN2-UserTask.bpmn2");
    PostgreProcessInstances pi = new PostgreProcessInstances(process, client, true, 1000L, false);
    assertNotNull(pi);
    WorkflowProcessInstance createPi = ((AbstractProcessInstance<?>) process.createInstance(BpmnVariables.create(Collections.singletonMap("test", "test")))).internalGetProcessInstance();
    createPi.setId(TEST_ID);
    createPi.setStartDate(new Date());
    AbstractProcessInstance<?> mockCreatePi = mock(AbstractProcessInstance.class);
    mockCreatePi.setVersion(1L);
    when(mockCreatePi.status()).thenReturn(ProcessInstance.STATE_ACTIVE);
    when(mockCreatePi.internalGetProcessInstance()).thenReturn(createPi);
    when(mockCreatePi.id()).thenReturn(TEST_ID);
    pi.create(TEST_ID, mockCreatePi);
    assertThat(pi.size()).isOne();
    assertTrue(pi.exists(TEST_ID));
    WorkflowProcessInstance updatePi = ((AbstractProcessInstance<?>) process.createInstance(BpmnVariables.create(Collections.singletonMap("test", "test")))).internalGetProcessInstance();
    updatePi.setId(TEST_ID);
    updatePi.setStartDate(new Date());
    AbstractProcessInstance<?> mockUpdatePi = mock(AbstractProcessInstance.class);
    when(mockUpdatePi.status()).thenReturn(ProcessInstance.STATE_ACTIVE);
    when(mockUpdatePi.internalGetProcessInstance()).thenReturn(updatePi);
    when(mockUpdatePi.id()).thenReturn(TEST_ID);
    pi.update(TEST_ID, mockUpdatePi);
    pi.remove(TEST_ID);
    assertFalse(pi.exists(TEST_ID));
}
Also used : BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) AbstractProcessInstance(org.kie.kogito.process.impl.AbstractProcessInstance) PostgreProcessInstances(org.kie.kogito.persistence.postgresql.PostgreProcessInstances) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 4 with PostgreProcessInstances

use of org.kie.kogito.persistence.postgresql.PostgreProcessInstances in project kogito-runtimes by kiegroup.

the class PostgreProcessInstancesWithLockIT method testRemove.

@Test
public void testRemove() {
    BpmnProcess process = createProcess("BPMN2-UserTask.bpmn2");
    ProcessInstance<BpmnVariables> processInstance = process.createInstance(BpmnVariables.create(Collections.singletonMap("test", "test")));
    processInstance.start();
    PostgreProcessInstances processInstances = (PostgreProcessInstances) 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 updated or deleted by other request.");
    }
}
Also used : BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) PostgreProcessInstances(org.kie.kogito.persistence.postgresql.PostgreProcessInstances) BpmnProcessInstance(org.kie.kogito.process.bpmn2.BpmnProcessInstance) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)4 PostgreProcessInstances (org.kie.kogito.persistence.postgresql.PostgreProcessInstances)4 BpmnProcess (org.kie.kogito.process.bpmn2.BpmnProcess)4 BpmnVariables (org.kie.kogito.process.bpmn2.BpmnVariables)3 BpmnProcessInstance (org.kie.kogito.process.bpmn2.BpmnProcessInstance)2 Date (java.util.Date)1 WorkflowProcessInstance (org.jbpm.workflow.instance.WorkflowProcessInstance)1 WorkItem (org.kie.kogito.process.WorkItem)1 AbstractProcessInstance (org.kie.kogito.process.impl.AbstractProcessInstance)1