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();
}
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();
}
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);
}
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();
}
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());
}
Aggregations