Search in sources :

Example 46 with BpmnVariables

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

the class KafkaProcessInstancesIT method testFindByIdReadMode.

@Test
void testFindByIdReadMode() {
    BpmnProcess process = BpmnProcess.from(new ClassPathResource("BPMN2-UserTask-Script.bpmn2")).get(0);
    listener.setKafkaStreams(createStreams(process));
    process.setProcessInstancesFactory(factory);
    process.configure();
    listener.getKafkaStreams().start();
    ProcessInstances<BpmnVariables> instances = process.instances();
    assertThat(instances.size()).isZero();
    ProcessInstance<BpmnVariables> mutablePi = process.createInstance(BpmnVariables.create(singletonMap("var", "value")));
    mutablePi.start();
    assertThat(mutablePi.status()).isEqualTo(STATE_ERROR);
    assertThat(mutablePi.error()).hasValueSatisfying(error -> {
        assertThat(error.errorMessage()).contains("java.lang.NullPointerException");
        assertThat(error.failedNodeId()).isEqualTo("ScriptTask_1");
    });
    assertThat(mutablePi.variables().toMap()).containsExactly(entry("var", "value"));
    await().until(() -> instances.values().size() == 1);
    ProcessInstance<BpmnVariables> pi = instances.findById(mutablePi.id(), ProcessInstanceReadMode.READ_ONLY).get();
    assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> pi.abort());
    ProcessInstance<BpmnVariables> readOnlyPi = instances.findById(mutablePi.id(), ProcessInstanceReadMode.READ_ONLY).get();
    assertThat(readOnlyPi.status()).isEqualTo(STATE_ERROR);
    assertThat(readOnlyPi.error()).hasValueSatisfying(error -> {
        assertThat(error.errorMessage()).contains("java.lang.NullPointerException");
        assertThat(error.failedNodeId()).isEqualTo("ScriptTask_1");
    });
    assertThat(readOnlyPi.variables().toMap()).containsExactly(entry("var", "value"));
    assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> readOnlyPi.abort());
    instances.findById(mutablePi.id()).get().abort();
    assertThat(instances.size()).isZero();
}
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 47 with BpmnVariables

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

the class KafkaProcessInstancesIT method testValuesReadMode.

@Test
void testValuesReadMode() {
    BpmnProcess process = BpmnProcess.from(new ClassPathResource("BPMN2-UserTask.bpmn2")).get(0);
    listener.setKafkaStreams(createStreams(process));
    process.setProcessInstancesFactory(factory);
    process.configure();
    listener.getKafkaStreams().start();
    ProcessInstances<BpmnVariables> instances = process.instances();
    assertThat(instances.size()).isZero();
    ProcessInstance<BpmnVariables> processInstance = process.createInstance(BpmnVariables.create(singletonMap("test", "test")));
    processInstance.start();
    await().until(() -> instances.values().size() == 1);
    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) ClassPathResource(org.drools.core.io.impl.ClassPathResource) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Example 48 with BpmnVariables

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

the class DocumentProcessInstanceMarshallerTest method testUnmarshalProcessInstance.

@Test
void testUnmarshalProcessInstance() {
    ProcessInstance<BpmnVariables> processInstance = (ProcessInstance<BpmnVariables>) marshaller.unmarshallProcessInstance(doc.toJson().getBytes(), process);
    assertNotNull(processInstance, "Unmarshalled value should not be null");
    assertThat(processInstance.id()).isEqualTo(doc.get("id"));
    assertThat(processInstance.description()).isEqualTo(doc.get("description"));
    assertThat(processInstance.description()).isEqualTo("User Task");
    Collection<? extends ProcessInstance<BpmnVariables>> values = process.instances().values();
    assertThat(values).isNotEmpty();
    BpmnVariables variables = processInstance.variables();
    String testVar = (String) variables.get("test");
    assertThat(testVar).isEqualTo("testValue");
}
Also used : ProcessInstance(org.kie.kogito.process.ProcessInstance) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Example 49 with BpmnVariables

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

the class MongoDBProcessInstancesIT method testFindByIdReadMode.

