Search in sources :

Example 51 with WorkItem

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

the class FileSystemProcessInstancesTest method testComplexVariableFlow.

@Test
public void testComplexVariableFlow() {
    BpmnProcess process = (BpmnProcess) BpmnProcess.from(new ClassPathResource("BPMN2-PersonUserTask.bpmn2")).get(0);
    process.setProcessInstancesFactory(new FileSystemProcessInstancesFactory());
    process.configure();
    Person person = new Person("John", 30);
    Address mainAddress = new Address("first", "Brisbane", "00000", "Australia", true);
    Address secondaryAddress = new Address("second", "Syndey", "11111", "Australia", false);
    person.addAddress(mainAddress);
    person.addAddress(secondaryAddress);
    ProcessInstance<BpmnVariables> processInstance = process.createInstance(BpmnVariables.create(Collections.singletonMap("person", person)));
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(STATE_ACTIVE);
    assertThat(processInstance.description()).isEqualTo("User Task");
    assertThat(process.instances().values(1, 10)).hasSize(1);
    FileSystemProcessInstances fileSystemBasedStorage = (FileSystemProcessInstances) process.instances();
    verify(fileSystemBasedStorage, times(2)).create(any(), any());
    verify(fileSystemBasedStorage, times(1)).setMetadata(any(), eq(FileSystemProcessInstances.PI_DESCRIPTION), eq("User Task"));
    verify(fileSystemBasedStorage, times(1)).setMetadata(any(), eq(FileSystemProcessInstances.PI_STATUS), eq("1"));
    Person testVar = (Person) processInstance.variables().get("person");
    assertThat(testVar).isEqualTo(person);
    assertThat(processInstance.description()).isEqualTo("User Task");
    WorkItem workItem = processInstance.workItems(securityPolicy).get(0);
    assertThat(workItem).isNotNull();
    assertThat(workItem.getParameters().get("ActorId")).isEqualTo("john");
    processInstance.completeWorkItem(workItem.getId(), null, securityPolicy);
    assertThat(processInstance.status()).isEqualTo(STATE_COMPLETED);
    fileSystemBasedStorage = (FileSystemProcessInstances) process.instances();
    verify(fileSystemBasedStorage, times(2)).remove(any(), any());
}
Also used : BpmnProcess(io.automatiko.engine.workflow.bpmn2.BpmnProcess) Address(io.automatiko.engine.addons.persistence.data.Address) Person(io.automatiko.engine.addons.persistence.data.Person) WorkItem(io.automatiko.engine.api.workflow.WorkItem) ClassPathResource(io.automatiko.engine.services.io.ClassPathResource) BpmnVariables(io.automatiko.engine.workflow.bpmn2.BpmnVariables) Test(org.junit.jupiter.api.Test)

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