Search in sources :

Example 21 with WorkItem

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

the class SignalEventTest method testIntermediateSignalEventWithData.

@Test
public void testIntermediateSignalEventWithData() throws Exception {
    Application app = generateCode(Collections.singletonList("signalevent/IntermediateCatchEventSignal.bpmn2"), Collections.singletonList("ruletask/BusinessRuleTask.drl"));
    assertThat(app).isNotNull();
    Process<? extends Model> p = app.processes().processById("IntermediateCatchEvent");
    Model m = p.createModel();
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    Set<EventDescription<?>> eventDescriptions = processInstance.events();
    assertThat(eventDescriptions).hasSize(1).extracting("event").contains("workItemCompleted");
    assertThat(eventDescriptions).extracting("eventType").contains("workItem");
    assertThat(eventDescriptions).extracting("processInstanceId").contains(processInstance.id());
    List<WorkItem> workItems = processInstance.workItems();
    assertThat(workItems).hasSize(1);
    processInstance.completeWorkItem(workItems.get(0).getId(), null);
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    eventDescriptions = processInstance.events();
    assertThat(eventDescriptions).hasSize(1).extracting("event").contains("MyMessage");
    assertThat(eventDescriptions).extracting("eventType").contains("signal");
    assertThat(eventDescriptions).extracting("processInstanceId").contains(processInstance.id());
    processInstance.send(Sig.of("MyMessage", "test"));
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
    Model result = (Model) processInstance.variables();
    assertThat(result.toMap()).hasSize(2).containsKey("x");
    assertThat(result.toMap().get("x")).isEqualTo("test");
    assertThat(p.instances().values(1, 10)).hasSize(0);
}
Also used : Model(io.automatiko.engine.api.Model) Application(io.automatiko.engine.api.Application) EventDescription(io.automatiko.engine.api.workflow.EventDescription) WorkItem(io.automatiko.engine.api.workflow.WorkItem) AbstractCodegenTest(io.automatiko.engine.codegen.AbstractCodegenTest) Test(org.junit.jupiter.api.Test)

Example 22 with WorkItem

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

the class PublishEventTest method testBasicUserTaskProcessWithTags.