void testFindByIdReadMode(MongoDBTransactionManager transactionManager) {
    BpmnProcess process = BpmnProcess.from(new ClassPathResource("BPMN2-UserTask-Script.bpmn2")).get(0);
    // workaround as BpmnProcess does not compile the scripts but just reads the xml
    for (Node node : ((WorkflowProcess) process.get()).getNodes()) {
        if (node instanceof ActionNode) {
            DroolsAction a = ((ActionNode) node).getAction();
            a.setMetaData("Action", (Action) kcontext -> {
                System.out.println("The variable value is " + kcontext.getVariable("s") + " about to call toString on it");
                kcontext.getVariable("s").toString();
            });
        }
    }
    process.setProcessInstancesFactory(new MongoDBProcessInstancesFactory(mongoClient, transactionManager));
    process.configure();
    ProcessInstance<BpmnVariables> mutablePi = process.createInstance(BpmnVariables.create(Collections.singletonMap("var", "value")));
    mutablePi.start();
    assertThat(mutablePi.status()).isEqualTo(STATE_ERROR);
    assertThat(mutablePi.error()).hasValueSatisfying(error -> {
        assertThat(error.errorMessage()).contains("java.lang.NullPointerException");
        assertThat(error.failedNodeId()).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(), ProcessInstanceReadMode.READ_ONLY).get();
    assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> pi.abort());
    ProcessInstance<BpmnVariables> readOnlyPi = instances.findById(mutablePi.id(), ProcessInstanceReadMode.READ_ONLY).get();
    assertThat(readOnlyPi.status()).isEqualTo(STATE_ERROR);
    assertThat(readOnlyPi.error()).hasValueSatisfying(error -> {
        assertThat(error.errorMessage()).contains("java.lang.NullPointerException");
        assertThat(error.failedNodeId()).isEqualTo("ScriptTask_1");
    });
    assertThat(readOnlyPi.variables().toMap()).containsExactly(entry("var", "value"));
    assertThatExceptionOfType(UnsupportedOperationException.class).isThrownBy(() -> readOnlyPi.abort());
    instances.findById(mutablePi.id()).get().abort();
    assertThat(instances.size()).isZero();
}
Also used : DroolsAction(org.jbpm.workflow.core.DroolsAction) Document(org.bson.Document) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) MongoClient(com.mongodb.client.MongoClient) MongoCollection(com.mongodb.client.MongoCollection) WorkflowProcess(org.jbpm.workflow.core.WorkflowProcess) STATE_ACTIVE(org.kie.kogito.internal.process.runtime.KogitoProcessInstance.STATE_ACTIVE) MongoDBTransactionManager(org.kie.kogito.mongodb.transaction.MongoDBTransactionManager) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) HashMap(java.util.HashMap) ProcessInstances(org.kie.kogito.process.ProcessInstances) ArrayList(java.util.ArrayList) AfterAll(org.junit.jupiter.api.AfterAll) STATE_COMPLETED(org.kie.kogito.internal.process.runtime.KogitoProcessInstance.STATE_COMPLETED) BeforeAll(org.junit.jupiter.api.BeforeAll) Map(java.util.Map) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) StreamSupport(java.util.stream.StreamSupport) DroolsAction(org.jbpm.workflow.core.DroolsAction) UnitOfWorkStartEvent(org.kie.kogito.uow.events.UnitOfWorkStartEvent) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) Container(org.testcontainers.junit.jupiter.Container) ActionNode(org.jbpm.workflow.core.node.ActionNode) BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) StaticIdentityProvider(org.kie.kogito.services.identity.StaticIdentityProvider) Collection(java.util.Collection) Testcontainers(org.testcontainers.junit.jupiter.Testcontainers) MongoClients(com.mongodb.client.MongoClients) SecurityPolicy(org.kie.kogito.auth.SecurityPolicy) Assertions.entry(org.assertj.core.api.Assertions.entry) KogitoProcessInstancesFactory(org.kie.kogito.persistence.KogitoProcessInstancesFactory) DOCUMENT_ID(org.kie.kogito.mongodb.utils.DocumentConstants.DOCUMENT_ID) Test(org.junit.jupiter.api.Test) DocumentConstants(org.kie.kogito.mongodb.utils.DocumentConstants) List(java.util.List) ProcessInstance(org.kie.kogito.process.ProcessInstance) ClassPathResource(org.drools.core.io.impl.ClassPathResource) Node(org.kie.api.definition.process.Node) ProcessInstanceReadMode(org.kie.kogito.process.ProcessInstanceReadMode) STATE_ERROR(org.kie.kogito.internal.process.runtime.KogitoProcessInstance.STATE_ERROR) Action(org.jbpm.process.instance.impl.Action) KogitoMongoDBContainer(org.kie.kogito.testcontainers.KogitoMongoDBContainer) Collections(java.util.Collections) WorkItem(org.kie.kogito.process.WorkItem) UnitOfWorkEndEvent(org.kie.kogito.uow.events.UnitOfWorkEndEvent) BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) ActionNode(org.jbpm.workflow.core.node.ActionNode) Node(org.kie.api.definition.process.Node) ActionNode(org.jbpm.workflow.core.node.ActionNode) WorkflowProcess(org.jbpm.workflow.core.WorkflowProcess) ClassPathResource(org.drools.core.io.impl.ClassPathResource) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables)

