use of io.automatiko.engine.api.Application 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.Application in project automatiko-engine by automatiko-io.
the class EmbeddedSubProcessTest method testEmbeddedSubprocessServiceProcessTaskWithRetry.
@Test
@Timeout(unit = TimeUnit.SECONDS, value = 10)
public void testEmbeddedSubprocessServiceProcessTaskWithRetry() throws Exception {
Application app = generateCodeProcessesOnly("subprocess/EmbeddedSubprocessWihErrorRetry.bpmn2");
assertThat(app).isNotNull();
NodeLeftCountDownProcessEventListener listener = new NodeLeftCountDownProcessEventListener("Error happened", 1);
((DefaultProcessEventListenerConfig) app.config().process().processEventListeners()).register(listener);
Process<? extends Model> p = app.processes().processById("subprocessRetry");
Model m = p.createModel();
Map<String, Object> parameters = new HashMap<>();
parameters.put("name", "john");
m.fromMap(parameters);
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start();
listener.waitTillCompleted();
assertThat(processInstance.startDate()).isNotNull();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
Model result = (Model) processInstance.variables();
assertThat(result.toMap()).hasSize(2).containsKeys("name", "ErrorData");
assertThat(result.toMap().get("name")).isNotNull().isEqualTo("john");
assertThat(result.toMap().get("ErrorData")).isNotNull().isInstanceOf(WorkItemExecutionError.class);
assertThat(((WorkItemExecutionError) result.toMap().get("ErrorData")).getErrorCode()).isEqualTo("500");
}
use of io.automatiko.engine.api.Application in project automatiko-engine by automatiko-io.
the class EventSubProcessTest method testEventErrorSubProcessDefaultHander.
@Test
public void testEventErrorSubProcessDefaultHander() throws Exception {
Application app = generateCodeProcessesOnly("event-subprocess/EventSubprocessErrorDefault.bpmn2");
assertThat(app).isNotNull();
NodeLeftCountDownProcessEventListener listener = new NodeLeftCountDownProcessEventListener("end-sub", 1);
((DefaultProcessEventListenerConfig) app.config().process().processEventListeners()).register(listener);
Process<? extends Model> p = app.processes().processById("EventSubprocessError_1");
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);
listener.waitTillCompleted(5000);
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ABORTED);
}
use of io.automatiko.engine.api.Application in project automatiko-engine by automatiko-io.
the class EventSubProcessTest method testEventTimerCycleISOSubProcess.
@Test
public void testEventTimerCycleISOSubProcess() throws Exception {
Application app = generateCodeProcessesOnly("event-subprocess/EventSubprocessTimerCycle.bpmn2");
assertThat(app).isNotNull();
NodeLeftCountDownProcessEventListener listener = new NodeLeftCountDownProcessEventListener("start-sub", 2);
((DefaultProcessEventListenerConfig) app.config().process().processEventListeners()).register(listener);
Process<? extends Model> p = app.processes().processById("EventSubprocessTimer_1");
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);
boolean completed = listener.waitTillCompleted(5000);
assertThat(completed).isTrue();
processInstance.abort();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ABORTED);
}
use of io.automatiko.engine.api.Application 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);
}
Aggregations