Search in sources :

Example 1 with FileSystemProcessInstances

use of org.kie.kogito.persistence.filesystem.FileSystemProcessInstances in project kogito-runtimes by kiegroup.

the class FileSystemProcessInstancesTest 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");
    FileSystemProcessInstances fileSystemBasedStorage = (FileSystemProcessInstances) process.instances();
    assertThat(fileSystemBasedStorage.size()).isOne();
    assertThat(fileSystemBasedStorage.exists(processInstance.id())).isTrue();
    verify(fileSystemBasedStorage).create(any(), any());
    verify(fileSystemBasedStorage, times(2)).setMetadata(any(), eq(FileSystemProcessInstances.PI_DESCRIPTION), eq("User Task"));
    verify(fileSystemBasedStorage, times(2)).setMetadata(any(), eq(FileSystemProcessInstances.PI_STATUS), eq("1"));
    String testVar = (String) processInstance.variables().get("test");
    assertThat(testVar).isEqualTo("test");
    assertThat(processInstance.description()).isEqualTo("User Task");
    assertThat(process.instances().size()).isEqualTo(1);
    assertThat(processInstance.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);
    fileSystemBasedStorage = (FileSystemProcessInstances) process.instances();
    verify(fileSystemBasedStorage, times(2)).remove(processInstance.id());
    assertThat(fileSystemBasedStorage.size()).isZero();
}
Also used : BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) WorkItem(org.kie.kogito.process.WorkItem) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) FileSystemProcessInstances(org.kie.kogito.persistence.filesystem.FileSystemProcessInstances) Test(org.junit.jupiter.api.Test)

Example 2 with FileSystemProcessInstances

use of org.kie.kogito.persistence.filesystem.FileSystemProcessInstances in project kogito-runtimes by kiegroup.

the class FileSystemProcessInstancesTest method testBasicFlowWithStartFrom.

@Test
void testBasicFlowWithStartFrom() {
    BpmnProcess process = createProcess("BPMN2-UserTask.bpmn2");
    ProcessInstance<BpmnVariables> processInstance = process.createInstance(BpmnVariables.create(Collections.singletonMap("test", "test")));
    processInstance.startFrom("_2");
    assertThat(processInstance.status()).isEqualTo(STATE_ACTIVE);
    assertThat(processInstance.description()).isEqualTo("User Task");
    FileSystemProcessInstances fileSystemBasedStorage = (FileSystemProcessInstances) process.instances();
    verify(fileSystemBasedStorage).update(any(), any());
    String testVar = (String) processInstance.variables().get("test");
    assertThat(testVar).isEqualTo("test");
    assertThat(processInstance.description()).isEqualTo("User Task");
    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);
    fileSystemBasedStorage = (FileSystemProcessInstances) process.instances();
    verify(fileSystemBasedStorage, times(2)).remove(any());
    assertThat(fileSystemBasedStorage.size()).isZero();
}
Also used : BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) WorkItem(org.kie.kogito.process.WorkItem) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) FileSystemProcessInstances(org.kie.kogito.persistence.filesystem.FileSystemProcessInstances) Test(org.junit.jupiter.api.Test)

Example 3 with FileSystemProcessInstances

use of org.kie.kogito.persistence.filesystem.FileSystemProcessInstances in project kogito-runtimes by kiegroup.

the class FileSystemProcessInstancesTest method testBasicFlowControlledByUnitOfWork.

@Test
void testBasicFlowControlledByUnitOfWork() {
    BpmnProcess process = createProcess("BPMN2-UserTask.bpmn2");
    process.setProcessInstancesFactory(new FileSystemProcessInstancesFactory());
    process.configure();
    ProcessInstance<BpmnVariables> processInstance = process.createInstance(BpmnVariables.create(Collections.singletonMap("test", "test")));
    UnitOfWorkManager uowManager = process.getApplication().unitOfWorkManager();
    UnitOfWork uow = uowManager.newUnitOfWork();
    uow.start();
    processInstance.start();
    uow.end();
    assertThat(processInstance.status()).isEqualTo(STATE_ACTIVE);
    assertThat(processInstance.description()).isEqualTo("User Task");
    FileSystemProcessInstances fileSystemBasedStorage = (FileSystemProcessInstances) process.instances();
    assertThat(fileSystemBasedStorage.exists(processInstance.id())).isTrue();
    verify(fileSystemBasedStorage).create(processInstance.id(), processInstance);
    verify(fileSystemBasedStorage, times(2)).setMetadata(any(), eq(FileSystemProcessInstances.PI_DESCRIPTION), eq("User Task"));
    verify(fileSystemBasedStorage, times(2)).setMetadata(any(), eq(FileSystemProcessInstances.PI_STATUS), eq("1"));
    String testVar = (String) processInstance.variables().get("test");
    assertThat(testVar).isEqualTo("test");
    assertThat(processInstance.description()).isEqualTo("User Task");
    WorkItem workItem = processInstance.workItems(securityPolicy).get(0);
    assertThat(workItem).isNotNull();
    assertThat(workItem.getParameters().get("ActorId")).isEqualTo("john");
    uow = uowManager.newUnitOfWork();
    uow.start();
    processInstance.completeWorkItem(workItem.getId(), null, securityPolicy);
    uow.end();
    assertThat(processInstance.status()).isEqualTo(STATE_COMPLETED);
    fileSystemBasedStorage = (FileSystemProcessInstances) process.instances();
    verify(fileSystemBasedStorage).remove(processInstance.id());
    assertThat(fileSystemBasedStorage.size()).isZero();
}
Also used : BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) UnitOfWork(org.kie.kogito.uow.UnitOfWork) UnitOfWorkManager(org.kie.kogito.uow.UnitOfWorkManager) WorkItem(org.kie.kogito.process.WorkItem) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) FileSystemProcessInstances(org.kie.kogito.persistence.filesystem.FileSystemProcessInstances) Test(org.junit.jupiter.api.Test)

Aggregations

Test (org.junit.jupiter.api.Test)3 FileSystemProcessInstances (org.kie.kogito.persistence.filesystem.FileSystemProcessInstances)3 WorkItem (org.kie.kogito.process.WorkItem)3 BpmnProcess (org.kie.kogito.process.bpmn2.BpmnProcess)3 BpmnVariables (org.kie.kogito.process.bpmn2.BpmnVariables)3 UnitOfWork (org.kie.kogito.uow.UnitOfWork)1 UnitOfWorkManager (org.kie.kogito.uow.UnitOfWorkManager)1