Search in sources :

Example 1 with UnitOfWorkManager

use of org.kie.kogito.uow.UnitOfWorkManager in project kogito-runtimes by kiegroup.

the class AbstractProcessInstanceTest method setup.

@SuppressWarnings("unchecked")
@BeforeEach
private void setup() {
    MockitoAnnotations.initMocks(this);
    AbstractProcess<TestModel> process = mock(AbstractProcess.class);
    when(process.process()).thenReturn(mock(Process.class));
    InternalProcessRuntime pr = mock(InternalProcessRuntime.class);
    when(pr.createProcessInstance(any(), any(), any())).thenReturn(wpi);
    when(pr.getProcessInstanceManager()).thenReturn(pim);
    UnitOfWorkManager unitOfWorkManager = mock(UnitOfWorkManager.class);
    when(pr.getUnitOfWorkManager()).thenReturn(unitOfWorkManager);
    KogitoProcessRuntime kogitoProcessRuntime = mock(KogitoProcessRuntime.class);
    when(pr.getKogitoProcessRuntime()).thenReturn(kogitoProcessRuntime);
    when(unitOfWorkManager.currentUnitOfWork()).thenReturn(unitOfWork);
    processInstance = new TestProcessInstance(process, new TestModel(), pr);
}
Also used : UnitOfWorkManager(org.kie.kogito.uow.UnitOfWorkManager) KogitoProcessRuntime(org.kie.kogito.internal.process.runtime.KogitoProcessRuntime) Process(org.kie.api.definition.process.Process) RuleFlowProcess(org.jbpm.ruleflow.core.RuleFlowProcess) InternalProcessRuntime(org.jbpm.process.instance.InternalProcessRuntime) BeforeEach(org.junit.jupiter.api.BeforeEach)

Example 2 with UnitOfWorkManager

use of org.kie.kogito.uow.UnitOfWorkManager 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

UnitOfWorkManager (org.kie.kogito.uow.UnitOfWorkManager)2 InternalProcessRuntime (org.jbpm.process.instance.InternalProcessRuntime)1 RuleFlowProcess (org.jbpm.ruleflow.core.RuleFlowProcess)1 BeforeEach (org.junit.jupiter.api.BeforeEach)1 Test (org.junit.jupiter.api.Test)1 Process (org.kie.api.definition.process.Process)1 KogitoProcessRuntime (org.kie.kogito.internal.process.runtime.KogitoProcessRuntime)1 FileSystemProcessInstances (org.kie.kogito.persistence.filesystem.FileSystemProcessInstances)1 WorkItem (org.kie.kogito.process.WorkItem)1 BpmnProcess (org.kie.kogito.process.bpmn2.BpmnProcess)1 BpmnVariables (org.kie.kogito.process.bpmn2.BpmnVariables)1 UnitOfWork (org.kie.kogito.uow.UnitOfWork)1