Search in sources :

Example 46 with Application

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

the class BusinessRuleTaskTest method testDecisionWithErrorHandling.

@Test
public void testDecisionWithErrorHandling() throws Exception {
    Application app = generateCode(Collections.singletonList("decision/models/dmnprocess.bpmn2"), Collections.emptyList(), Collections.singletonList("decision/models/vacationDaysAlt/VacationDays.dmn"), Collections.emptyList(), false);
    Process<? extends Model> p = app.processes().processById("DmnProcess_1_0");
    Model m = p.createModel();
    HashMap<String, Object> vars = new HashMap<>();
    vars.put("age", 1);
    vars.put("yearsOfService", 1);
    m.fromMap(vars);
    ProcessInstance<? extends Model> processInstance = p.createInstance(m);
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    List<WorkItem> items = processInstance.workItems();
    assertThat(items).hasSize(1);
    WorkItem wi = items.get(0);
    assertThat(wi.getName()).isEqualTo("analyze");
    assertThat(wi.getParameters()).containsKey("error");
    @SuppressWarnings("unchecked") Map<String, Object> error = (Map<String, Object>) wi.getParameters().get("error");
    assertThat(error).containsKey("error");
    assertThat(error).containsKey("results");
    processInstance.completeWorkItem(wi.getId(), null);
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
}
Also used : HashMap(java.util.HashMap) WorkItem(io.automatiko.engine.api.workflow.WorkItem) Model(io.automatiko.engine.api.Model) Application(io.automatiko.engine.api.Application) HashMap(java.util.HashMap) Map(java.util.Map) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Test(org.junit.jupiter.api.Test)

Example 47 with Application

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

the class CallActivityTaskTest 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);
    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("x", "y");
    assertThat(result.toMap().get("y")).isNotNull().isEqualTo("new value");
    assertThat(result.toMap().get("x")).isNotNull().isEqualTo("a");
}
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 48 with Application

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

the class CallActivityTaskTest method testCallActivityTaskWithExpressionsForIONested.

@Test
public void testCallActivityTaskWithExpressionsForIONested() throws Exception {
    Application app = generateCodeProcessesOnly("subprocess/CallActivityWithIOexpressionNested.bpmn2", "subprocess/CallActivitySubProcess.bpmn2");
    assertThat(app).isNotNull();
    Process<? extends Model> p = app.processes().processById("ParentProcess");
    Model m = p.createModel();
    Map<String, Object> parameters = new HashMap<>();
    PersonWithAddress pa = new PersonWithAddress("john", 0);
    pa.setAddress(new Address("test", null, null, null));
    parameters.put("person", pa);
    m.fromMap(parameters);
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    Model result = (Model) processInstance.variables();
    assertThat(result.toMap()).hasSize(1).containsKeys("person");
    PersonWithAddress person = (PersonWithAddress) result.toMap().get("person");
    assertEquals("john", person.getName());
    assertEquals("test", person.getAddress().getStreet());
    assertEquals("new value", person.getAddress().getCity());
    List<WorkItem> workItems = processInstance.workItems(securityPolicy);
    assertEquals(1, workItems.size());
    WorkItem wi = workItems.get(0);
    assertEquals("MyTask", wi.getName());
    assertEquals(Active.ID, wi.getPhase());
    assertEquals(Active.STATUS, wi.getPhaseStatus());
    processInstance.transitionWorkItem(workItems.get(0).getId(), new HumanTaskTransition(Complete.ID, null, securityPolicy));
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
}
Also used : Address(io.automatiko.engine.codegen.data.Address) PersonWithAddress(io.automatiko.engine.codegen.data.PersonWithAddress) HashMap(java.util.HashMap) WorkItem(io.automatiko.engine.api.workflow.WorkItem) HumanTaskTransition(io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskTransition) Model(io.automatiko.engine.api.Model) PersonWithAddress(io.automatiko.engine.codegen.data.PersonWithAddress) Application(io.automatiko.engine.api.Application) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Test(org.junit.jupiter.api.Test)

Example 49 with Application

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

the class CallActivityTaskTest method testCallActivityTaskWithSubprocesWaitAndAbort.

@Test
public void testCallActivityTaskWithSubprocesWaitAndAbort() throws Exception {
    Application app = generateCodeProcessesOnly("subprocess/CallActivity.bpmn2", "subprocess/CallActivitySubProcessHT.bpmn2", "subprocess/CallActivitySubProcessHT2.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);
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    Model result = (Model) processInstance.variables();
    assertThat(result.toMap()).hasSize(2).containsKeys("x", "y");
    // check if tasks can be accessed via parent process instance even if they are
    // in subprocesses
    List<WorkItem> workItems = processInstance.workItems(securityPolicy);
    assertEquals(1, workItems.size());
    WorkItem wi = workItems.get(0);
    assertEquals("User Task 1", wi.getName());
    assertEquals(Active.ID, wi.getPhase());
    assertEquals(Active.STATUS, wi.getPhaseStatus());
    // following check shows that task(wi) comes from another process instance
    assertNotEquals(processInstance.id(), wi.getProcessInstanceId());
    Collection<ProcessInstance<? extends Model>> subprocesses = processInstance.subprocesses();
    assertThat(subprocesses).hasSize(1);
    ProcessInstance<?> childProcessInstance = subprocesses.iterator().next();
    processInstance.abort();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ABORTED);
    assertThat(childProcessInstance.status()).isEqualTo(ProcessInstance.STATE_ABORTED);
    subprocesses = processInstance.subprocesses();
    assertThat(subprocesses).hasSize(0);
    assertThat(p.instances().size()).isEqualTo(0);
    assertThat(childProcessInstance.process().instances().size()).isEqualTo(0);
}
Also used : HashMap(java.util.HashMap) Model(io.automatiko.engine.api.Model) ProcessInstance(io.automatiko.engine.api.workflow.ProcessInstance) 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)

Example 50 with Application

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

the class CallActivityTaskTest method testCallActivityTaskWithExpressionsForIO.

@Test
public void testCallActivityTaskWithExpressionsForIO() throws Exception {
    Application app = generateCodeProcessesOnly("subprocess/CallActivityWithIOexpression.bpmn2", "subprocess/CallActivitySubProcess.bpmn2");
    assertThat(app).isNotNull();
    Process<? extends Model> p = app.processes().processById("ParentProcess");
    Model m = p.createModel();
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("person", new Person("john", 0));
    m.fromMap(parameters);
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    Model result = (Model) processInstance.variables();
    assertThat(result.toMap()).hasSize(1).containsKeys("person");
    Person person = (Person) result.toMap().get("person");
    assertEquals("new value", person.getName());
    List<WorkItem> workItems = processInstance.workItems(securityPolicy);
    assertEquals(1, workItems.size());
    WorkItem wi = workItems.get(0);
    assertEquals("MyTask", wi.getName());
    assertEquals(Active.ID, wi.getPhase());
    assertEquals(Active.STATUS, wi.getPhaseStatus());
    processInstance.transitionWorkItem(workItems.get(0).getId(), new HumanTaskTransition(Complete.ID, null, securityPolicy));
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
}
Also used : HumanTaskTransition(io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskTransition) HashMap(java.util.HashMap) Model(io.automatiko.engine.api.Model) Application(io.automatiko.engine.api.Application) Person(io.automatiko.engine.codegen.data.Person) WorkItem(io.automatiko.engine.api.workflow.WorkItem) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Test(org.junit.jupiter.api.Test)

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