@Test
public void testBasicUserTaskProcessWithTags() throws Exception {
    Application app = generateCodeProcessesOnly("usertask/UserTasksProcessTags.bpmn2");
    assertThat(app).isNotNull();
    Process<? extends Model> p = app.processes().processById("UserTasksProcess");
    Model m = p.createModel();
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("name", "john");
    m.fromMap(parameters);
    TestEventPublisher publisher = new TestEventPublisher();
    app.unitOfWorkManager().eventManager().setService("http://myhost");
    app.unitOfWorkManager().eventManager().addPublisher(publisher);
    UnitOfWork uow = app.unitOfWorkManager().newUnitOfWork();
    uow.start();
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    uow.end();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    List<DataEvent<?>> events = publisher.extract();
    assertThat(events).isNotNull().hasSize(2);
    ProcessInstanceEventBody body = assertProcessInstanceEvent(events.get(0), "UserTasksProcess", "UserTasksProcess", 1);
    assertThat(body.getTags()).hasSize(2).contains("important", "john");
    assertThat(body.getNodeInstances()).hasSize(2).extractingResultOf("getNodeType").contains("StartNode", "HumanTaskNode");
    assertThat(body.getNodeInstances()).extractingResultOf("getTriggerTime").allMatch(v -> v != null);
    // human task is active
    assertThat(body.getNodeInstances()).extractingResultOf("getLeaveTime").containsNull();
    // thus null for leave
    // time
    assertUserTaskInstanceEvent(events.get(1), "First Task", null, "1", "Ready", "UserTasksProcess");
    List<WorkItem> workItems = processInstance.workItems(SecurityPolicy.of(new StaticIdentityProvider("john")));
    assertEquals(1, workItems.size());
    assertEquals("FirstTask", workItems.get(0).getName());
    uow = app.unitOfWorkManager().newUnitOfWork();
    uow.start();
    processInstance.completeWorkItem(workItems.get(0).getId(), null, SecurityPolicy.of(new StaticIdentityProvider("john")));
    uow.end();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    events = publisher.extract();
    assertThat(events).isNotNull().hasSize(3);
    body = assertProcessInstanceEvent(events.get(0), "UserTasksProcess", "UserTasksProcess", 1);
    assertThat(body.getNodeInstances()).hasSize(2).extractingResultOf("getNodeType").contains("HumanTaskNode", "HumanTaskNode");
    assertThat(body.getNodeInstances()).extractingResultOf("getTriggerTime").allMatch(v -> v != null);
    // human task is active
    assertThat(body.getNodeInstances()).extractingResultOf("getLeaveTime").containsNull();
    // thus null for leave
    // time
    assertUserTaskInstanceEvent(events.get(1), "Second Task", null, "1", "Ready", "UserTasksProcess");
    assertUserTaskInstanceEvent(events.get(2), "First Task", null, "1", "Completed", "UserTasksProcess");
    workItems = processInstance.workItems(SecurityPolicy.of(new StaticIdentityProvider("john")));
    assertEquals(1, workItems.size());
    assertEquals("SecondTask", workItems.get(0).getName());
    uow = app.unitOfWorkManager().newUnitOfWork();
    uow.start();
    processInstance.completeWorkItem(workItems.get(0).getId(), null, SecurityPolicy.of(new StaticIdentityProvider("john")));
    uow.end();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
    events = publisher.extract();
    assertThat(events).isNotNull().hasSize(2);
    body = assertProcessInstanceEvent(events.get(0), "UserTasksProcess", "UserTasksProcess", 2);
    assertThat(body.getNodeInstances()).hasSize(2).extractingResultOf("getNodeType").contains("HumanTaskNode", "EndNode");
    assertThat(body.getNodeInstances()).extractingResultOf("getTriggerTime").allMatch(v -> v != null);
    assertThat(body.getNodeInstances()).extractingResultOf("getLeaveTime").allMatch(v -> v != null);
    assertUserTaskInstanceEvent(events.get(1), "Second Task", null, "1", "Completed", "UserTasksProcess");
}
Also used : StaticIdentityProvider(io.automatiko.engine.services.identity.StaticIdentityProvider) UnitOfWork(io.automatiko.engine.api.uow.UnitOfWork) HashMap(java.util.HashMap) ProcessInstanceEventBody(io.automatiko.engine.services.event.impl.ProcessInstanceEventBody) DataEvent(io.automatiko.engine.api.event.DataEvent) UserTaskInstanceDataEvent(io.automatiko.engine.services.event.UserTaskInstanceDataEvent) ProcessInstanceDataEvent(io.automatiko.engine.services.event.ProcessInstanceDataEvent) WorkItem(io.automatiko.engine.api.workflow.WorkItem) 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 23 with WorkItem

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

the class PublishEventTest method testBasicUserTaskProcessWithSensitiveData.

