Search in sources :

Example 1 with Application

use of io.automatiko.engine.api.Application 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 2 with Application

use of io.automatiko.engine.api.Application 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)

Example 3 with Application

use of io.automatiko.engine.api.Application 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()));
}
Also used : AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) UserTaskInstanceEventBody(io.automatiko.engine.services.event.impl.UserTaskInstanceEventBody) MilestoneEventBody(io.automatiko.engine.services.event.impl.MilestoneEventBody) SecurityPolicy(io.automatiko.engine.api.auth.SecurityPolicy) ProcessInstanceEventBody(io.automatiko.engine.services.event.impl.ProcessInstanceEventBody) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) ProcessErrors(io.automatiko.engine.api.workflow.ProcessErrors) HashMap(java.util.HashMap) DataEvent(io.automatiko.engine.api.event.DataEvent) ArrayList(java.util.ArrayList) Application(io.automatiko.engine.api.Application) UserTaskInstanceDataEvent(io.automatiko.engine.services.event.UserTaskInstanceDataEvent) ProcessInstanceDataEvent(io.automatiko.engine.services.event.ProcessInstanceDataEvent) Map(java.util.Map) StaticIdentityProvider(io.automatiko.engine.services.identity.StaticIdentityProvider) Process(io.automatiko.engine.api.workflow.Process) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) EventPublisher(io.automatiko.engine.api.event.EventPublisher) Model(io.automatiko.engine.api.Model) Assertions.tuple(org.assertj.core.api.Assertions.tuple) Collection(java.util.Collection) Status(io.automatiko.engine.api.workflow.flexible.ItemDescription.Status) Set(java.util.Set) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) UnitOfWork(io.automatiko.engine.api.uow.UnitOfWork) Test(org.junit.jupiter.api.Test) List(java.util.List) WorkItem(io.automatiko.engine.api.workflow.WorkItem) UnitOfWork(io.automatiko.engine.api.uow.UnitOfWork) MilestoneEventBody(io.automatiko.engine.services.event.impl.MilestoneEventBody) DataEvent(io.automatiko.engine.api.event.DataEvent) UserTaskInstanceDataEvent(io.automatiko.engine.services.event.UserTaskInstanceDataEvent) ProcessInstanceDataEvent(io.automatiko.engine.services.event.ProcessInstanceDataEvent) 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 4 with Application

use of io.automatiko.engine.api.Application in project automatiko-engine by automatiko-io.

the class ServerlessWorkflowTest method testParallelExecWorkflow.

@Test
public void testParallelExecWorkflow() throws Exception {
    Application app = generateCodeProcessesOnly("serverless/parallel-state.sw.json", "serverless/parallel-state-branch1.sw.json", "serverless/parallel-state-branch2.sw.json");
    assertThat(app).isNotNull();
    Process<? extends Model> p = app.processes().processById("parallelworkflow_1_0");
    Model m = p.createModel();
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
    Model result = (Model) processInstance.variables();
    assertThat(result.toMap()).containsKeys("branch1data", "branch2data");
    Map<String, Object> dataOut = result.toMap();
    assertThat(((JsonNode) dataOut.get("branch1data")).textValue()).isEqualTo("testBranch1Data");
    assertThat(((JsonNode) dataOut.get("branch2data")).textValue()).isEqualTo("testBranch2Data");
}
Also used : Model(io.automatiko.engine.api.Model) JsonNode(com.fasterxml.jackson.databind.JsonNode) Application(io.automatiko.engine.api.Application) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with Application

use of io.automatiko.engine.api.Application in project automatiko-engine by automatiko-io.

the class ServerlessWorkflowTest method testCompensationWorkflow.

@Disabled
@ParameterizedTest
@ValueSource(strings = { "serverless/compensation.sw.json" })
public void testCompensationWorkflow(String processLocation) throws Exception {
    Application app = generateCodeProcessesOnly(processLocation);
    assertThat(app).isNotNull();
    Process<? extends Model> p = app.processes().processById("compensationworkflow");
    Model m = p.createModel();
    String jsonParamStr = "{\"x\": \"0\"}";
    ObjectMapper mapper = new ObjectMapper();
    JsonNode jsonParamObj = mapper.readTree(jsonParamStr);
    m.fromMap(toMap(jsonParamObj));
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
    Model result = (Model) processInstance.variables();
    assertThat(result.toMap()).containsKeys("x");
    JsonNode dataOut = (JsonNode) result.toMap().get("x");
    assertThat(dataOut.textValue()).isEqualTo("2");
}
Also used : Model(io.automatiko.engine.api.Model) JsonNode(com.fasterxml.jackson.databind.JsonNode) Application(io.automatiko.engine.api.Application) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) ValueSource(org.junit.jupiter.params.provider.ValueSource) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest) Disabled(org.junit.jupiter.api.Disabled)

Aggregations

Application (io.automatiko.engine.api.Application)157 Model (io.automatiko.engine.api.Model)146 AbstractCodegenTest (io.automatiko.engine.codegen.AbstractCodegenTest)143 Test (org.junit.jupiter.api.Test)143 HashMap (java.util.HashMap)126 WorkItem (io.automatiko.engine.api.workflow.WorkItem)46 ProcessInstance (io.automatiko.engine.api.workflow.ProcessInstance)29 DefaultProcessEventListenerConfig (io.automatiko.engine.workflow.DefaultProcessEventListenerConfig)27 NodeLeftCountDownProcessEventListener (io.automatiko.engine.workflow.compiler.util.NodeLeftCountDownProcessEventListener)27 ArrayList (java.util.ArrayList)17 List (java.util.List)16 StaticIdentityProvider (io.automatiko.engine.services.identity.StaticIdentityProvider)14 HumanTaskTransition (io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskTransition)14 Process (io.automatiko.engine.api.workflow.Process)13 Map (java.util.Map)12 Person (io.automatiko.engine.codegen.data.Person)11 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 JsonNode (com.fasterxml.jackson.databind.JsonNode)10 UnitOfWork (io.automatiko.engine.api.uow.UnitOfWork)9 SecurityPolicy (io.automatiko.engine.api.auth.SecurityPolicy)8