use of io.automatiko.engine.api.Application 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.Application in project automatiko-engine by automatiko-io.
the class CallActivityTaskTest method testBasicCallActivityTask.
@Test
public void testBasicCallActivityTask() throws Exception {
Application app = generateCodeProcessesOnly("subprocess/CallActivity.bpmn2", "subprocess/CallActivitySubProcess.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_COMPLETED);
Model result = (Model) processInstance.variables();
assertThat(result.toMap()).hasSize(2).containsKeys("x", "y");
assertThat(result.toMap().get("y")).isNotNull().isEqualTo("new value");
assertThat(result.toMap().get("x")).isNotNull().isEqualTo("a");
}
use of io.automatiko.engine.api.Application 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);
}
use of io.automatiko.engine.api.Application 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.Application 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);
}
Aggregations