@Test
public void testBasicUserTaskProcessWithSensitiveData() throws Exception {
    Application app = generateCodeProcessesOnly("usertask/UserTasksProcessSensitive.bpmn2");
    assertThat(app).isNotNull();
    Process<? extends Model> p = app.processes().processById("UserTasksProcess");
    Model m = p.createModel();
    Map<String, Object> parameters = new HashMap<>();
    parameters.put("name", "john");
    parameters.put("ssn", "123-456");
    m.fromMap(parameters);
    TestEventPublisher publisher = new TestEventPublisher();
    app.unitOfWorkManager().eventManager().setService("http://myhost");
    app.unitOfWorkManager().eventManager().addPublisher(publisher);
    UnitOfWork uow = app.unitOfWorkManager().newUnitOfWork();
    uow.start();
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    uow.end();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    List<DataEvent<?>> events = publisher.extract();
    assertThat(events).isNotNull().hasSize(2);
    ProcessInstanceEventBody body = assertProcessInstanceEvent(events.get(0), "UserTasksProcess", "UserTasksProcess", 1);
    assertThat(body.getTags()).hasSize(0);
    assertThat(body.getVariables()).hasSize(1).containsEntry("name", "john");
    assertThat(body.getNodeInstances()).hasSize(2).extractingResultOf("getNodeType").contains("StartNode", "HumanTaskNode");
    assertThat(body.getNodeInstances()).extractingResultOf("getTriggerTime").allMatch(v -> v != null);
    // human task is active
    assertThat(body.getNodeInstances()).extractingResultOf("getLeaveTime").containsNull();
    // thus null for leave
    // time
    assertUserTaskInstanceEvent(events.get(1), "First Task", null, "1", "Ready", "UserTasksProcess");
    List<WorkItem> workItems = processInstance.workItems(SecurityPolicy.of(new StaticIdentityProvider("john")));
    assertEquals(1, workItems.size());
    assertEquals("FirstTask", workItems.get(0).getName());
    uow = app.unitOfWorkManager().newUnitOfWork();
    uow.start();
    processInstance.completeWorkItem(workItems.get(0).getId(), null, SecurityPolicy.of(new StaticIdentityProvider("john")));
    uow.end();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    events = publisher.extract();
    assertThat(events).isNotNull().hasSize(3);
    body = assertProcessInstanceEvent(events.get(0), "UserTasksProcess", "UserTasksProcess", 1);
    assertThat(body.getNodeInstances()).hasSize(2).extractingResultOf("getNodeType").contains("HumanTaskNode", "HumanTaskNode");
    assertThat(body.getNodeInstances()).extractingResultOf("getTriggerTime").allMatch(v -> v != null);
    // human task is active
    assertThat(body.getNodeInstances()).extractingResultOf("getLeaveTime").containsNull();
    // thus null for leave
    // time
    assertUserTaskInstanceEvent(events.get(1), "Second Task", null, "1", "Ready", "UserTasksProcess");
    assertUserTaskInstanceEvent(events.get(2), "First Task", null, "1", "Completed", "UserTasksProcess");
    workItems = processInstance.workItems(SecurityPolicy.of(new StaticIdentityProvider("john")));
    assertEquals(1, workItems.size());
    assertEquals("SecondTask", workItems.get(0).getName());
    uow = app.unitOfWorkManager().newUnitOfWork();
    uow.start();
    processInstance.completeWorkItem(workItems.get(0).getId(), null, SecurityPolicy.of(new StaticIdentityProvider("john")));
    uow.end();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
    events = publisher.extract();
    assertThat(events).isNotNull().hasSize(2);
    body = assertProcessInstanceEvent(events.get(0), "UserTasksProcess", "UserTasksProcess", 2);
    assertThat(body.getNodeInstances()).hasSize(2).extractingResultOf("getNodeType").contains("HumanTaskNode", "EndNode");
    assertThat(body.getNodeInstances()).extractingResultOf("getTriggerTime").allMatch(v -> v != null);
    assertThat(body.getNodeInstances()).extractingResultOf("getLeaveTime").allMatch(v -> v != null);
    assertUserTaskInstanceEvent(events.get(1), "Second Task", null, "1", "Completed", "UserTasksProcess");
}
Also used : StaticIdentityProvider(io.automatiko.engine.services.identity.StaticIdentityProvider) UnitOfWork(io.automatiko.engine.api.uow.UnitOfWork) HashMap(java.util.HashMap) ProcessInstanceEventBody(io.automatiko.engine.services.event.impl.ProcessInstanceEventBody) DataEvent(io.automatiko.engine.api.event.DataEvent) UserTaskInstanceDataEvent(io.automatiko.engine.services.event.UserTaskInstanceDataEvent) ProcessInstanceDataEvent(io.automatiko.engine.services.event.ProcessInstanceDataEvent) WorkItem(io.automatiko.engine.api.workflow.WorkItem) 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 24 with WorkItem

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

the class PublishEventTest method testBasicUserTaskProcess.

