use of io.automatiko.engine.api.workflow.WorkItem in project automatiko-engine by automatiko-io.
the class MessageStartEventTest method testMultipleMessagesStartEventProcess.
@Test
public void testMultipleMessagesStartEventProcess() throws Exception {
Application app = generateCodeProcessesOnly("messagestartevent/MessageAndMessageStartEvent.bpmn2");
assertThat(app).isNotNull();
Process<? extends Model> p = app.processes().processById("MessageStartEvent");
Model m = p.createModel();
Map<String, Object> parameters = new HashMap<>();
m.fromMap(parameters);
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start("customers", null, "CUS-00998877");
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
Model result = (Model) processInstance.variables();
assertThat(result.toMap()).hasSize(2).containsKeys("customerId");
assertThat(result.toMap().get("customerId")).isNotNull().isEqualTo("CUS-00998877");
processInstance.send(Sig.of("managers", "John the manager"));
List<WorkItem> workItems = processInstance.workItems(securityPolicy);
assertEquals(2, workItems.size());
result = (Model) processInstance.variables();
assertThat(result.toMap()).hasSize(2).containsKeys("customerId", "path");
assertThat(result.toMap().get("customerId")).isNotNull().isEqualTo("CUS-00998877");
assertThat(result.toMap().get("path")).isNotNull().isEqualTo("John the manager");
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 AdHocFragmentsTest method testStartUserTask.
@Test
void testStartUserTask() throws Exception {
String taskName = "AdHoc User Task";
Application app = generateCodeProcessesOnly("cases/AdHocFragments.bpmn");
assertThat(app).isNotNull();
Process<? extends Model> p = app.processes().processById("TestCase.AdHocFragments_1_0");
ProcessInstance<? extends Model> processInstance = p.createInstance(p.createModel());
processInstance.start();
Optional<WorkItem> workItem = processInstance.workItems().stream().filter(wi -> wi.getParameters().get("NodeName").equals(taskName)).findFirst();
assertThat(workItem).isNotPresent();
processInstance.send(Sig.of(taskName, p.createModel()));
assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.status());
workItem = processInstance.workItems().stream().filter(wi -> wi.getParameters().get("NodeName").equals(taskName)).findFirst();
assertThat(workItem).isPresent();
assertThat(workItem.get().getId()).isNotBlank();
assertThat(workItem.get().getName()).isNotBlank();
}
use of io.automatiko.engine.api.workflow.WorkItem in project automatiko-engine by automatiko-io.
the class AdHocSubProcessTest method testCompletionAdHoc.
@Test
void testCompletionAdHoc() throws Exception {
Application app = generateCodeProcessesOnly("cases/CompletionAdHoc.bpmn");
assertThat(app).isNotNull();
Process<? extends Model> p = app.processes().processById("TestCase.CompletionAdHoc_1_0");
Model model = p.createModel();
Map<String, Object> params = new HashMap<>();
params.put("favouriteColour", "yellow");
model.fromMap(params);
ProcessInstance<?> processInstance = p.createInstance(model);
assertState(processInstance, ProcessInstance.STATE_PENDING);
processInstance.start();
assertState(processInstance, ProcessInstance.STATE_ACTIVE);
List<WorkItem> workItems = processInstance.workItems();
assertThat(workItems.size()).isEqualTo(1);
WorkItem workItem = workItems.get(0);
workItem.getParameters().put("favouriteColour", "green");
params.put("favouriteColour", "green");
processInstance.completeWorkItem(workItem.getId(), params);
assertState(processInstance, ProcessInstance.STATE_COMPLETED);
}
use of io.automatiko.engine.api.workflow.WorkItem in project automatiko-engine by automatiko-io.
the class BusinessRuleTaskTest method testDecisionWithErrorHandling.
@Test
public void testDecisionWithErrorHandling() throws Exception {
Application app = generateCode(Collections.singletonList("decision/models/dmnprocess.bpmn2"), Collections.emptyList(), Collections.singletonList("decision/models/vacationDaysAlt/VacationDays.dmn"), Collections.emptyList(), false);
Process<? extends Model> p = app.processes().processById("DmnProcess_1_0");
Model m = p.createModel();
HashMap<String, Object> vars = new HashMap<>();
vars.put("age", 1);
vars.put("yearsOfService", 1);
m.fromMap(vars);
ProcessInstance<? extends Model> processInstance = p.createInstance(m);
processInstance.start();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
List<WorkItem> items = processInstance.workItems();
assertThat(items).hasSize(1);
WorkItem wi = items.get(0);
assertThat(wi.getName()).isEqualTo("analyze");
assertThat(wi.getParameters()).containsKey("error");
@SuppressWarnings("unchecked") Map<String, Object> error = (Map<String, Object>) wi.getParameters().get("error");
assertThat(error).containsKey("error");
assertThat(error).containsKey("results");
processInstance.completeWorkItem(wi.getId(), null);
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 testCallActivityTaskWithExpressionsForIONested.
@Test
public void testCallActivityTaskWithExpressionsForIONested() throws Exception {
Application app = generateCodeProcessesOnly("subprocess/CallActivityWithIOexpressionNested.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<>();
PersonWithAddress pa = new PersonWithAddress("john", 0);
pa.setAddress(new Address("test", null, null, null));
parameters.put("person", pa);
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");
PersonWithAddress person = (PersonWithAddress) result.toMap().get("person");
assertEquals("john", person.getName());
assertEquals("test", person.getAddress().getStreet());
assertEquals("new value", person.getAddress().getCity());
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);
}
Aggregations