use of io.automatiko.engine.api.workflow.WorkItem in project automatiko-engine by automatiko-io.
the class CallActivityTaskTest method testCallActivityTaskWithSubprocesWaitAndAbort.
@Test
public void testCallActivityTaskWithSubprocesWaitAndAbort() 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");
// 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();
processInstance.abort();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ABORTED);
assertThat(childProcessInstance.status()).isEqualTo(ProcessInstance.STATE_ABORTED);
subprocesses = processInstance.subprocesses();
assertThat(subprocesses).hasSize(0);
assertThat(p.instances().size()).isEqualTo(0);
assertThat(childProcessInstance.process().instances().size()).isEqualTo(0);
}
use of io.automatiko.engine.api.workflow.WorkItem in project automatiko-engine by automatiko-io.
the class CallActivityTaskTest method testCallActivityTaskWithExpressionsForIO.
@Test
public void testCallActivityTaskWithExpressionsForIO() throws Exception {
Application app = generateCodeProcessesOnly("subprocess/CallActivityWithIOexpression.bpmn2", "subprocess/CallActivitySubProcess.bpmn2");
assertThat(app).isNotNull();
Process<? extends Model> p = app.processes().processById("ParentProcess");
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);
Model result = (Model) processInstance.variables();
assertThat(result.toMap()).hasSize(1).containsKeys("person");
Person person = (Person) result.toMap().get("person");
assertEquals("new value", person.getName());
List<WorkItem> workItems = processInstance.workItems(securityPolicy);
assertEquals(1, workItems.size());
WorkItem wi = workItems.get(0);
assertEquals("MyTask", 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_COMPLETED);
}
use of io.automatiko.engine.api.workflow.WorkItem in project automatiko-engine by automatiko-io.
the class EmbeddedSubProcessTest method testEmbeddedSubProcessWithUserTaskAndVariableScopes.
@Test
public void testEmbeddedSubProcessWithUserTaskAndVariableScopes() throws Exception {
Application app = generateCodeProcessesOnly("subprocess/EmbeddedSubProcessWithUserTask.bpmn2");
assertThat(app).isNotNull();
Process<? extends Model> p = app.processes().processById("embeddedWithUserTask_1_0");
Person person = new Person("john", 25);
Model m = p.createModel();
Map<String, Object> parameters = new HashMap<>();
parameters.put("person", person);
m.fromMap(parameters);
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
List<WorkItem> tasks = processInstance.workItems();
assertThat(tasks).hasSize(1);
WorkItem wi = processInstance.workItem(tasks.get(0).getId());
assertThat(wi).isNotNull();
assertThat(wi.getParameters()).containsKey("person");
assertThat(wi.getParameters()).extracting("person").isEqualTo(person);
processInstance.completeWorkItem(tasks.get(0).getId(), new HashMap<>(Collections.singletonMap("person", new Person("mary", 20))));
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
}
use of io.automatiko.engine.api.workflow.WorkItem in project automatiko-engine by automatiko-io.
the class ExportProcessInstanceTest method testBasicUserTaskProcess.
@Test
public void testBasicUserTaskProcess() throws Exception {
ProcessInstanceMarshaller marshaller = new ProcessInstanceMarshaller();
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());
assertEquals("FirstTask", workItems.get(0).getName());
processInstance.completeWorkItem(workItems.get(0).getId(), null, securityPolicy);
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
// exprt process instance
ExportedProcessInstance exported = marshaller.exportProcessInstance(processInstance);
assertThat(exported).isNotNull();
ProcessInstance<?> imported = marshaller.importProcessInstance(exported, p);
workItems = imported.workItems(securityPolicy);
assertEquals(1, workItems.size());
assertEquals("SecondTask", workItems.get(0).getName());
imported.completeWorkItem(workItems.get(0).getId(), null, securityPolicy);
assertThat(imported.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
}
use of io.automatiko.engine.api.workflow.WorkItem in project automatiko-engine by automatiko-io.
the class OrdersProcessService method testOrderProcess.
@GET
@Produces(MediaType.TEXT_PLAIN)
public String testOrderProcess() {
Model m = orderProcess.createModel();
Map<String, Object> parameters = new HashMap<>();
parameters.put("approver", "john");
parameters.put("order", new Order("12345", false, 0.0));
m.fromMap(parameters);
ProcessInstance<?> processInstance = orderProcess.createInstance(m);
processInstance.start();
assert (io.automatiko.engine.api.runtime.process.ProcessInstance.STATE_ACTIVE == processInstance.status());
Model result = (Model) processInstance.variables();
assert (result.toMap().size() == 2);
assert (((Order) result.toMap().get("order")).getTotal() > 0);
ProcessInstances<? extends Model> orderItemProcesses = orderItemsProcess.instances();
assert (orderItemProcesses.values(1, 10).size() == 1);
ProcessInstance<?> childProcessInstance = orderItemProcesses.values(1, 10).iterator().next();
List<WorkItem> workItems = childProcessInstance.workItems();
assert (workItems.size()) == 1;
childProcessInstance.completeWorkItem(workItems.get(0).getId(), null);
assert (io.automatiko.engine.api.runtime.process.ProcessInstance.STATE_COMPLETED == childProcessInstance.status());
assert (io.automatiko.engine.api.runtime.process.ProcessInstance.STATE_COMPLETED == processInstance.status());
// no active process instances for both orders and order items processes
assert (orderProcess.instances().values(1, 10).size() == 0);
assert (orderItemsProcess.instances().values(1, 10).size() == 0);
return "OK";
}
Aggregations