Search in sources :

Example 11 with WorkItem

use of io.automatiko.engine.api.workflow.WorkItem 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 12 with WorkItem

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

Example 13 with WorkItem

use of io.automatiko.engine.api.workflow.WorkItem in project automatiko-engine by automatiko-io.

the class EmbeddedSubProcessTest method testEmbeddedSubProcessWithUserTaskAndVariableScopes.

@Test
public void testEmbeddedSubProcessWithUserTaskAndVariableScopes() throws Exception {
    Application app = generateCodeProcessesOnly("subprocess/EmbeddedSubProcessWithUserTask.bpmn2");
    assertThat(app).isNotNull();
    Process<? extends Model> p = app.processes().processById("embeddedWithUserTask_1_0");
    Person person = new Person("john", 25);
    Model m = p.createModel();
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("person", person);
    m.fromMap(parameters);
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    List<WorkItem> tasks = processInstance.workItems();
    assertThat(tasks).hasSize(1);
    WorkItem wi = processInstance.workItem(tasks.get(0).getId());
    assertThat(wi).isNotNull();
    assertThat(wi.getParameters()).containsKey("person");
    assertThat(wi.getParameters()).extracting("person").isEqualTo(person);
    processInstance.completeWorkItem(tasks.get(0).getId(), new HashMap<>(Collections.singletonMap("person", new Person("mary", 20))));
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
}
Also used : 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)

Example 14 with WorkItem

use of io.automatiko.engine.api.workflow.WorkItem in project automatiko-engine by automatiko-io.

the class ExportProcessInstanceTest method testBasicUserTaskProcess.

@Test
public void testBasicUserTaskProcess() throws Exception {
    ProcessInstanceMarshaller marshaller = new ProcessInstanceMarshaller();
    Application app = generateCodeProcessesOnly("usertask/UserTasksProcess.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);
    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);
    // exprt process instance
    ExportedProcessInstance exported = marshaller.exportProcessInstance(processInstance);
    assertThat(exported).isNotNull();
    ProcessInstance<?> imported = marshaller.importProcessInstance(exported, p);
    workItems = imported.workItems(securityPolicy);
    assertEquals(1, workItems.size());
    assertEquals("SecondTask", workItems.get(0).getName());
    imported.completeWorkItem(workItems.get(0).getId(), null, securityPolicy);
    assertThat(imported.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
}
Also used : ProcessInstanceMarshaller(io.automatiko.engine.workflow.marshalling.ProcessInstanceMarshaller) HashMap(java.util.HashMap) Model(io.automatiko.engine.api.Model) ExportedProcessInstance(io.automatiko.engine.api.workflow.ExportedProcessInstance) 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 15 with WorkItem

use of io.automatiko.engine.api.workflow.WorkItem in project automatiko-engine by automatiko-io.

the class OrdersProcessService method testOrderProcess.

@GET
@Produces(MediaType.TEXT_PLAIN)
public String testOrderProcess() {
    Model m = orderProcess.createModel();
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("approver", "john");
    parameters.put("order", new Order("12345", false, 0.0));
    m.fromMap(parameters);
    ProcessInstance<?> processInstance = orderProcess.createInstance(m);
    processInstance.start();
    assert (io.automatiko.engine.api.runtime.process.ProcessInstance.STATE_ACTIVE == processInstance.status());
    Model result = (Model) processInstance.variables();
    assert (result.toMap().size() == 2);
    assert (((Order) result.toMap().get("order")).getTotal() > 0);
    ProcessInstances<? extends Model> orderItemProcesses = orderItemsProcess.instances();
    assert (orderItemProcesses.values(1, 10).size() == 1);
    ProcessInstance<?> childProcessInstance = orderItemProcesses.values(1, 10).iterator().next();
    List<WorkItem> workItems = childProcessInstance.workItems();
    assert (workItems.size()) == 1;
    childProcessInstance.completeWorkItem(workItems.get(0).getId(), null);
    assert (io.automatiko.engine.api.runtime.process.ProcessInstance.STATE_COMPLETED == childProcessInstance.status());
    assert (io.automatiko.engine.api.runtime.process.ProcessInstance.STATE_COMPLETED == processInstance.status());
    // no active process instances for both orders and order items processes
    assert (orderProcess.instances().values(1, 10).size() == 0);
    assert (orderItemsProcess.instances().values(1, 10).size() == 0);
    return "OK";
}
Also used : HashMap(java.util.HashMap) Model(io.automatiko.engine.api.Model) WorkItem(io.automatiko.engine.api.workflow.WorkItem) Produces(javax.ws.rs.Produces) GET(javax.ws.rs.GET)

Aggregations

WorkItem (io.automatiko.engine.api.workflow.WorkItem)51 Test (org.junit.jupiter.api.Test)46 Model (io.automatiko.engine.api.Model)41 Application (io.automatiko.engine.api.Application)39 AbstractCodegenTest (io.automatiko.engine.codegen.AbstractCodegenTest)39 HashMap (java.util.HashMap)38 HumanTaskTransition (io.automatiko.engine.workflow.base.instance.impl.humantask.HumanTaskTransition)13 ProcessInstance (io.automatiko.engine.api.workflow.ProcessInstance)8 BpmnProcess (io.automatiko.engine.workflow.bpmn2.BpmnProcess)7 BpmnVariables (io.automatiko.engine.workflow.bpmn2.BpmnVariables)7 StaticIdentityProvider (io.automatiko.engine.services.identity.StaticIdentityProvider)6 UnitOfWork (io.automatiko.engine.api.uow.UnitOfWork)5 ArrayList (java.util.ArrayList)5 WorkItemNotFoundException (io.automatiko.engine.api.runtime.process.WorkItemNotFoundException)4 IdentityProvider (io.automatiko.engine.api.auth.IdentityProvider)3 DataEvent (io.automatiko.engine.api.event.DataEvent)3 DefaultProcessEventListener (io.automatiko.engine.api.event.process.DefaultProcessEventListener)3 ProcessWorkItemTransitionEvent (io.automatiko.engine.api.event.process.ProcessWorkItemTransitionEvent)3 Process (io.automatiko.engine.api.workflow.Process)3 Person (io.automatiko.engine.codegen.data.Person)3