Search in sources :

Example 31 with BpmnVariables

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

the class FileSystemProcessInstancesTest method testBasicFlowWithTransientVariable.

@Test
void testBasicFlowWithTransientVariable() {
    BpmnProcess process = createProcess(null, "BPMN2-UserTask.bpmn2");
    ProcessInstance<BpmnVariables> processInstance = process.createInstance(BpmnVariables.create(Collections.singletonMap("temp", "test")));
    processInstance.start();
    assertThat(processInstance.variables().get("temp")).isEqualTo("test");
    assertThat(processInstance.status()).isEqualTo(STATE_ACTIVE);
    assertThat(processInstance.description()).isEqualTo("User Task");
    FileSystemProcessInstances fileSystemBasedStorage = (FileSystemProcessInstances) process.instances();
    assertThat(fileSystemBasedStorage.size()).isOne();
    ProcessInstance<BpmnVariables> processInstanceLoaded = (ProcessInstance<BpmnVariables>) fileSystemBasedStorage.findById(processInstance.id()).get();
    assertThat(processInstanceLoaded.variables().get("temp")).isNull();
    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(any(), any());
    assertThat(fileSystemBasedStorage.size()).isZero();
}
Also used : BpmnProcess(io.automatiko.engine.workflow.bpmn2.BpmnProcess) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) WorkItem(io.automatiko.engine.api.workflow.WorkItem) BpmnVariables(io.automatiko.engine.workflow.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Example 32 with BpmnVariables

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

the class PredictionAwareHumanTaskLifeCycleTest method testUserTaskWithoutPredictionService.

@Test
public void testUserTaskWithoutPredictionService() {
    BpmnProcess process = (BpmnProcess) 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_ACTIVE, processInstance.status());
    WorkItem workItem = processInstance.workItems(securityPolicy).get(0);
    assertNotNull(workItem);
    assertEquals("john", workItem.getParameters().get("ActorId"));
    processInstance.completeWorkItem(workItem.getId(), Collections.singletonMap("output", "given value"), securityPolicy);
    assertEquals(STATE_COMPLETED, processInstance.status());
    Model result = (Model) processInstance.variables();
    assertEquals(2, result.toMap().size());
    assertEquals("given value", result.toMap().get("s"));
    assertEquals(1, trainedTasks.size());
}
Also used : BpmnProcess(io.automatiko.engine.workflow.bpmn2.BpmnProcess) Model(io.automatiko.engine.api.Model) WorkItem(io.automatiko.engine.api.workflow.WorkItem) ClassPathResource(io.automatiko.engine.services.io.ClassPathResource) BpmnVariables(io.automatiko.engine.workflow.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Example 33 with BpmnVariables

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

the class SmileRandomForestPredictionTest method testUserTaskWithPredictionService.

@Test
public void testUserTaskWithPredictionService() {
    BpmnProcess process = (BpmnProcess) 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"));
}
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 34 with BpmnVariables

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

the class PredictionAwareHumanTaskLifeCycleTest method testUserTaskWithoutPredictionService.

@Test
public void testUserTaskWithoutPredictionService() {
    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_ACTIVE, processInstance.status());
    WorkItem workItem = processInstance.workItems(securityPolicy).get(0);
    assertNotNull(workItem);
    assertEquals("john", workItem.getParameters().get("ActorId"));
    processInstance.completeWorkItem(workItem.getId(), Collections.singletonMap("output", "given value"), securityPolicy);
    assertEquals(STATE_COMPLETED, processInstance.status());
    Model result = (Model) processInstance.variables();
    assertEquals(2, result.toMap().size());
    assertEquals("given value", result.toMap().get("s"));
    assertEquals(1, trainedTasks.size());
}
Also used : BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) Model(org.kie.kogito.Model) WorkItem(org.kie.kogito.process.WorkItem) InternalKogitoWorkItem(org.kie.kogito.process.workitems.InternalKogitoWorkItem) ClassPathResource(org.drools.core.io.impl.ClassPathResource) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Example 35 with BpmnVariables

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

the class CacheProcessInstancesIT method testBasicFlow.

@Test
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();
    assertEquals(STATE_ACTIVE, processInstance.status());
    assertThat(process.instances().size()).isOne();
    SecurityPolicy asJohn = SecurityPolicy.of(new StaticIdentityProvider("john"));
    assertThat(process.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(process.instances().size()).isZero();
}
Also used : StaticIdentityProvider(org.kie.kogito.services.identity.StaticIdentityProvider) 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)

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