Search in sources :

Example 11 with BpmnProcess

use of org.kie.kogito.process.bpmn2.BpmnProcess 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 12 with BpmnProcess

use of org.kie.kogito.process.bpmn2.BpmnProcess in project kogito-runtimes by kiegroup.

the class FileSystemProcessInstancesTest method testValuesReadMode.

@Test
void testValuesReadMode() {
    BpmnProcess process = createProcess("BPMN2-UserTask.bpmn2");
    ProcessInstance<BpmnVariables> processInstance = process.createInstance(BpmnVariables.create(Collections.singletonMap("test", "test")));
    processInstance.start();
    ProcessInstances<BpmnVariables> instances = process.instances();
    assertThat(instances.size()).isOne();
    ProcessInstance<BpmnVariables> pi = instances.values().stream().findFirst().get();
    assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> pi.abort());
    instances.values(ProcessInstanceReadMode.MUTABLE).stream().findFirst().get().abort();
    assertThat(instances.size()).isZero();
}
Also used : BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Example 13 with BpmnProcess

use of org.kie.kogito.process.bpmn2.BpmnProcess in project kogito-runtimes by kiegroup.

the class CacheProcessInstancesWithLockIT method testBasic.

@Test
public void testBasic() {
    BpmnProcess process = createProcess("BPMN2-UserTask.bpmn2");
    CacheProcessInstances pi = new CacheProcessInstances(process, cacheManager, null, true);
    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);
    try {
        pi.update(TEST_ID, mockUpdatePi);
    } catch (RuntimeException e) {
        assertThat(e.getMessage()).isEqualTo("The document with ID: " + TEST_ID + " was updated or deleted by other request.");
    }
    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) WorkflowProcessInstance(org.jbpm.workflow.instance.WorkflowProcessInstance) Date(java.util.Date) Test(org.junit.jupiter.api.Test)

Example 14 with BpmnProcess

use of org.kie.kogito.process.bpmn2.BpmnProcess in project kogito-runtimes by kiegroup.

the class PersistentProcessInstancesWithLockIT method testRemove.

@Test
public void testRemove() {
    MongoDBProcessInstancesFactory factory = new MongoDBProcessInstancesFactory(getMongoClient());
    BpmnProcess process = createProcess(factory);
    ProcessInstance<BpmnVariables> processInstance = process.createInstance(BpmnVariables.create(Collections.singletonMap("test", "test")));
    processInstance.start();
    MongoDBProcessInstances<?> processInstances = new MongoDBProcessInstances<>(getMongoClient(), process, DB_NAME, factory.transactionManager(), true);
    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.");
    }
}
Also used : BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) BpmnProcessInstance(org.kie.kogito.process.bpmn2.BpmnProcessInstance) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Example 15 with BpmnProcess

use of org.kie.kogito.process.bpmn2.BpmnProcess in project kogito-runtimes by kiegroup.

the class PersistentProcessInstancesWithLockIT method createProcess.

private BpmnProcess createProcess(MongoDBProcessInstancesFactory factory) {
    BpmnProcess process = BpmnProcess.from(new ClassPathResource("BPMN2-UserTask.bpmn2")).get(0);
    process.setProcessInstancesFactory(factory);
    process.configure();
    return process;
}
Also used : BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) ClassPathResource(org.drools.core.io.impl.ClassPathResource)

Aggregations

Test (org.junit.jupiter.api.Test)74 BpmnProcess (org.kie.kogito.process.bpmn2.BpmnProcess)64 BpmnVariables (org.kie.kogito.process.bpmn2.BpmnVariables)47 ClassPathResource (org.drools.core.io.impl.ClassPathResource)46 BpmnProcess (io.automatiko.engine.workflow.bpmn2.BpmnProcess)22 HashMap (java.util.HashMap)21 BpmnVariables (io.automatiko.engine.workflow.bpmn2.BpmnVariables)18 ProcessMetaData (org.jbpm.compiler.canonical.ProcessMetaData)16 WorkItem (org.kie.kogito.process.WorkItem)16 StaticIdentityProvider (org.kie.kogito.services.identity.StaticIdentityProvider)10 BpmnProcessInstance (org.kie.kogito.process.bpmn2.BpmnProcessInstance)8 WorkItem (io.automatiko.engine.api.workflow.WorkItem)7 Collections (java.util.Collections)7 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)7 SecurityPolicy (org.kie.kogito.auth.SecurityPolicy)7 ProcessConfig (io.automatiko.engine.api.workflow.ProcessConfig)6 STATE_ACTIVE (org.kie.kogito.internal.process.runtime.KogitoProcessInstance.STATE_ACTIVE)6 ProcessInstance (org.kie.kogito.process.ProcessInstance)6 ClassPathResource (io.automatiko.engine.services.io.ClassPathResource)5 List (java.util.List)5