use of io.automatiko.engine.api.workflow.WorkItem in project automatiko-engine by automatiko-io.
the class UserTaskTest method testBasicUserTaskProcessWithTags.
@SuppressWarnings({ "unchecked", "rawtypes" })
@Test
public void testBasicUserTaskProcessWithTags() throws Exception {
Application app = generateCodeProcessesOnly("usertask/UserTasksProcessTags.bpmn2");
assertThat(app).isNotNull();
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);
assertThat(processInstance.tags()).isNotNull();
assertThat(processInstance.tags().values()).hasSize(2).contains("important", "john");
processInstance.tags().add("custom tag");
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);
assertThat(processInstance.tags().values()).hasSize(3).contains("important", "john", "custom tag");
Tag delete = processInstance.tags().get().stream().filter(t -> t.getValue().equals("custom tag")).findFirst().get();
processInstance.tags().remove(delete.getId());
m = p.createModel();
Map<String, Object> updates = new HashMap<String, Object>();
updates.put("name", "mary");
m.fromMap(updates);
((ProcessInstance) processInstance).updateVariables(m);
assertThat(processInstance.tags().values()).hasSize(2).contains("important", "mary");
workItems = processInstance.workItems(securityPolicy);
assertEquals(1, workItems.size());
assertEquals("SecondTask", workItems.get(0).getName());
processInstance.completeWorkItem(workItems.get(0).getId(), null, securityPolicy);
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
assertThat(processInstance.tags().values()).hasSize(2).doesNotContain(delete.getValue());
}
use of io.automatiko.engine.api.workflow.WorkItem in project automatiko-engine by automatiko-io.
the class UserTaskTest method testBasicUserTaskProcessDataInputOutput.
@Test
public void testBasicUserTaskProcessDataInputOutput() throws Exception {
Application app = generateCodeProcessesOnly("usertask/UserTasksProcessIO.bpmn2");
assertThat(app).isNotNull();
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);
workItems = processInstance.workItems(securityPolicy);
assertEquals(1, workItems.size());
assertEquals("SecondTask", workItems.get(0).getName());
processInstance.completeWorkItem(workItems.get(0).getId(), null, securityPolicy);
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
}
use of io.automatiko.engine.api.workflow.WorkItem in project automatiko-engine by automatiko-io.
the class UserTaskTest method testUserTaskWithIOexpressionProcess.
@Test
public void testUserTaskWithIOexpressionProcess() throws Exception {
Application app = generateCodeProcessesOnly("usertask/UserTaskWithIOexpression.bpmn2");
assertThat(app).isNotNull();
Process<? extends Model> p = app.processes().processById("UserTask");
Model m = p.createModel();
Map<String, Object> parameters = new HashMap<>();
parameters.put("person", new Person("john", 0));
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("Hello", workItems.get(0).getName());
assertEquals("john", workItems.get(0).getParameters().get("personName"));
processInstance.completeWorkItem(workItems.get(0).getId(), Collections.singletonMap("personAge", 50), securityPolicy);
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
Model output = (Model) processInstance.variables();
Person person = (Person) output.toMap().get("person");
assertEquals(50, person.getAge());
}
use of io.automatiko.engine.api.workflow.WorkItem in project automatiko-engine by automatiko-io.
the class UserTaskTest method testBasicUserTaskProcessCancelAndTriggerNode.
@Test
public void testBasicUserTaskProcessCancelAndTriggerNode() 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.cancelNodeInstance(wi.getNodeInstanceId());
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
processInstance.triggerNode("UserTask_2");
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 triggered again 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.api.workflow.WorkItem in project automatiko-engine by automatiko-io.
the class UserTaskTest method testBasicUserTaskProcessClaimAndCompletePhasesWithIdentity.
@Test
public void testBasicUserTaskProcessClaimAndCompletePhasesWithIdentity() throws Exception {
Application app = generateCodeProcessesOnly("usertask/UserTasksProcess.bpmn2");
assertThat(app).isNotNull();
final List<String> workItemTransitionEvents = new ArrayList<>();
((DefaultProcessEventListenerConfig) app.config().process().processEventListeners()).listeners().add(new DefaultProcessEventListener() {
@Override
public void beforeWorkItemTransition(ProcessWorkItemTransitionEvent event) {
workItemTransitionEvents.add("BEFORE:: " + event);
}
@Override
public void afterWorkItemTransition(ProcessWorkItemTransitionEvent event) {
workItemTransitionEvents.add("AFTER:: " + event);
}
});
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(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);
assertThat(workItemTransitionEvents).hasSize(10);
}
Aggregations