Search in sources :

Example 1 with BpmnProcess

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

the class KafkaProcessInstancesIT method testBasicFlow.

@Test
void testBasicFlow() {
    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();
    assertEquals(STATE_ACTIVE, processInstance.status());
    await().until(() -> instances.values().size() == 1);
    SecurityPolicy asJohn = SecurityPolicy.of(IdentityProviders.of("john"));
    assertThat(instances.values().iterator().next().workItems(asJohn)).hasSize(1);
    List<WorkItem> workItems = processInstance.workItems(asJohn);
    assertThat(workItems).hasSize(1);
    WorkItem workItem = workItems.get(0);
    assertEquals("john", workItem.getParameters().get("ActorId"));
    processInstance.completeWorkItem(workItem.getId(), null, asJohn);
    assertEquals(STATE_COMPLETED, processInstance.status());
    assertThat(instances.size()).isZero();
}
Also used : BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) SecurityPolicy(org.kie.kogito.auth.SecurityPolicy) 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 2 with BpmnProcess

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

the class PredictionAwareHumanTaskLifeCycleTest method testUserTaskWithPredictionService.

@Test
public void testUserTaskWithPredictionService() {
    predictNow.set(true);
    BpmnProcess process = BpmnProcess.from(config, new ClassPathResource("BPMN2-UserTask.bpmn2")).get(0);
    process.configure();
    ProcessInstance<BpmnVariables> processInstance = process.createInstance(BpmnVariables.create(Collections.singletonMap("test", "test")));
    processInstance.start();
    assertEquals(STATE_COMPLETED, processInstance.status());
    Model result = (Model) processInstance.variables();
    assertEquals(2, result.toMap().size());
    assertEquals("predicted value", result.toMap().get("s"));
    assertEquals(0, trainedTasks.size());
}
Also used : BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) Model(org.kie.kogito.Model) ClassPathResource(org.drools.core.io.impl.ClassPathResource) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Example 3 with BpmnProcess

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

the class CacheProcessInstancesIT method testValuesReadMode.

@Test
void testValuesReadMode() {
    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();
    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) ClassPathResource(org.drools.core.io.impl.ClassPathResource) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Example 4 with BpmnProcess

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

the class CacheProcessInstancesIT method testFindByIdReadMode.

@Test
void testFindByIdReadMode() {
    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 CacheProcessInstancesFactory(cacheManager));
    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) BeforeEach(org.junit.jupiter.api.BeforeEach) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) WorkflowProcess(org.jbpm.workflow.core.WorkflowProcess) STATE_ACTIVE(org.kie.kogito.internal.process.runtime.KogitoProcessInstance.STATE_ACTIVE) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ProcessInstances(org.kie.kogito.process.ProcessInstances) RemoteCacheManager(org.infinispan.client.hotrod.RemoteCacheManager) STATE_COMPLETED(org.kie.kogito.internal.process.runtime.KogitoProcessInstance.STATE_COMPLETED) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) DroolsAction(org.jbpm.workflow.core.DroolsAction) 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) Testcontainers(org.testcontainers.junit.jupiter.Testcontainers) ConfigurationBuilder(org.infinispan.client.hotrod.configuration.ConfigurationBuilder) SecurityPolicy(org.kie.kogito.auth.SecurityPolicy) Assertions.entry(org.assertj.core.api.Assertions.entry) KogitoProcessInstancesFactory(org.kie.kogito.persistence.KogitoProcessInstancesFactory) Test(org.junit.jupiter.api.Test) List(java.util.List) AfterEach(org.junit.jupiter.api.AfterEach) KogitoInfinispanContainer(org.kie.kogito.testcontainers.KogitoInfinispanContainer) 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) Collections(java.util.Collections) WorkItem(org.kie.kogito.process.WorkItem) 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) Test(org.junit.jupiter.api.Test)

Example 5 with BpmnProcess

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

the class MockCacheProcessInstancesTest method testBasicFlowWithError.

private void testBasicFlowWithError(Consumer<ProcessInstance<BpmnVariables>> op) {
    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 CacheProcessInstancesFactory(cacheManager));
    process.configure();
    ProcessInstance<BpmnVariables> processInstance = process.createInstance(BpmnVariables.create());
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(STATE_ERROR);
    Optional<ProcessError> errorOp = processInstance.error();
    assertThat(errorOp).isPresent();
    assertThat(errorOp.get().failedNodeId()).isEqualTo("ScriptTask_1");
    assertThat(errorOp.get().errorMessage()).isNotNull().contains("java.lang.NullPointerException");
    op.accept(processInstance);
    assertThat(processInstance.error()).isNotPresent();
    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 : DroolsAction(org.jbpm.workflow.core.DroolsAction) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) BeforeEach(org.junit.jupiter.api.BeforeEach) MetadataValueImpl(org.infinispan.client.hotrod.impl.MetadataValueImpl) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) WorkflowProcess(org.jbpm.workflow.core.WorkflowProcess) STATE_ACTIVE(org.kie.kogito.internal.process.runtime.KogitoProcessInstance.STATE_ACTIVE) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) RemoteCache(org.infinispan.client.hotrod.RemoteCache) ProcessInstances(org.kie.kogito.process.ProcessInstances) RemoteCacheManager(org.infinispan.client.hotrod.RemoteCacheManager) STATE_COMPLETED(org.kie.kogito.internal.process.runtime.KogitoProcessInstance.STATE_COMPLETED) Assertions.assertThatThrownBy(org.assertj.core.api.Assertions.assertThatThrownBy) Assertions.assertThatExceptionOfType(org.assertj.core.api.Assertions.assertThatExceptionOfType) DroolsAction(org.jbpm.workflow.core.DroolsAction) RemoteCacheManagerAdmin(org.infinispan.client.hotrod.RemoteCacheManagerAdmin) ActionNode(org.jbpm.workflow.core.node.ActionNode) BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) StaticIdentityProvider(org.kie.kogito.services.identity.StaticIdentityProvider) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) SecurityPolicy(org.kie.kogito.auth.SecurityPolicy) Mockito.when(org.mockito.Mockito.when) Assertions.entry(org.assertj.core.api.Assertions.entry) KogitoProcessInstancesFactory(org.kie.kogito.persistence.KogitoProcessInstancesFactory) Consumer(java.util.function.Consumer) Test(org.junit.jupiter.api.Test) List(java.util.List) ProcessInstance(org.kie.kogito.process.ProcessInstance) ClassPathResource(org.drools.core.io.impl.ClassPathResource) Node(org.kie.api.definition.process.Node) ProcessError(org.kie.kogito.process.ProcessError) ProcessInstanceReadMode(org.kie.kogito.process.ProcessInstanceReadMode) STATE_ERROR(org.kie.kogito.internal.process.runtime.KogitoProcessInstance.STATE_ERROR) Optional(java.util.Optional) Action(org.jbpm.process.instance.impl.Action) Collections(java.util.Collections) WorkItem(org.kie.kogito.process.WorkItem) ProcessInstanceNotFoundException(org.kie.kogito.process.ProcessInstanceNotFoundException) Mockito.mock(org.mockito.Mockito.mock) StaticIdentityProvider(org.kie.kogito.services.identity.StaticIdentityProvider) 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) WorkItem(org.kie.kogito.process.WorkItem) ClassPathResource(org.drools.core.io.impl.ClassPathResource) ProcessError(org.kie.kogito.process.ProcessError) WorkflowProcess(org.jbpm.workflow.core.WorkflowProcess) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables)

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