use of io.automatiko.engine.api.runtime.process.ProcessInstance in project automatiko-engine by automatiko-io.
the class SubProcessTest method testNonExistentSubProcess.
@Test
public void testNonExistentSubProcess() {
String nonExistentSubProcessName = "nonexistent.process";
ExecutableProcess process = new ExecutableProcess();
process.setId("org.company.core.process.process");
process.setName("Process");
StartNode startNode = new StartNode();
startNode.setName("Start");
startNode.setId(1);
SubProcessNode subProcessNode = new SubProcessNode();
subProcessNode.setName("SubProcessNode");
subProcessNode.setId(2);
subProcessNode.setProcessId(nonExistentSubProcessName);
EndNode endNode = new EndNode();
endNode.setName("End");
endNode.setId(3);
connect(startNode, subProcessNode);
connect(subProcessNode, endNode);
process.addNode(startNode);
process.addNode(subProcessNode);
process.addNode(endNode);
InternalProcessRuntime ksession = createProcessRuntime(process);
ProcessInstance pi = ksession.startProcess("org.company.core.process.process");
assertEquals(ProcessInstance.STATE_ERROR, pi.getState());
}
use of io.automatiko.engine.api.runtime.process.ProcessInstance in project automatiko-engine by automatiko-io.
the class WorkItemTest method testMockDataWorkItemHandlerCustomFunction.
@Test
public void testMockDataWorkItemHandlerCustomFunction() {
String processId = "org.company.actions";
String workName = "Unnexistent Task";
ExecutableProcess process = getWorkItemProcess(processId, workName);
InternalProcessRuntime ksession = createProcessRuntime(process);
ksession.getWorkItemManager().registerWorkItemHandler(workName, new MockDataWorkItemHandler((input) -> {
Map<String, Object> output = new HashMap<String, Object>();
if ("John Doe".equals(input.get("Comment"))) {
output.put("Result", "one");
} else {
output.put("Result", "two");
}
return output;
}));
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("UserName", "John Doe");
parameters.put("Person", new Person("John Doe"));
ProcessInstance processInstance = ksession.startProcess("org.company.actions", parameters);
Object numberVariable = ((WorkflowProcessInstance) processInstance).getVariable("MyObject");
assertNotNull(numberVariable);
assertEquals("one", numberVariable);
assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
parameters = new HashMap<String, Object>();
parameters.put("UserName", "John Doe");
parameters.put("Person", new Person("John Deen"));
processInstance = ksession.startProcess("org.company.actions", parameters);
numberVariable = ((WorkflowProcessInstance) processInstance).getVariable("MyObject");
assertNotNull(numberVariable);
assertEquals("two", numberVariable);
assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
}
use of io.automatiko.engine.api.runtime.process.ProcessInstance in project automatiko-engine by automatiko-io.
the class WorkItemTest method testMockDataWorkItemHandler.
@Test
public void testMockDataWorkItemHandler() {
String processId = "org.company.actions";
String workName = "Unnexistent Task";
ExecutableProcess process = getWorkItemProcess(processId, workName);
InternalProcessRuntime ksession = createProcessRuntime(process);
Map<String, Object> output = new HashMap<String, Object>();
output.put("Result", "test");
ksession.getWorkItemManager().registerWorkItemHandler(workName, new MockDataWorkItemHandler(output));
Map<String, Object> parameters = new HashMap<String, Object>();
parameters.put("UserName", "John Doe");
parameters.put("Person", new Person("John Doe"));
ProcessInstance processInstance = ksession.startProcess("org.company.actions", parameters);
Object numberVariable = ((WorkflowProcessInstance) processInstance).getVariable("MyObject");
assertNotNull(numberVariable);
assertEquals("test", numberVariable);
assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
}
use of io.automatiko.engine.api.runtime.process.ProcessInstance 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());
}
use of io.automatiko.engine.api.runtime.process.ProcessInstance 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());
}
Aggregations