Search in sources :

Example 6 with BpmnVariables

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

the class MockCacheProcessInstancesTest method testBasicFlow.

@Test
public void testBasicFlow() {
    BpmnProcess process = BpmnProcess.from(new ClassPathResource("BPMN2-UserTask.bpmn2")).get(0);
    process.setProcessInstancesFactory(new CacheProcessInstancesFactory(cacheManager));
    process.configure();
    ProcessInstance<BpmnVariables> processInstance = process.createInstance(BpmnVariables.create(Collections.singletonMap("test", "test")));
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(STATE_ACTIVE);
    WorkItem workItem = processInstance.workItems(SecurityPolicy.of(new StaticIdentityProvider("john"))).get(0);
    assertThat(workItem).isNotNull();
    assertThat(workItem.getParameters().get("ActorId")).isEqualTo("john");
    processInstance.completeWorkItem(workItem.getId(), null, SecurityPolicy.of(new StaticIdentityProvider("john")));
    assertThat(processInstance.status()).isEqualTo(STATE_COMPLETED);
}
Also used : StaticIdentityProvider(org.kie.kogito.services.identity.StaticIdentityProvider) BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) WorkItem(org.kie.kogito.process.WorkItem) ClassPathResource(org.drools.core.io.impl.ClassPathResource) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Example 7 with BpmnVariables

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

the class MockCacheProcessInstancesTest method testProcessInstanceNotFound.

@Test
public void testProcessInstanceNotFound() {
    BpmnProcess process = BpmnProcess.from(new ClassPathResource("BPMN2-UserTask.bpmn2")).get(0);
    process.setProcessInstancesFactory(new CacheProcessInstancesFactory(cacheManager));
    process.configure();
    ProcessInstance<BpmnVariables> processInstance = process.createInstance(BpmnVariables.create(Collections.singletonMap("test", "test")));
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(STATE_ACTIVE);
    mockCache.clear();
    assertThatThrownBy(() -> processInstance.workItems().get(0)).isInstanceOf(ProcessInstanceNotFoundException.class);
    Optional<? extends ProcessInstance<BpmnVariables>> loaded = process.instances().findById(processInstance.id());
    assertThat(loaded).isNotPresent();
}
Also used : BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) ClassPathResource(org.drools.core.io.impl.ClassPathResource) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Example 8 with BpmnVariables

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

the class AbstractProcessInstancesIT method testBasicTaskFlow.

@Test
void testBasicTaskFlow() {
    var factory = new TestProcessInstancesFactory(getDataSource(), false);
    BpmnProcess process = createProcess(factory, "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");
    JDBCProcessInstances processInstances = (JDBCProcessInstances) process.instances();
    assertThat(processInstances.size()).isOne();
    assertThat(processInstances.exists(processInstance.id())).isTrue();
    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()).containsEntry("ActorId", "john");
    processInstance.completeWorkItem(workItem.getId(), null, securityPolicy);
    assertThat(processInstance.status()).isEqualTo(STATE_COMPLETED);
    processInstances = (JDBCProcessInstances) process.instances();
    verify(processInstances, times(2)).remove(processInstance.id());
    assertThat(processInstances.size()).isZero();
    assertThat(process.instances().values()).isEmpty();
}
Also used : JDBCProcessInstances(org.kie.kogito.persistence.jdbc.JDBCProcessInstances) BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) WorkItem(org.kie.kogito.process.WorkItem) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Example 9 with BpmnVariables

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

the class AbstractProcessInstancesIT method testRemove.

@Test
public void testRemove() {
    var factory = new TestProcessInstancesFactory(getDataSource(), true);
    BpmnProcess process = createProcess(factory, "BPMN2-UserTask.bpmn2");
    ProcessInstance<BpmnVariables> processInstance = process.createInstance(BpmnVariables.create(Collections.singletonMap("test", "test")));
    processInstance.start();
    JDBCProcessInstances processInstances = (JDBCProcessInstances) 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 deleted by other request.");
    }
}
Also used : JDBCProcessInstances(org.kie.kogito.persistence.jdbc.JDBCProcessInstances) 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 10 with BpmnVariables

use of org.kie.kogito.process.bpmn2.BpmnVariables 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)

Aggregations

Test (org.junit.jupiter.api.Test)64 BpmnVariables (org.kie.kogito.process.bpmn2.BpmnVariables)48 BpmnProcess (org.kie.kogito.process.bpmn2.BpmnProcess)47 ClassPathResource (org.drools.core.io.impl.ClassPathResource)34 HashMap (java.util.HashMap)19 BpmnProcess (io.automatiko.engine.workflow.bpmn2.BpmnProcess)18 BpmnVariables (io.automatiko.engine.workflow.bpmn2.BpmnVariables)18 WorkItem (org.kie.kogito.process.WorkItem)16 ProcessMetaData (org.jbpm.compiler.canonical.ProcessMetaData)13 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 ProcessInstance (org.kie.kogito.process.ProcessInstance)7 TestWorkItemHandler (org.jbpm.bpmn2.objects.TestWorkItemHandler)6 STATE_ACTIVE (org.kie.kogito.internal.process.runtime.KogitoProcessInstance.STATE_ACTIVE)6 List (java.util.List)5 Assertions.assertThatExceptionOfType (org.assertj.core.api.Assertions.assertThatExceptionOfType)5