Example 50 with BpmnVariables

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

the class MongoDBProcessInstancesIT method test.

private void test(MongoDBTransactionManager transactionManager) {
    BpmnProcess process = BpmnProcess.from(new ClassPathResource("BPMN2-UserTask.bpmn2")).get(0);
    process.setProcessInstancesFactory(new MongoDBProcessInstancesFactory(mongoClient, transactionManager));
    process.configure();
    testIndexCreation(process);
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("test", "test");
    parameters.put("integerVar", 10);
    parameters.put("booleanVar", true);
    parameters.put("doubleVar", 10.11);
    parameters.put("floatVar", 3.5f);
    parameters.put("address", new Address("main street", "Boston", "10005", "US"));
    PersonWithAddresses pa = new PersonWithAddresses("bob", 16);
    List<Address> list = new ArrayList<>();
    list.add(new Address("main street", "Boston", "10005", "US"));
    list.add(new Address("new Street", "Charlotte", "28200", "US"));
    pa.setAddresses(list);
    parameters.put("pa", pa);
    parameters.put("addresslist", list);
    Map<Object, Object> map = new HashMap<>();
    map.put("addresslist", list);
    map.put(1, "ss");
    map.put("2", "kk");
    Map<Object, Object> testMap = new HashMap<>();
    testMap.put("addresslist", list);
    testMap.put(1, "integer");
    testMap.put("2", "string");
    testMap.put("map", map);
    parameters.put("testMap", testMap);
    ProcessInstance<BpmnVariables> processInstance = process.createInstance(BpmnVariables.create(parameters));
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(STATE_ACTIVE);
    assertThat(processInstance.description()).isEqualTo("User Task");
    Collection<? extends ProcessInstance<BpmnVariables>> values = process.instances().values();
    assertThat(values).hasSize(1);
    String testVar = (String) processInstance.variables().get("test");
    assertThat(testVar).isEqualTo("test");
    Object addr = processInstance.variables().get("address");
    assertThat(addr.getClass().getName()).isEqualTo("org.kie.kogito.mongodb.Address");
    Object flt = processInstance.variables().get("floatVar");
    assertThat(flt.getClass().getName()).isEqualTo("java.lang.Float");
    assertThat(processInstance.description()).isEqualTo("User Task");
    List<WorkItem> workItems = processInstance.workItems(securityPolicy);
    assertThat(workItems).hasSize(1);
    WorkItem workItem = workItems.get(0);
    assertEquals("john", workItem.getParameters().get("ActorId"));
    processInstance.completeWorkItem(workItem.getId(), null, securityPolicy);
    assertEquals(STATE_COMPLETED, processInstance.status());
    assertThat(process.instances().size()).isZero();
}
Also used : BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) WorkItem(org.kie.kogito.process.WorkItem) ClassPathResource(org.drools.core.io.impl.ClassPathResource) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables)

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