use of io.automatiko.engine.api.workflow.WorkItem in project automatiko-engine by automatiko-io.
the class MilestoneTest method testConditionalMilestone.
@Test
void testConditionalMilestone() throws Exception {
Application app = generateCodeProcessesOnly("cases/milestones/ConditionalMilestone.bpmn");
assertThat(app).isNotNull();
Process<? extends Model> p = app.processes().processById("TestCase.ConditionalMilestone_1_0");
Model model = p.createModel();
Map<String, Object> params = new HashMap<>();
params.put("favouriteColour", "orange");
model.fromMap(params);
ProcessInstance<?> processInstance = p.createInstance(model);
assertState(processInstance, ProcessInstance.STATE_PENDING);
Collection<Milestone> expected = new ArrayList<>();
expected.add(Milestone.builder().withName("Milestone").withStatus(AVAILABLE).build());
assertMilestones(expected, processInstance.milestones());
processInstance.start();
assertState(processInstance, ProcessInstance.STATE_ACTIVE);
expected = expected.stream().map(m -> Milestone.builder().withId(m.getId()).withName(m.getName()).withStatus(AVAILABLE).build()).collect(Collectors.toList());
assertMilestones(expected, processInstance.milestones());
List<WorkItem> workItems = processInstance.workItems();
params.put("favouriteColour", "blue");
processInstance.completeWorkItem(workItems.get(0).getId(), params);
expected = expected.stream().map(m -> Milestone.builder().withId(m.getId()).withName(m.getName()).withStatus(COMPLETED).build()).collect(Collectors.toList());
assertMilestones(expected, processInstance.milestones());
}
use of io.automatiko.engine.api.workflow.WorkItem in project automatiko-engine by automatiko-io.
the class ExportProcessInstanceTest method testBasicUserTaskProcessArchive.
@Test
public void testBasicUserTaskProcessArchive() 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<>();
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);
// archive active process instance
ArchivedProcessInstance archived = processInstance.archive(new ArchiveBuilder() {
@Override
public ArchivedVariable variable(String name, Object value) {
return new ArchivedVariable(name, value) {
@Override
public byte[] data() {
return getValue().toString().getBytes();
}
};
}
@Override
public ArchivedProcessInstance instance(String id, String processId, ExportedProcessInstance<?> exported) {
return new ArchivedProcessInstance(id, processId, exported);
}
});
assertThat(archived).isNotNull();
assertThat(archived.getExport()).isNotNull();
assertThat(archived.getVariables()).isNotNull();
assertThat(archived.getSubInstances()).isNotNull();
assertThat(archived.getVariables()).hasSize(1);
assertThat(archived.getSubInstances()).hasSize(0);
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);
// and now let's export completed instance
archived = processInstance.archive(new ArchiveBuilder() {
@Override
public ArchivedVariable variable(String name, Object value) {
return new ArchivedVariable(name, value) {
@Override
public byte[] data() {
return getValue().toString().getBytes();
}
};
}
@Override
public ArchivedProcessInstance instance(String id, String processId, ExportedProcessInstance<?> exported) {
return new ArchivedProcessInstance(id, processId, exported);
}
});
assertThat(archived).isNotNull();
assertThat(archived.getExport()).isNotNull();
assertThat(archived.getVariables()).isNotNull();
assertThat(archived.getSubInstances()).isNotNull();
assertThat(archived.getVariables()).hasSize(1);
assertThat(archived.getSubInstances()).hasSize(0);
}
use of io.automatiko.engine.api.workflow.WorkItem 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.api.workflow.WorkItem 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.api.workflow.WorkItem in project automatiko-engine by automatiko-io.
the class CompensationEventTest method testEndEventCompensationEventProcess.
@Test
public void testEndEventCompensationEventProcess() throws Exception {
Application app = generateCodeProcessesOnly("compensation/UserTaskBeforeAssociatedActivityEnd.bpmn2");
Process<? extends Model> p = app.processes().processById("CompensateEndEvent");
Model m = p.createModel();
Map<String, Object> parameters = new HashMap<>();
parameters.put("x", "0");
m.fromMap(parameters);
ProcessInstance<? extends Model> processInstance = p.createInstance(m);
processInstance.start();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
List<WorkItem> workItems = processInstance.workItems();
assertEquals(1, workItems.size());
assertEquals("task", workItems.get(0).getName());
processInstance.completeWorkItem(workItems.get(0).getId(), null);
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
assertThat(processInstance.variables().toMap()).containsEntry("x", "1");
}
Aggregations