Search in sources :

Example 6 with BpmnProcess

use of io.automatiko.engine.workflow.bpmn2.BpmnProcess 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 BpmnProcess

use of io.automatiko.engine.workflow.bpmn2.BpmnProcess 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 BpmnProcess

use of io.automatiko.engine.workflow.bpmn2.BpmnProcess 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 BpmnProcess

use of io.automatiko.engine.workflow.bpmn2.BpmnProcess 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 BpmnProcess

use of io.automatiko.engine.workflow.bpmn2.BpmnProcess in project kogito-runtimes by kiegroup.

the class AbstractProcessInstancesIT method createProcess.

public static BpmnProcess createProcess(TestProcessInstancesFactory factory, String fileName) {
    BpmnProcess process = BpmnProcess.from(new ClassPathResource(fileName)).get(0);
    process.setProcessInstancesFactory(factory);
    process.configure();
    process.instances().values(ProcessInstanceReadMode.MUTABLE).forEach(p -> p.abort());
    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 ProcessConfig (io.automatiko.engine.api.workflow.ProcessConfig)8 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 List (java.util.List)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