use of io.automatiko.engine.api.event.DataEvent in project automatiko-engine by automatiko-io.
the class PublishEventTest 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);
TestEventPublisher publisher = new TestEventPublisher();
app.unitOfWorkManager().eventManager().setService("http://myhost");
app.unitOfWorkManager().eventManager().addPublisher(publisher);
UnitOfWork uow = app.unitOfWorkManager().newUnitOfWork();
uow.start();
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start();
uow.end();
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");
List<DataEvent<?>> events = publisher.extract();
assertThat(events).isNotNull().hasSize(2);
}
use of io.automatiko.engine.api.event.DataEvent in project automatiko-engine by automatiko-io.
the class PublishEventTest method testBasicUserTaskProcessWithSecurityRoles.
@Test
public void testBasicUserTaskProcessWithSecurityRoles() throws Exception {
Application app = generateCodeProcessesOnly("usertask/UserTasksProcessWithSecurityRoles.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);
TestEventPublisher publisher = new TestEventPublisher();
app.unitOfWorkManager().eventManager().setService("http://myhost");
app.unitOfWorkManager().eventManager().addPublisher(publisher);
UnitOfWork uow = app.unitOfWorkManager().newUnitOfWork();
uow.start();
ProcessInstance<?> processInstance = p.createInstance(m);
processInstance.start();
uow.end();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
List<DataEvent<?>> events = publisher.extract();
assertThat(events).isNotNull().hasSize(2);
ProcessInstanceEventBody body = assertProcessInstanceEvent(events.get(0), "UserTasksProcess", "UserTasksProcess", 1);
assertThat(body.getRoles()).hasSize(2).contains("employees", "managers");
assertThat(body.getNodeInstances()).hasSize(2).extractingResultOf("getNodeType").contains("StartNode", "HumanTaskNode");
assertThat(body.getNodeInstances()).extractingResultOf("getTriggerTime").allMatch(v -> v != null);
// human task is active
assertThat(body.getNodeInstances()).extractingResultOf("getLeaveTime").containsNull();
// thus null for leave
// time
assertUserTaskInstanceEvent(events.get(1), "First Task", null, "1", "Ready", "UserTasksProcess");
}
use of io.automatiko.engine.api.event.DataEvent in project automatiko-engine by automatiko-io.
the class PublishEventTest method testProcessWithMilestoneEvents.
@Test
public void testProcessWithMilestoneEvents() throws Exception {
Application app = generateCodeProcessesOnly("cases/milestones/SimpleMilestone.bpmn");
assertThat(app).isNotNull();
TestEventPublisher publisher = new TestEventPublisher();
app.unitOfWorkManager().eventManager().setService("http://myhost");
app.unitOfWorkManager().eventManager().addPublisher(publisher);
UnitOfWork uow = app.unitOfWorkManager().newUnitOfWork();
uow.start();
Process<? extends Model> p = app.processes().processById("TestCase.SimpleMilestone_1_0");
ProcessInstance<?> processInstance = p.createInstance(p.createModel());
processInstance.start();
assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
uow.end();
List<DataEvent<?>> events = publisher.extract();
assertThat(events).isNotNull().hasSize(1);
DataEvent<?> event = events.get(0);
assertThat(event).isInstanceOf(ProcessInstanceDataEvent.class);
ProcessInstanceDataEvent processDataEvent = (ProcessInstanceDataEvent) event;
assertThat(processDataEvent.getSource()).isEqualTo("http://myhost/SimpleMilestone");
Set<MilestoneEventBody> milestones = ((ProcessInstanceDataEvent) event).getData().getMilestones();
assertThat(milestones).hasSize(2).extracting(e -> e.getName(), e -> e.getStatus()).containsExactlyInAnyOrder(tuple("AutoStartMilestone", Status.COMPLETED.name()), tuple("SimpleMilestone", Status.COMPLETED.name()));
}
use of io.automatiko.engine.api.event.DataEvent in project automatiko-engine by automatiko-io.
the class VerificationTest method testProcessParentsSuccessful.
@Test
public void testProcessParentsSuccessful() {
String addPayload = "{\"name\" : \"john\"}";
given().contentType(ContentType.JSON).accept(ContentType.JSON).body(addPayload).when().post("/parents").then().statusCode(200).body("id", notNullValue(), "name", equalTo("john"));
List<DataEvent<?>> received = publisher.events();
assertEquals(4, received.size());
ProcessInstanceDataEvent piEvent = (ProcessInstanceDataEvent) received.stream().filter(pi -> ((ProcessInstanceDataEvent) pi).getData().getState().equals(ProcessInstance.STATE_COMPLETED) && ((ProcessInstanceDataEvent) pi).getData().getProcessId().equals("parents")).findFirst().get();
assertEquals("Here is async name", piEvent.getData().getVariables().get("name"));
given().accept(ContentType.JSON).when().get("/parents").then().statusCode(200).body("$.size()", is(0));
}
use of io.automatiko.engine.api.event.DataEvent in project automatiko-engine by automatiko-io.
the class VerificationTest method testProcessAsyncCallSuccessful.
@Test
public void testProcessAsyncCallSuccessful() {
String addPayload = "{\"name\" : \"john\"}";
given().contentType(ContentType.JSON).accept(ContentType.JSON).body(addPayload).when().post("/async").then().statusCode(200).body("id", notNullValue(), "name", equalTo("john"));
List<DataEvent<?>> received = publisher.events();
assertEquals(2, received.size());
ProcessInstanceDataEvent piEvent = (ProcessInstanceDataEvent) received.stream().filter(pi -> ((ProcessInstanceDataEvent) pi).getData().getState().equals(ProcessInstance.STATE_COMPLETED)).findFirst().get();
assertEquals("Here is async name", piEvent.getData().getVariables().get("name"));
given().accept(ContentType.JSON).when().get("/async").then().statusCode(200).body("$.size()", is(0));
}
Aggregations