Search in sources :

Example 1 with TestWorkItemHandler

use of io.automatiko.engine.workflow.process.test.TestWorkItemHandler in project automatiko-engine by automatiko-io.

the class CompensationTest method runCompensationBoundaryEventSpecificTest.

public static void runCompensationBoundaryEventSpecificTest(InternalProcessRuntime ksession, ExecutableProcess process, String processId, String[] workItemNames, List<String> eventList, String compensationEvent) {
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    for (String workItem : workItemNames) {
        ksession.getWorkItemManager().registerWorkItemHandler(workItem, workItemHandler);
    }
    ProcessInstance processInstance = ksession.startProcess(processId);
    // call compensation on the uncompleted work 1 (which should not fire)
    ksession.signalEvent("Compensation", compensationEvent, processInstance.getId());
    assertEquals(0, eventList.size(), "Compensation should not have fired yet.");
    // complete work 1
    ksession.getWorkItemManager().completeWorkItem(workItemHandler.getWorkItems().removeLast().getId(), null);
    assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
    // call compensation on work 1, which should now fire
    ksession.signalEvent("Compensation", compensationEvent, processInstance.getId());
    assertEquals(1, eventList.size(), "Compensation should have fired.");
    // complete work 2 & 3
    ksession.getWorkItemManager().completeWorkItem(workItemHandler.getWorkItems().removeLast().getId(), null);
    ksession.getWorkItemManager().completeWorkItem(workItemHandler.getWorkItems().removeLast().getId(), null);
    assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
}
Also used : TestWorkItemHandler(io.automatiko.engine.workflow.process.test.TestWorkItemHandler) ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance)

Example 2 with TestWorkItemHandler

use of io.automatiko.engine.workflow.process.test.TestWorkItemHandler in project automatiko-engine by automatiko-io.

the class CompensationTest method runCompensationEventSubProcessGeneralTest.

public static void runCompensationEventSubProcessGeneralTest(InternalProcessRuntime ksession, ExecutableProcess process, String processId, String[] workItemNames, List<String> eventList, String compensationEvent) {
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    for (String workItem : workItemNames) {
        ksession.getWorkItemManager().registerWorkItemHandler(workItem, workItemHandler);
    }
    ProcessInstance processInstance = ksession.startProcess(processId);
    // pre and sub process work item
    ksession.getWorkItemManager().completeWorkItem(workItemHandler.getWorkItems().removeLast().getId(), null);
    ksession.getWorkItemManager().completeWorkItem(workItemHandler.getWorkItems().removeLast().getId(), null);
    // Call general compensation
    ksession.signalEvent("Compensation", compensationEvent, processInstance.getId());
    assertEquals(1, eventList.size(), "Compensation should have fired once.");
    // post work item
    ksession.getWorkItemManager().completeWorkItem(workItemHandler.getWorkItems().removeLast().getId(), null);
    assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
}
Also used : TestWorkItemHandler(io.automatiko.engine.workflow.process.test.TestWorkItemHandler) ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance)

Example 3 with TestWorkItemHandler

use of io.automatiko.engine.workflow.process.test.TestWorkItemHandler in project automatiko-engine by automatiko-io.

the class CompensationTest method runCompensationEventSubProcessSpecificTest.

public static void runCompensationEventSubProcessSpecificTest(InternalProcessRuntime ksession, ExecutableProcess process, String processId, String[] workItemNames, List<String> eventList, String compensationEvent) {
    // run process
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    for (String workItem : workItemNames) {
        ksession.getWorkItemManager().registerWorkItemHandler(workItem, workItemHandler);
    }
    ProcessInstance processInstance = ksession.startProcess(processId);
    // call compensation on the uncompleted work 1 (which should not fire)
    ksession.signalEvent("Compensation", compensationEvent, processInstance.getId());
    assertEquals(0, eventList.size(), "Compensation should not have fired yet.");
    // pre work item
    ksession.getWorkItemManager().completeWorkItem(workItemHandler.getWorkItems().removeLast().getId(), null);
    // sub-process is active, but not complete
    ksession.signalEvent("Compensation", compensationEvent, processInstance.getId());
    assertEquals(0, eventList.size(), "Compensation should not have fired yet.");
    // sub process work item
    ksession.getWorkItemManager().completeWorkItem(workItemHandler.getWorkItems().removeLast().getId(), null);
    // sub-process has completed
    ksession.signalEvent("Compensation", compensationEvent, processInstance.getId());
    assertEquals(1, eventList.size(), "Compensation should have fired once.");
    // post work item
    ksession.getWorkItemManager().completeWorkItem(workItemHandler.getWorkItems().removeLast().getId(), null);
    assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
}
Also used : TestWorkItemHandler(io.automatiko.engine.workflow.process.test.TestWorkItemHandler) ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance)

Example 4 with TestWorkItemHandler

use of io.automatiko.engine.workflow.process.test.TestWorkItemHandler in project automatiko-engine by automatiko-io.

the class CompensationTest method runCompensationBoundaryEventGeneralTest.

public static void runCompensationBoundaryEventGeneralTest(InternalProcessRuntime ksession, ExecutableProcess process, String processId, String[] workItemNames, List<String> eventList, String compensationEvent) {
    TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
    for (String workItem : workItemNames) {
        ksession.getWorkItemManager().registerWorkItemHandler(workItem, workItemHandler);
    }
    ProcessInstance processInstance = ksession.startProcess(processId);
    // general compensation should not cause anything to happen
    ksession.signalEvent("Compensation", compensationEvent, processInstance.getId());
    assertEquals(0, eventList.size(), "Compensation should not have fired yet.");
    // complete work 1 & 2
    ksession.getWorkItemManager().completeWorkItem(workItemHandler.getWorkItems().removeLast().getId(), null);
    ksession.getWorkItemManager().completeWorkItem(workItemHandler.getWorkItems().removeLast().getId(), null);
    assertEquals(ProcessInstance.STATE_ACTIVE, processInstance.getState());
    assertEquals(0, eventList.size(), "Compensation should not have fired yet.");
    // general compensation should now cause the compensation handlers to fire in
    // reverse order
    ksession.signalEvent("Compensation", compensationEvent, processInstance.getId());
    assertEquals(2, eventList.size(), "Compensation should have fired.");
    // complete work 3 and finish
    ksession.getWorkItemManager().completeWorkItem(workItemHandler.getWorkItems().removeLast().getId(), null);
    assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
}
Also used : TestWorkItemHandler(io.automatiko.engine.workflow.process.test.TestWorkItemHandler) ProcessInstance(io.automatiko.engine.api.runtime.process.ProcessInstance)

Aggregations

ProcessInstance (io.automatiko.engine.api.runtime.process.ProcessInstance)4 TestWorkItemHandler (io.automatiko.engine.workflow.process.test.TestWorkItemHandler)4