Search in sources :

Example 36 with WorkItem

use of org.kie.kogito.process.WorkItem in project kogito-runtimes by kiegroup.

the class FileSystemProcessInstancesTest method testBasicFlowWithStartFrom.

@Test
void testBasicFlowWithStartFrom() {
    BpmnProcess process = createProcess("BPMN2-UserTask.bpmn2");
    ProcessInstance<BpmnVariables> processInstance = process.createInstance(BpmnVariables.create(Collections.singletonMap("test", "test")));
    processInstance.startFrom("_2");
    assertThat(processInstance.status()).isEqualTo(STATE_ACTIVE);
    assertThat(processInstance.description()).isEqualTo("User Task");
    FileSystemProcessInstances fileSystemBasedStorage = (FileSystemProcessInstances) process.instances();
    verify(fileSystemBasedStorage).update(any(), any());
    String testVar = (String) processInstance.variables().get("test");
    assertThat(testVar).isEqualTo("test");
    assertThat(processInstance.description()).isEqualTo("User Task");
    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());
    assertThat(fileSystemBasedStorage.size()).isZero();
}
Also used : BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) WorkItem(org.kie.kogito.process.WorkItem) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) FileSystemProcessInstances(org.kie.kogito.persistence.filesystem.FileSystemProcessInstances) Test(org.junit.jupiter.api.Test)

Example 37 with WorkItem

use of org.kie.kogito.process.WorkItem 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.util.io.ClassPathResource) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Example 38 with WorkItem

use of org.kie.kogito.process.WorkItem in project kogito-runtimes by kiegroup.

the class MockCacheProcessInstancesTest method testBasicFlowNoActors.

@Test
public void testBasicFlowNoActors() {
    BpmnProcess process = BpmnProcess.from(new ClassPathResource("BPMN2-UserTask-NoActors.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().get(0);
    assertThat(workItem).isNotNull();
    assertThat(workItem.getParameters().get("ActorId")).isNull();
    List<WorkItem> workItems = processInstance.workItems(SecurityPolicy.of(new StaticIdentityProvider("john")));
    assertThat(workItems).hasSize(1);
    processInstance.completeWorkItem(workItem.getId(), null);
    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.util.io.ClassPathResource) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Example 39 with WorkItem

use of org.kie.kogito.process.WorkItem in project kogito-runtimes by kiegroup.

the class PostgresqlProcessInstancesIT method testBasicFlow.

@Test
void testBasicFlow() {
    BpmnProcess process = createProcess("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");
    PostgresqlProcessInstances processInstances = (PostgresqlProcessInstances) process.instances();
    assertThat(processInstances.size()).isOne();
    assertThat(processInstances.exists(processInstance.id())).isTrue();
    ProcessInstance<?> readOnlyPI = process.instances().findById(processInstance.id(), ProcessInstanceReadMode.READ_ONLY).get();
    assertThat(readOnlyPI.status()).isEqualTo(STATE_ACTIVE);
    assertThat(process.instances().values(ProcessInstanceReadMode.READ_ONLY).size()).isOne();
    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 = (PostgresqlProcessInstances) process.instances();
    verify(processInstances, times(2)).remove(processInstance.id());
    assertThat(processInstances.size()).isZero();
    assertThat(process.instances().values()).isEmpty();
}
Also used : BpmnProcess(org.kie.kogito.process.bpmn2.BpmnProcess) PostgresqlProcessInstances(org.kie.kogito.persistence.postgresql.PostgresqlProcessInstances) WorkItem(org.kie.kogito.process.WorkItem) BpmnVariables(org.kie.kogito.process.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

Example 40 with WorkItem

use of org.kie.kogito.process.WorkItem in project kogito-runtimes by kiegroup.

the class JsonSchemaUtilTest method testJsonSchemaPhases.

@Test
<T> void testJsonSchemaPhases() throws IOException {
    InputStream in = new ByteArrayInputStream(example.getBytes());
    Policy<T>[] policies = new Policy[0];
    Map<String, Object> schemaMap = JsonSchemaUtil.load(in);
    in.close();
    Process<T> process = mock(Process.class);
    ProcessInstances<T> processInstances = mock(ProcessInstances.class);
    when(process.instances()).thenReturn(processInstances);
    ProcessInstance<T> processInstance = mock(ProcessInstance.class);
    when(processInstances.findById("pepe", ProcessInstanceReadMode.READ_ONLY)).thenReturn((Optional) Optional.of(processInstance));
    WorkItem task = mock(WorkItem.class);
    when(processInstance.workItem("task", policies)).thenReturn(task);
    when(task.getPhase()).thenReturn("active");
    Config config = mock(Config.class);
    ProcessConfig processConfig = mock(ProcessConfig.class);
    when(config.get(any())).thenReturn(processConfig);
    WorkItemHandlerConfig workItemHandlerConfig = mock(WorkItemHandlerConfig.class);
    when(processConfig.workItemHandlers()).thenReturn(workItemHandlerConfig);
    KogitoWorkItemHandler workItemHandler = new HumanTaskWorkItemHandler();
    when(workItemHandlerConfig.forName("Human Task")).thenReturn(workItemHandler);
    schemaMap = JsonSchemaUtil.addPhases(process, workItemHandler, "pepe", "task", policies, schemaMap);
    assertFalse(((Collection) schemaMap.get("phases")).isEmpty());
}
Also used : Policy(org.kie.kogito.process.workitem.Policy) HumanTaskWorkItemHandler(org.jbpm.process.instance.impl.humantask.HumanTaskWorkItemHandler) ProcessConfig(org.kie.kogito.process.ProcessConfig) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Config(org.kie.kogito.Config) ProcessConfig(org.kie.kogito.process.ProcessConfig) WorkItemHandlerConfig(org.kie.kogito.process.WorkItemHandlerConfig) KogitoWorkItemHandler(org.kie.kogito.internal.process.runtime.KogitoWorkItemHandler) WorkItem(org.kie.kogito.process.WorkItem) WorkItemHandlerConfig(org.kie.kogito.process.WorkItemHandlerConfig) ByteArrayInputStream(java.io.ByteArrayInputStream) Test(org.junit.jupiter.api.Test)

Aggregations

WorkItem (org.kie.kogito.process.WorkItem)41 Test (org.junit.jupiter.api.Test)38 HashMap (java.util.HashMap)27 Model (org.kie.kogito.Model)26 Application (org.kie.kogito.Application)24 Processes (org.kie.kogito.process.Processes)24 BpmnProcess (org.kie.kogito.process.bpmn2.BpmnProcess)14 BpmnVariables (org.kie.kogito.process.bpmn2.BpmnVariables)14 HumanTaskTransition (org.jbpm.process.instance.impl.humantask.HumanTaskTransition)11 StaticIdentityProvider (org.kie.kogito.services.identity.StaticIdentityProvider)9 ArrayList (java.util.ArrayList)7 ClassPathResource (org.drools.util.io.ClassPathResource)7 SecurityPolicy (org.kie.kogito.auth.SecurityPolicy)5 List (java.util.List)4 Person (org.kie.kogito.codegen.data.Person)3 ProcessConfig (org.kie.kogito.process.ProcessConfig)3 UnitOfWork (org.kie.kogito.uow.UnitOfWork)3 Optional (java.util.Optional)2 Assertions.assertThat (org.assertj.core.api.Assertions.assertThat)2 ActionNode (org.jbpm.workflow.core.node.ActionNode)2