use of io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskTransition in project automatiko-engine by automatiko-io.
the class CallActivityTaskTest method testCallActivityTaskWithSubprocesWaitBusinessKeyFromVars.
@Test
public void testCallActivityTaskWithSubprocesWaitBusinessKeyFromVars() throws Exception {
Application app = generateCodeProcessesOnly("subprocess/CallActivity.bpmn2", "subprocess/CallActivitySubProcessHT.bpmn2", "subprocess/CallActivitySubProcessHT2.bpmn2");
assertThat(app).isNotNull();
Process<? extends Model> p = app.processes().processById("ParentProcess_1");
Model m = p.createModel();
Map<String, Object> parameters = new HashMap<>();
parameters.put("x", "a");
parameters.put("y", "b");
m.fromMap(parameters);
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
Model result = (Model) processInstance.variables();
assertThat(result.toMap()).hasSize(2).containsKeys("x", "y");
assertThat(p.instances().findById("b")).isPresent();
// check if tasks can be accessed via parent process instance even if they are
// in subprocesses
List<WorkItem> workItems = processInstance.workItems(securityPolicy);
assertEquals(1, workItems.size());
WorkItem wi = workItems.get(0);
assertEquals("User Task 1", wi.getName());
assertEquals(Active.ID, wi.getPhase());
assertEquals(Active.STATUS, wi.getPhaseStatus());
// following check shows that task(wi) comes from another process instance
assertNotEquals(processInstance.id(), wi.getProcessInstanceId());
Collection<ProcessInstance<? extends Model>> subprocesses = processInstance.subprocesses();
assertThat(subprocesses).hasSize(1);
ProcessInstance<?> childProcessInstance = subprocesses.iterator().next();
// verify that sub processes can be access by business key defined via variable tagging
Process<? extends Model> sp = (Process<? extends Model>) childProcessInstance.process();
Optional<?> found = sp.instances().findById("b:a");
assertThat(found).isPresent();
workItems = childProcessInstance.workItems(securityPolicy);
assertEquals(1, workItems.size());
wi = workItems.get(0);
assertEquals("User Task 1", wi.getName());
assertEquals(Active.ID, wi.getPhase());
assertEquals(Active.STATUS, wi.getPhaseStatus());
childProcessInstance.transitionWorkItem(workItems.get(0).getId(), new HumanTaskTransition(Complete.ID, null, securityPolicy));
workItems = processInstance.workItems(securityPolicy);
assertEquals(1, workItems.size());
wi = workItems.get(0);
assertEquals("User Task 2", wi.getName());
assertEquals(Active.ID, wi.getPhase());
assertEquals(Active.STATUS, wi.getPhaseStatus());
// following check shows that task(wi) comes from another process instance
assertNotEquals(processInstance.id(), wi.getProcessInstanceId());
subprocesses = childProcessInstance.subprocesses();
assertThat(subprocesses).hasSize(1);
ProcessInstance<?> subChildProcessInstance = subprocesses.iterator().next();
subChildProcessInstance.transitionWorkItem(workItems.get(0).getId(), new HumanTaskTransition(Complete.ID, null, securityPolicy));
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
}
use of io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskTransition in project automatiko-engine by automatiko-io.
the class CallActivityTaskTest method testCallActivityTaskWithSubprocesWait.
@Test
public void testCallActivityTaskWithSubprocesWait() throws Exception {
Application app = generateCodeProcessesOnly("subprocess/CallActivity.bpmn2", "subprocess/CallActivitySubProcessHT.bpmn2", "subprocess/CallActivitySubProcessHT2.bpmn2");
assertThat(app).isNotNull();
Process<? extends Model> p = app.processes().processById("ParentProcess_1");
Model m = p.createModel();
Map<String, Object> parameters = new HashMap<>();
parameters.put("x", "a");
parameters.put("y", "b");
m.fromMap(parameters);
ProcessInstance<?> processInstance = p.createInstance("custom-key", m);
processInstance.start();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
Model result = (Model) processInstance.variables();
assertThat(result.toMap()).hasSize(2).containsKeys("x", "y");
assertThat(p.instances().findById("custom-key")).isPresent();
assertThat(p.instances().findById("b")).isNotPresent();
// check if tasks can be accessed via parent process instance even if they are
// in subprocesses
List<WorkItem> workItems = processInstance.workItems(securityPolicy);
assertEquals(1, workItems.size());
WorkItem wi = workItems.get(0);
assertEquals("User Task 1", wi.getName());
assertEquals(Active.ID, wi.getPhase());
assertEquals(Active.STATUS, wi.getPhaseStatus());
// following check shows that task(wi) comes from another process instance
assertNotEquals(processInstance.id(), wi.getProcessInstanceId());
Collection<ProcessInstance<? extends Model>> subprocesses = processInstance.subprocesses();
assertThat(subprocesses).hasSize(1);
ProcessInstance<?> childProcessInstance = subprocesses.iterator().next();
// verify that sub processes can be access by business key defined via variable tagging
Process<? extends Model> sp = (Process<? extends Model>) childProcessInstance.process();
Optional<?> found = sp.instances().findById("custom-key:a");
assertThat(found).isPresent();
workItems = childProcessInstance.workItems(securityPolicy);
assertEquals(1, workItems.size());
wi = workItems.get(0);
assertEquals("User Task 1", wi.getName());
assertEquals(Active.ID, wi.getPhase());
assertEquals(Active.STATUS, wi.getPhaseStatus());
childProcessInstance.transitionWorkItem(workItems.get(0).getId(), new HumanTaskTransition(Complete.ID, null, securityPolicy));
workItems = processInstance.workItems(securityPolicy);
assertEquals(1, workItems.size());
wi = workItems.get(0);
assertEquals("User Task 2", wi.getName());
assertEquals(Active.ID, wi.getPhase());
assertEquals(Active.STATUS, wi.getPhaseStatus());
// following check shows that task(wi) comes from another process instance
assertNotEquals(processInstance.id(), wi.getProcessInstanceId());
subprocesses = childProcessInstance.subprocesses();
assertThat(subprocesses).hasSize(1);
ProcessInstance<?> subChildProcessInstance = subprocesses.iterator().next();
subChildProcessInstance.transitionWorkItem(workItems.get(0).getId(), new HumanTaskTransition(Complete.ID, null, securityPolicy));
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
}
use of io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskTransition in project automatiko-engine by automatiko-io.
the class UserTaskTest method testBasicUserTaskProcessCancelAndRetriggerNode.
@Test
public void testBasicUserTaskProcessCancelAndRetriggerNode() 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());
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());
String firstSecondTaskNodeInstanceId = wi.getNodeInstanceId();
processInstance.retriggerNodeInstance(wi.getNodeInstanceId());
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());
// since it was retriggered it must have different node instance id
assertNotEquals(firstSecondTaskNodeInstanceId, wi.getNodeInstanceId());
processInstance.transitionWorkItem(workItems.get(0).getId(), new HumanTaskTransition(Complete.ID, null, securityPolicy));
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
}
use of io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskTransition in project automatiko-engine by automatiko-io.
the class UserTaskTest method testApprovalWithExcludedOwnerViaPhases.
@Test
public void testApprovalWithExcludedOwnerViaPhases() 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());
HumanTaskTransition transition = new HumanTaskTransition(Complete.ID, null, identity);
processInstance.transitionWorkItem(workItems.get(0).getId(), transition);
// 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());
transition = new HumanTaskTransition(Complete.ID, null, identity);
processInstance.transitionWorkItem(workItems.get(0).getId(), transition);
assertEquals(io.automatiko.engine.api.runtime.process.ProcessInstance.STATE_COMPLETED, processInstance.status());
}
use of io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskTransition in project automatiko-engine by automatiko-io.
the class UserTaskTest method testBasicUserTaskProcessClaimAndCompleteWrongUser.
@Test
public void testBasicUserTaskProcessClaimAndCompleteWrongUser() 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());
final String wiId = wi.getId();
IdentityProvider identity = new StaticIdentityProvider("kelly");
// if user that is not authorized to work on work item both listing and getting
// by id should apply it
List<WorkItem> securedWorkItems = processInstance.workItems(SecurityPolicy.of(identity));
assertEquals(0, securedWorkItems.size());
assertThrows(WorkItemNotFoundException.class, () -> processInstance.workItem(wiId, SecurityPolicy.of(identity)));
assertThrows(NotAuthorizedException.class, () -> processInstance.transitionWorkItem(wiId, new HumanTaskTransition(Claim.ID, null, identity)));
assertThrows(NotAuthorizedException.class, () -> processInstance.completeWorkItem(wiId, null, SecurityPolicy.of(identity)));
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
workItems = processInstance.workItems(securityPolicy);
assertEquals(1, workItems.size());
wi = workItems.get(0);
assertEquals("FirstTask", wi.getName());
assertEquals(Active.ID, wi.getPhase());
assertEquals(Active.STATUS, wi.getPhaseStatus());
assertEquals(0, wi.getResults().size());
IdentityProvider identityCorrect = new StaticIdentityProvider("john");
processInstance.transitionWorkItem(workItems.get(0).getId(), new HumanTaskTransition(Complete.ID, null, identityCorrect));
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);
}
Aggregations