use of io.automatiko.engine.api.workflow.WorkItem in project automatiko-engine by automatiko-io.
the class UserTaskTest method testBasicUserTaskProcessExecutionTimeout.
@Test
public void testBasicUserTaskProcessExecutionTimeout() throws Exception {
Application app = generateCodeProcessesOnly("usertask/UserTasksProcessExecTimeout.bpmn2");
assertThat(app).isNotNull();
NodeLeftCountDownProcessEventListener listener = new NodeLeftCountDownProcessEventListener("Execution timeout :: end", 1);
((DefaultProcessEventListenerConfig) app.config().process().processEventListeners()).register(listener);
Process<? extends Model> p = app.processes().processById("UserTasksProcess");
Model m = p.createModel();
Map<String, Object> parameters = new HashMap<>();
parameters.put("name", "john");
m.fromMap(parameters);
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
List<WorkItem> workItems = processInstance.workItems(securityPolicy);
assertEquals(1, workItems.size());
assertEquals("FirstTask", workItems.get(0).getName());
processInstance.completeWorkItem(workItems.get(0).getId(), null, securityPolicy);
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
boolean completed = listener.waitTillCompleted(3000);
assertThat(completed).isTrue();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ABORTED);
}
use of io.automatiko.engine.api.workflow.WorkItem in project automatiko-engine by automatiko-io.
the class UserTaskTest method testApprovalWithExcludedOwner.
@Test
public void testApprovalWithExcludedOwner() throws Exception {
Application app = generateCodeProcessesOnly("usertask/approval.bpmn2");
assertThat(app).isNotNull();
Process<? extends Model> p = app.processes().processById("approvals");
Model m = p.createModel();
Map<String, Object> parameters = new HashMap<>();
m.fromMap(parameters);
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start();
assertEquals(io.automatiko.engine.api.runtime.process.ProcessInstance.STATE_ACTIVE, processInstance.status());
StaticIdentityProvider identity = new StaticIdentityProvider("admin", Collections.singletonList("managers"));
SecurityPolicy policy = SecurityPolicy.of(identity);
processInstance.workItems(policy);
List<WorkItem> workItems = processInstance.workItems(policy);
assertEquals(1, workItems.size());
processInstance.completeWorkItem(workItems.get(0).getId(), null, policy);
// actual owner of the first task is excluded owner on the second task so won't
// find it
workItems = processInstance.workItems(policy);
assertEquals(0, workItems.size());
identity = new StaticIdentityProvider("john", Collections.singletonList("managers"));
policy = SecurityPolicy.of(identity);
workItems = processInstance.workItems(policy);
assertEquals(1, workItems.size());
processInstance.completeWorkItem(workItems.get(0).getId(), null, policy);
assertEquals(io.automatiko.engine.api.runtime.process.ProcessInstance.STATE_COMPLETED, processInstance.status());
}
use of io.automatiko.engine.api.workflow.WorkItem in project automatiko-engine by automatiko-io.
the class UserTaskTest method testBasicUserTaskProcessClaimReleaseClaimAndCompletePhases.
@Test
public void testBasicUserTaskProcessClaimReleaseClaimAndCompletePhases() throws Exception {
Application app = generateCodeProcessesOnly("usertask/UserTasksProcess.bpmn2");
assertThat(app).isNotNull();
Process<? extends Model> p = app.processes().processById("UserTasksProcess");
Model m = p.createModel();
Map<String, Object> parameters = new HashMap<>();
m.fromMap(parameters);
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
List<WorkItem> workItems = processInstance.workItems(securityPolicy);
assertEquals(1, workItems.size());
WorkItem wi = workItems.get(0);
assertEquals("FirstTask", wi.getName());
assertEquals(Active.ID, wi.getPhase());
assertEquals(Active.STATUS, wi.getPhaseStatus());
assertEquals(0, wi.getResults().size());
processInstance.transitionWorkItem(workItems.get(0).getId(), new HumanTaskTransition(Claim.ID, Collections.singletonMap("test", "value"), securityPolicy));
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
workItems = processInstance.workItems(securityPolicy);
assertEquals(1, workItems.size());
wi = workItems.get(0);
assertEquals("FirstTask", wi.getName());
assertEquals(Claim.ID, wi.getPhase());
assertEquals(Claim.STATUS, wi.getPhaseStatus());
assertEquals(2, wi.getResults().size());
assertEquals("value", wi.getResults().get("test"));
assertEquals("john", wi.getResults().get("ActorId"));
processInstance.transitionWorkItem(workItems.get(0).getId(), new HumanTaskTransition(Release.ID, null, securityPolicy));
workItems = processInstance.workItems(securityPolicy);
assertEquals(1, workItems.size());
wi = workItems.get(0);
assertEquals("FirstTask", wi.getName());
assertEquals(Release.ID, wi.getPhase());
assertEquals(Release.STATUS, wi.getPhaseStatus());
assertEquals(2, wi.getResults().size());
assertEquals("value", wi.getResults().get("test"));
assertEquals("john", wi.getResults().get("ActorId"));
processInstance.transitionWorkItem(workItems.get(0).getId(), new HumanTaskTransition(Claim.ID, Collections.singletonMap("test", "value"), securityPolicy));
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
workItems = processInstance.workItems(securityPolicy);
assertEquals(1, workItems.size());
wi = workItems.get(0);
assertEquals("FirstTask", wi.getName());
assertEquals(Claim.ID, wi.getPhase());
assertEquals(Claim.STATUS, wi.getPhaseStatus());
assertEquals(2, wi.getResults().size());
assertEquals("value", wi.getResults().get("test"));
assertEquals("john", wi.getResults().get("ActorId"));
processInstance.transitionWorkItem(workItems.get(0).getId(), new HumanTaskTransition(Complete.ID, null, securityPolicy));
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
workItems = processInstance.workItems(securityPolicy);
assertEquals(1, workItems.size());
wi = workItems.get(0);
assertEquals("SecondTask", wi.getName());
assertEquals(Active.ID, wi.getPhase());
assertEquals(Active.STATUS, wi.getPhaseStatus());
assertEquals(0, wi.getResults().size());
processInstance.abort();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ABORTED);
}
use of io.automatiko.engine.api.workflow.WorkItem in project automatiko-engine by automatiko-io.
the class FileSystemProcessInstancesTest method testBasicFlowWithStartFrom.
@Test
void testBasicFlowWithStartFrom() {
BpmnProcess process = createProcess(null, "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, times(1)).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(), any());
assertThat(fileSystemBasedStorage.size()).isZero();
}
use of io.automatiko.engine.api.workflow.WorkItem in project automatiko-engine by automatiko-io.
the class FileSystemProcessInstancesTest method testBasicFlow.
@Test
void testBasicFlow() {
BpmnProcess process = createProcess(null, "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");
FileSystemProcessInstances fileSystemBasedStorage = (FileSystemProcessInstances) process.instances();
assertThat(fileSystemBasedStorage.size()).isOne();
Collection findByTag = fileSystemBasedStorage.findByIdOrTag(ProcessInstanceReadMode.READ_ONLY, "important");
assertThat(findByTag).hasSize(1);
verify(fileSystemBasedStorage, times(2)).create(any(), any());
verify(fileSystemBasedStorage, times(1)).setMetadata(any(), eq(FileSystemProcessInstances.PI_DESCRIPTION), eq("User Task"));
verify(fileSystemBasedStorage, times(1)).setMetadata(any(), eq(FileSystemProcessInstances.PI_STATUS), eq("1"));
String testVar = (String) processInstance.variables().get("test");
assertThat(testVar).isEqualTo("test");
assertThat(processInstance.description()).isEqualTo("User Task");
assertThat(process.instances().values(1, 10).iterator().next().workItems(securityPolicy)).hasSize(1);
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();
}
Aggregations