Search in sources :

Example 1 with ProcessInstanceMarshaller

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

Aggregations

Application (io.automatiko.engine.api.Application)1 Model (io.automatiko.engine.api.Model)1 ExportedProcessInstance (io.automatiko.engine.api.workflow.ExportedProcessInstance)1 WorkItem (io.automatiko.engine.api.workflow.WorkItem)1 AbstractCodegenTest (io.automatiko.engine.codegen.AbstractCodegenTest)1 ProcessInstanceMarshaller (io.automatiko.engine.workflow.marshalling.ProcessInstanceMarshaller)1 HashMap (java.util.HashMap)1 Test (org.junit.jupiter.api.Test)1