use of io.automatiko.engine.api.uow.UnitOfWork in project automatiko-engine by automatiko-io.
the class DefaultUnitOfWorkManagerTest method testUnitOfWorkStartOnFinishedUnit.
@Test
public void testUnitOfWorkStartOnFinishedUnit() {
UnitOfWork unit = unitOfWorkManager.newUnitOfWork();
assertThat(unit).isNotNull().isInstanceOf(ManagedUnitOfWork.class);
unit.start();
unit.abort();
assertThrows(IllegalStateException.class, () -> unit.start(), "Cannot start already completed unit");
assertThrows(IllegalStateException.class, () -> unit.end(), "Cannot end already completed unit");
assertThrows(IllegalStateException.class, () -> unit.abort(), "Cannot abort already completed unit");
assertThrows(IllegalStateException.class, () -> unit.intercept(null), "Cannot intercept on already completed unit");
}
use of io.automatiko.engine.api.uow.UnitOfWork in project automatiko-engine by automatiko-io.
the class DefaultUnitOfWorkManagerTest method testUnitOfWorkAddWorkOnNotStarted.
@Test
public void testUnitOfWorkAddWorkOnNotStarted() {
UnitOfWork unit = unitOfWorkManager.newUnitOfWork();
assertThat(unit).isNotNull().isInstanceOf(ManagedUnitOfWork.class);
final AtomicInteger counter = new AtomicInteger(0);
assertThat(counter.get()).isEqualTo(0);
WorkUnit<AtomicInteger> dummyWork = WorkUnit.create(counter, (d) -> d.incrementAndGet());
assertThrows(IllegalStateException.class, () -> unit.intercept(dummyWork), "Cannot intercept on not started unit");
}
use of io.automatiko.engine.api.uow.UnitOfWork in project automatiko-engine by automatiko-io.
the class DefaultUnitOfWorkManagerTest method testFallbackUnitOfWork.
@Test
public void testFallbackUnitOfWork() {
UnitOfWork unit = unitOfWorkManager.currentUnitOfWork();
assertThat(unit).isNotNull().isInstanceOf(PassThroughUnitOfWork.class);
}
use of io.automatiko.engine.api.uow.UnitOfWork 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.uow.UnitOfWork 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");
}
Aggregations