Search in sources :

Example 16 with Model

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

the class UserTaskTest method testBasicUserTaskProcess.

@Test
public void testBasicUserTaskProcess() throws Exception {
    Application app = generateCodeProcessesOnly("usertask/UserTasksProcess.bpmn2");
    assertThat(app).isNotNull();
    final List<String> workItemTransitionEvents = new ArrayList<>();
    app.config().process().processEventListeners().listeners().add(new DefaultProcessEventListener() {

        @Override
        public void beforeWorkItemTransition(ProcessWorkItemTransitionEvent event) {
            workItemTransitionEvents.add("BEFORE:: " + event);
        }

        @Override
        public void afterWorkItemTransition(ProcessWorkItemTransitionEvent event) {
            workItemTransitionEvents.add("AFTER:: " + event);
        }
    });
    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);
    workItems = processInstance.workItems(securityPolicy);
    assertEquals(1, workItems.size());
    assertEquals("SecondTask", workItems.get(0).getName());
    processInstance.completeWorkItem(workItems.get(0).getId(), null, securityPolicy);
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
    assertThat(workItemTransitionEvents).hasSize(8);
}
Also used : HashMap(java.util.HashMap) ProcessWorkItemTransitionEvent(io.automatiko.engine.api.event.process.ProcessWorkItemTransitionEvent) ArrayList(java.util.ArrayList) WorkItem(io.automatiko.engine.api.workflow.WorkItem) Model(io.automatiko.engine.api.Model) DefaultProcessEventListener(io.automatiko.engine.api.event.process.DefaultProcessEventListener) Application(io.automatiko.engine.api.Application) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Test(org.junit.jupiter.api.Test)

Example 17 with Model

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

the class UserTaskTest method testApprovalWithRequiredVariableTags.

@Test
public void testApprovalWithRequiredVariableTags() throws Exception {
    Application app = generateCodeProcessesOnly("usertask/approval-with-required-variable-tags.bpmn2");
    assertThat(app).isNotNull();
    Process<? extends Model> p = app.processes().processById("approvals");
    Model m = p.createModel();
    Map<String, Object> parameters = new HashMap<>();
    m.fromMap(parameters);
    assertThrows(VariableViolationException.class, () -> {
        ProcessInstance<?> processInstance = p.createInstance(m);
        processInstance.start();
    });
}
Also used : HashMap(java.util.HashMap) 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 18 with Model

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

the class VariableTest method testVariablesWithReservedNameOnServiceTask.

@Test
public void testVariablesWithReservedNameOnServiceTask() throws Exception {
    Application app = generateCodeProcessesOnly("servicetask/ServiceTaskWithReservedNameVariable.bpmn2");
    assertThat(app).isNotNull();
    Process<? extends Model> p = app.processes().processById("test_1_0");
    Model m = p.createModel();
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("package", "john");
    m.fromMap(parameters);
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
    Model result = (Model) processInstance.variables();
    assertThat(result.toMap()).hasSize(2).containsKeys("result");
    assertThat(result.toMap()).hasSize(2).containsKeys("package");
    assertThat(result.toMap().get("result")).isNotNull().isEqualTo("Hello Hello john!!");
}
Also used : HashMap(java.util.HashMap) Model(io.automatiko.engine.api.Model) Application(io.automatiko.engine.api.Application) Test(org.junit.jupiter.api.Test) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest)

Example 19 with Model

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

the class MessageStartEventTest method testMessageStartAndEndEventProcess.

@Test
public void testMessageStartAndEndEventProcess() throws Exception {
    Application app = generateCodeProcessesOnly("messagestartevent/MessageStartAndEndEvent.bpmn2");
    assertThat(app).isNotNull();
    Process<? extends Model> p = app.processes().processById("MessageStartEvent");
    Model m = p.createModel();
    Map<String, Object> parameters = new HashMap<>();
    m.fromMap(parameters);
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start("customers", null, "CUS-00998877");
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
    Model result = (Model) processInstance.variables();
    assertThat(result.toMap()).hasSize(1).containsKeys("customerId");
    assertThat(result.toMap().get("customerId")).isNotNull().isEqualTo("CUS-00998877");
}
Also used : HashMap(java.util.HashMap) 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 20 with Model

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

the class MessageStartEventTest method testMultipleMessagesStartEventProcess.

@Test
public void testMultipleMessagesStartEventProcess() throws Exception {
    Application app = generateCodeProcessesOnly("messagestartevent/MessageAndMessageStartEvent.bpmn2");
    assertThat(app).isNotNull();
    Process<? extends Model> p = app.processes().processById("MessageStartEvent");
    Model m = p.createModel();
    Map<String, Object> parameters = new HashMap<>();
    m.fromMap(parameters);
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start("customers", null, "CUS-00998877");
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    Model result = (Model) processInstance.variables();
    assertThat(result.toMap()).hasSize(2).containsKeys("customerId");
    assertThat(result.toMap().get("customerId")).isNotNull().isEqualTo("CUS-00998877");
    processInstance.send(Sig.of("managers", "John the manager"));
    List<WorkItem> workItems = processInstance.workItems(securityPolicy);
    assertEquals(2, workItems.size());
    result = (Model) processInstance.variables();
    assertThat(result.toMap()).hasSize(2).containsKeys("customerId", "path");
    assertThat(result.toMap().get("customerId")).isNotNull().isEqualTo("CUS-00998877");
    assertThat(result.toMap().get("path")).isNotNull().isEqualTo("John the manager");
    processInstance.abort();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ABORTED);
}
Also used : HashMap(java.util.HashMap) Model(io.automatiko.engine.api.Model) Application(io.automatiko.engine.api.Application) WorkItem(io.automatiko.engine.api.workflow.WorkItem) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Test(org.junit.jupiter.api.Test)

Aggregations

Model (io.automatiko.engine.api.Model)161 Application (io.automatiko.engine.api.Application)142 Test (org.junit.jupiter.api.Test)138 AbstractCodegenTest (io.automatiko.engine.codegen.AbstractCodegenTest)133 HashMap (java.util.HashMap)127 WorkItem (io.automatiko.engine.api.workflow.WorkItem)43 ProcessInstance (io.automatiko.engine.api.workflow.ProcessInstance)26 DefaultProcessEventListenerConfig (io.automatiko.engine.workflow.DefaultProcessEventListenerConfig)23 NodeLeftCountDownProcessEventListener (io.automatiko.engine.workflow.compiler.util.NodeLeftCountDownProcessEventListener)23 ArrayList (java.util.ArrayList)16 HumanTaskTransition (io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskTransition)13 JsonNode (com.fasterxml.jackson.databind.JsonNode)11 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)11 Person (io.automatiko.engine.codegen.data.Person)10 StaticIdentityProvider (io.automatiko.engine.services.identity.StaticIdentityProvider)10 UnitOfWork (io.automatiko.engine.api.uow.UnitOfWork)9 AbstractProcessInstance (io.automatiko.engine.workflow.AbstractProcessInstance)9 List (java.util.List)9 DataEvent (io.automatiko.engine.api.event.DataEvent)8 ProcessInstanceDataEvent (io.automatiko.engine.services.event.ProcessInstanceDataEvent)8