Search in sources :

Example 1 with UnitOfWork

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");
}
Also used : ManagedUnitOfWork(io.automatiko.engine.services.uow.ManagedUnitOfWork) PassThroughUnitOfWork(io.automatiko.engine.services.uow.PassThroughUnitOfWork) UnitOfWork(io.automatiko.engine.api.uow.UnitOfWork) CollectingUnitOfWork(io.automatiko.engine.services.uow.CollectingUnitOfWork) Test(org.junit.jupiter.api.Test)

Example 2 with UnitOfWork

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");
}
Also used : ManagedUnitOfWork(io.automatiko.engine.services.uow.ManagedUnitOfWork) PassThroughUnitOfWork(io.automatiko.engine.services.uow.PassThroughUnitOfWork) UnitOfWork(io.automatiko.engine.api.uow.UnitOfWork) CollectingUnitOfWork(io.automatiko.engine.services.uow.CollectingUnitOfWork) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) Test(org.junit.jupiter.api.Test)

Example 3 with UnitOfWork

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);
}
Also used : ManagedUnitOfWork(io.automatiko.engine.services.uow.ManagedUnitOfWork) PassThroughUnitOfWork(io.automatiko.engine.services.uow.PassThroughUnitOfWork) UnitOfWork(io.automatiko.engine.api.uow.UnitOfWork) CollectingUnitOfWork(io.automatiko.engine.services.uow.CollectingUnitOfWork) Test(org.junit.jupiter.api.Test)

Example 4 with UnitOfWork

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);
}
Also used : UnitOfWork(io.automatiko.engine.api.uow.UnitOfWork) HashMap(java.util.HashMap) Model(io.automatiko.engine.api.Model) DataEvent(io.automatiko.engine.api.event.DataEvent) UserTaskInstanceDataEvent(io.automatiko.engine.services.event.UserTaskInstanceDataEvent) ProcessInstanceDataEvent(io.automatiko.engine.services.event.ProcessInstanceDataEvent) Application(io.automatiko.engine.api.Application) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Test(org.junit.jupiter.api.Test)

Example 5 with UnitOfWork

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");
}
Also used : UnitOfWork(io.automatiko.engine.api.uow.UnitOfWork) HashMap(java.util.HashMap) ProcessInstanceEventBody(io.automatiko.engine.services.event.impl.ProcessInstanceEventBody) DataEvent(io.automatiko.engine.api.event.DataEvent) UserTaskInstanceDataEvent(io.automatiko.engine.services.event.UserTaskInstanceDataEvent) ProcessInstanceDataEvent(io.automatiko.engine.services.event.ProcessInstanceDataEvent) Model(io.automatiko.engine.api.Model) Application(io.automatiko.engine.api.Application) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Test(org.junit.jupiter.api.Test)

Aggregations

UnitOfWork (io.automatiko.engine.api.uow.UnitOfWork)18 Test (org.junit.jupiter.api.Test)16 Application (io.automatiko.engine.api.Application)9 Model (io.automatiko.engine.api.Model)9 AbstractCodegenTest (io.automatiko.engine.codegen.AbstractCodegenTest)9 DataEvent (io.automatiko.engine.api.event.DataEvent)8 ProcessInstanceDataEvent (io.automatiko.engine.services.event.ProcessInstanceDataEvent)8 UserTaskInstanceDataEvent (io.automatiko.engine.services.event.UserTaskInstanceDataEvent)8 HashMap (java.util.HashMap)8 ProcessInstanceEventBody (io.automatiko.engine.services.event.impl.ProcessInstanceEventBody)7 WorkItem (io.automatiko.engine.api.workflow.WorkItem)6 CollectingUnitOfWork (io.automatiko.engine.services.uow.CollectingUnitOfWork)6 ManagedUnitOfWork (io.automatiko.engine.services.uow.ManagedUnitOfWork)6 PassThroughUnitOfWork (io.automatiko.engine.services.uow.PassThroughUnitOfWork)6 StaticIdentityProvider (io.automatiko.engine.services.identity.StaticIdentityProvider)4 BaseWorkUnit (io.automatiko.engine.services.uow.BaseWorkUnit)3 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)3 ProcessErrors (io.automatiko.engine.api.workflow.ProcessErrors)2 ProcessInstance (io.automatiko.engine.api.workflow.ProcessInstance)2 IdentityProvider (io.automatiko.engine.api.auth.IdentityProvider)1