@Test
public void testBasicUserTaskProcess() throws Exception {
    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);
    TestEventPublisher publisher = new TestEventPublisher();
    app.unitOfWorkManager().eventManager().setService("http://myhost");
    app.unitOfWorkManager().eventManager().addPublisher(publisher);
    UnitOfWork uow = app.unitOfWorkManager().newUnitOfWork();
    uow.start();
    ProcessInstance<?> processInstance = p.createInstance(m);
    processInstance.start();
    uow.end();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    List<DataEvent<?>> events = publisher.extract();
    assertThat(events).isNotNull().hasSize(2);
    ProcessInstanceEventBody body = assertProcessInstanceEvent(events.get(0), "UserTasksProcess", "UserTasksProcess", 1);
    assertThat(body.getNodeInstances()).hasSize(2).extractingResultOf("getNodeType").contains("StartNode", "HumanTaskNode");
    assertThat(body.getNodeInstances()).extractingResultOf("getTriggerTime").allMatch(v -> v != null);
    // human task is active
    assertThat(body.getNodeInstances()).extractingResultOf("getLeaveTime").containsNull();
    // thus null for leave
    // time
    assertUserTaskInstanceEvent(events.get(1), "First Task", null, "1", "Ready", "UserTasksProcess");
    List<WorkItem> workItems = processInstance.workItems(SecurityPolicy.of(new StaticIdentityProvider("john")));
    assertEquals(1, workItems.size());
    assertEquals("FirstTask", workItems.get(0).getName());
    uow = app.unitOfWorkManager().newUnitOfWork();
    uow.start();
    processInstance.completeWorkItem(workItems.get(0).getId(), null, SecurityPolicy.of(new StaticIdentityProvider("john")));
    uow.end();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_ACTIVE);
    events = publisher.extract();
    assertThat(events).isNotNull().hasSize(3);
    body = assertProcessInstanceEvent(events.get(0), "UserTasksProcess", "UserTasksProcess", 1);
    assertThat(body.getNodeInstances()).hasSize(2).extractingResultOf("getNodeType").contains("HumanTaskNode", "HumanTaskNode");
    assertThat(body.getNodeInstances()).extractingResultOf("getTriggerTime").allMatch(v -> v != null);
    // human task is active
    assertThat(body.getNodeInstances()).extractingResultOf("getLeaveTime").containsNull();
    // thus null for leave
    // time
    assertUserTaskInstanceEvent(events.get(1), "Second Task", null, "1", "Ready", "UserTasksProcess");
    assertUserTaskInstanceEvent(events.get(2), "First Task", null, "1", "Completed", "UserTasksProcess");
    workItems = processInstance.workItems(SecurityPolicy.of(new StaticIdentityProvider("john")));
    assertEquals(1, workItems.size());
    assertEquals("SecondTask", workItems.get(0).getName());
    uow = app.unitOfWorkManager().newUnitOfWork();
    uow.start();
    processInstance.completeWorkItem(workItems.get(0).getId(), null, SecurityPolicy.of(new StaticIdentityProvider("john")));
    uow.end();
    assertThat(processInstance.status()).isEqualTo(ProcessInstance.STATE_COMPLETED);
    events = publisher.extract();
    assertThat(events).isNotNull().hasSize(2);
    body = assertProcessInstanceEvent(events.get(0), "UserTasksProcess", "UserTasksProcess", 2);
    assertThat(body.getNodeInstances()).hasSize(2).extractingResultOf("getNodeType").contains("HumanTaskNode", "EndNode");
    assertThat(body.getNodeInstances()).extractingResultOf("getTriggerTime").allMatch(v -> v != null);
    assertThat(body.getNodeInstances()).extractingResultOf("getLeaveTime").allMatch(v -> v != null);
    assertUserTaskInstanceEvent(events.get(1), "Second Task", null, "1", "Completed", "UserTasksProcess");
}
Also used : StaticIdentityProvider(io.automatiko.engine.services.identity.StaticIdentityProvider) UnitOfWork(io.automatiko.engine.api.uow.UnitOfWork) HashMap(java.util.HashMap) ProcessInstanceEventBody(io.automatiko.engine.services.event.impl.ProcessInstanceEventBody) DataEvent(io.automatiko.engine.api.event.DataEvent) UserTaskInstanceDataEvent(io.automatiko.engine.services.event.UserTaskInstanceDataEvent) ProcessInstanceDataEvent(io.automatiko.engine.services.event.ProcessInstanceDataEvent) WorkItem(io.automatiko.engine.api.workflow.WorkItem) 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 25 with WorkItem

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

the class MessageStartEventTest method testMultipleMessagesStartEventProcessCorrelationExpression.

@Test
public void testMultipleMessagesStartEventProcessCorrelationExpression() throws Exception {
    Application app = generateCodeProcessesOnly("messagestartevent/MessageAndMessageStartEventCorrelationExpr.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

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