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);
}
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();
}
Aggregations