Search in sources :

Example 56 with BpmnVariables

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

the class AbstractProcessInstancesIT method testBasicFlow.

@Test
void testBasicFlow() {
    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();
    JDBCProcessInstances processInstances = (JDBCProcessInstances) process.instances();
    assertThat(processInstances.size()).isOne();
    Optional<?> foundOne = processInstances.findById(processInstance.id());
    BpmnProcessInstance instanceOne = (BpmnProcessInstance) foundOne.get();
    processInstances.update(processInstance.id(), instanceOne);
    assertThat(processInstances.size()).isOne();
    assertThat(processInstances.exists(TEST_ID)).isFalse();
    Optional<?> foundTwo = processInstances.findById(TEST_ID);
    assertThat(foundTwo).isEmpty();
    processInstances.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) BpmnProcessInstance(org.kie.kogito.process.bpmn2.BpmnProcessInstance) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Example 57 with BpmnVariables

use of io.automatiko.engine.workflow.bpmn2.BpmnVariables in project automatiko-engine by automatiko-io.

the class VariableTagsTest method testRequiredVariableFiltering.

@Test
public void testRequiredVariableFiltering() {
    BpmnProcess process = create("variable-tags/approval-with-custom-variable-tags.bpmn2");
    Map<String, Object> params = new HashMap<String, Object>();
    params.put("approver", "john");
    ProcessInstance<BpmnVariables> instance = process.createInstance(BpmnVariables.create(params));
    instance.start();
    assertEquals(STATE_ACTIVE, instance.status());
    assertThat(instance.variables().toMap()).hasSize(1);
    assertThat(instance.variables().toMap(BpmnVariables.OUTPUTS_ONLY)).hasSize(0);
    assertThat(instance.variables().toMap(BpmnVariables.INPUTS_ONLY)).hasSize(0);
    assertThat(instance.variables().toMap(BpmnVariables.INTERNAL_ONLY)).hasSize(0);
    assertThat(instance.variables().toMap(v -> v.hasTag("onlyAdmin"))).hasSize(1).containsEntry("approver", "john");
    instance.abort();
    assertEquals(STATE_ABORTED, instance.status());
}
Also used : Assertions.assertThrows(org.junit.jupiter.api.Assertions.assertThrows) Assertions.assertNotNull(org.junit.jupiter.api.Assertions.assertNotNull) ProcessVariableChangedEvent(io.automatiko.engine.api.event.process.ProcessVariableChangedEvent) WorkItem(io.automatiko.engine.api.runtime.process.WorkItem) BpmnProcess(io.automatiko.engine.workflow.bpmn2.BpmnProcess) STATE_ACTIVE(io.automatiko.engine.api.workflow.ProcessInstance.STATE_ACTIVE) DefaultProcessEventListener(io.automatiko.engine.api.event.process.DefaultProcessEventListener) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) STATE_COMPLETED(io.automatiko.engine.api.workflow.ProcessInstance.STATE_COMPLETED) ProcessConfig(io.automatiko.engine.api.workflow.ProcessConfig) STATE_ABORTED(io.automatiko.engine.api.workflow.ProcessInstance.STATE_ABORTED) HashMap(java.util.HashMap) TestWorkItemHandler(io.automatiko.engine.workflow.bpmn2.objects.TestWorkItemHandler) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) Test(org.junit.jupiter.api.Test) BpmnVariables(io.automatiko.engine.workflow.bpmn2.BpmnVariables) VariableViolationException(io.automatiko.engine.api.workflow.VariableViolationException) Map(java.util.Map) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Collections(java.util.Collections) BpmnProcess(io.automatiko.engine.workflow.bpmn2.BpmnProcess) HashMap(java.util.HashMap) BpmnVariables(io.automatiko.engine.workflow.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Example 58 with BpmnVariables

use of io.automatiko.engine.workflow.bpmn2.BpmnVariables in project automatiko-engine by automatiko-io.

the class ActivityTest method testScriptTask.

@Test
public void testScriptTask() throws Exception {
    BpmnProcess process = create("BPMN2-ScriptTask.bpmn2");
    ProcessInstance<BpmnVariables> instance = process.createInstance(BpmnVariables.create());
    instance.start();
    assertEquals(STATE_COMPLETED, instance.status());
}
Also used : BpmnProcess(io.automatiko.engine.workflow.bpmn2.BpmnProcess) BpmnVariables(io.automatiko.engine.workflow.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Example 59 with BpmnVariables

use of io.automatiko.engine.workflow.bpmn2.BpmnVariables in project automatiko-engine by automatiko-io.

the class ActivityTest method testMinimalProcessImplicit.

@Test
public void testMinimalProcessImplicit() throws Exception {
    BpmnProcess process = create("BPMN2-MinimalProcessImplicit.bpmn2");
    ProcessInstance<BpmnVariables> instance = process.createInstance(BpmnVariables.create());
    instance.start();
    assertEquals(STATE_COMPLETED, instance.status());
}
Also used : BpmnProcess(io.automatiko.engine.workflow.bpmn2.BpmnProcess) BpmnVariables(io.automatiko.engine.workflow.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Example 60 with BpmnVariables

use of io.automatiko.engine.workflow.bpmn2.BpmnVariables in project automatiko-engine by automatiko-io.

the class FileSystemProcessInstancesTest method testFindByIdReadMode.

@Test
void testFindByIdReadMode() {
    BpmnProcess process = createProcess(null, "BPMN2-UserTask-Script.bpmn2");
    // workaround as BpmnProcess does not compile the scripts but just reads the xml
    for (io.automatiko.engine.api.definition.process.Node node : ((WorkflowProcess) process.process()).getNodes()) {
        if (node instanceof ActionNode) {
            ProcessAction a = ((ActionNode) node).getAction();
            a.removeMetaData("Action");
            a.setMetaData("Action", new Action() {

                @Override
                public void execute(ProcessContext kcontext) throws Exception {
                    System.out.println("The variable value is " + kcontext.getVariable("s") + " about to call toString on it");
                    kcontext.getVariable("s").toString();
                }
            });
        }
    }
    ProcessInstance<BpmnVariables> mutablePi = process.createInstance(BpmnVariables.create(Collections.singletonMap("var", "value")));
    mutablePi.start();
    assertThat(mutablePi.status()).isEqualTo(STATE_ERROR);
    assertThat(mutablePi.errors()).hasValueSatisfying(errors -> {
        assertThat(errors.errorMessages()).contains("null");
        assertThat(errors.failedNodeIds()).isEqualTo("ScriptTask_1");
    });
    assertThat(mutablePi.variables().toMap()).containsExactly(entry("var", "value"));
    ProcessInstances<BpmnVariables> instances = process.instances();
    assertThat(instances.size()).isOne();
    ProcessInstance<BpmnVariables> pi = instances.findById(mutablePi.id(), ProcessInstance.STATE_ERROR, ProcessInstanceReadMode.READ_ONLY).get();
    assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> pi.abort());
    ProcessInstance<BpmnVariables> readOnlyPi = instances.findById(mutablePi.id(), ProcessInstance.STATE_ERROR, ProcessInstanceReadMode.READ_ONLY).get();
    assertThat(readOnlyPi.status()).isEqualTo(STATE_ERROR);
    assertThat(readOnlyPi.errors()).hasValueSatisfying(errors -> {
        assertThat(errors.failedNodeIds()).isEqualTo("ScriptTask_1");
    });
    assertThat(readOnlyPi.variables().toMap()).containsExactly(entry("var", "value"));
    assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> readOnlyPi.abort());
    instances.findById(mutablePi.id(), ProcessInstance.STATE_ERROR, ProcessInstanceReadMode.MUTABLE).get().abort();
    assertThat(instances.size()).isZero();
}
Also used : ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) BpmnProcess(io.automatiko.engine.workflow.bpmn2.BpmnProcess) Action(io.automatiko.engine.workflow.base.instance.impl.Action) ProcessAction(io.automatiko.engine.workflow.process.core.ProcessAction) ActionNode(io.automatiko.engine.workflow.process.core.node.ActionNode) ProcessContext(io.automatiko.engine.api.runtime.process.ProcessContext) IOException(java.io.IOException) WorkflowProcess(io.automatiko.engine.api.definition.process.WorkflowProcess) BpmnVariables(io.automatiko.engine.workflow.bpmn2.BpmnVariables) 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