use of io.automatiko.engine.workflow.process.executable.core.ExecutableProcess in project automatiko-engine by automatiko-io.
the class CompensationTest method createCompensationBoundaryEventProcess.
private ExecutableProcess createCompensationBoundaryEventProcess(String processId, String[] workItemNames, final List<String> eventList) throws Exception {
ExecutableProcess process = new ExecutableProcess();
process.setAutoComplete(true);
process.setId(processId);
process.setName("CESP Process");
process.setMetaData("Compensation", true);
List<Variable> variables = new ArrayList<Variable>();
Variable variable = new Variable();
variable.setName("event");
ObjectDataType personDataType = new ObjectDataType(java.lang.String.class);
variable.setType(personDataType);
variables.add(variable);
process.getVariableScope().setVariables(variables);
NodeCreator<StartNode> startNodeCreator = new NodeCreator<StartNode>(process, StartNode.class);
NodeCreator<EndNode> endNodeCreator = new NodeCreator<EndNode>(process, EndNode.class);
NodeCreator<WorkItemNode> workItemNodeCreator = new NodeCreator<WorkItemNode>(process, WorkItemNode.class);
NodeCreator<BoundaryEventNode> boundaryNodeCreator = new NodeCreator<BoundaryEventNode>(process, BoundaryEventNode.class);
NodeCreator<ActionNode> actionNodeCreator = new NodeCreator<ActionNode>(process, ActionNode.class);
// Create process
StartNode startNode = startNodeCreator.createNode("start");
Node lastNode = startNode;
WorkItemNode[] workItemNodes = new WorkItemNode[3];
for (int i = 0; i < 3; ++i) {
workItemNodes[i] = workItemNodeCreator.createNode("work" + (i + 1));
workItemNodes[i].getWork().setName(workItemNames[i]);
connect(lastNode, workItemNodes[i]);
lastNode = workItemNodes[i];
}
EndNode endNode = endNodeCreator.createNode("end");
connect(workItemNodes[2], endNode);
// Compensation (boundary event) handlers
for (int i = 0; i < 3; ++i) {
createBoundaryEventCompensationHandler(process, workItemNodes[i], eventList, "" + i + 1);
}
return process;
}
use of io.automatiko.engine.workflow.process.executable.core.ExecutableProcess in project automatiko-engine by automatiko-io.
the class CompensationTest method testCompensationBoundaryEventSpecific.
/*
* TESTS
*/
@Test
public void testCompensationBoundaryEventSpecific() throws Exception {
String processId = "org.jbpm.process.compensation.boundary";
String[] workItemNames = { "Don-Quixote", "Sancho", "Ricote" };
List<String> eventList = new ArrayList<String>();
ExecutableProcess process = createCompensationBoundaryEventProcess(processId, workItemNames, eventList);
// run process
ksession = createProcessRuntime(process);
Node compensatedNode = findNode(process, "work1");
String compensationEvent = (String) compensatedNode.getMetaData().get("UniqueId");
runCompensationBoundaryEventSpecificTest(ksession, process, processId, workItemNames, eventList, compensationEvent);
}
use of io.automatiko.engine.workflow.process.executable.core.ExecutableProcess in project automatiko-engine by automatiko-io.
the class CompensationTest method testNestedCompensationEventSubProcessGeneral.
@Test
public void testNestedCompensationEventSubProcessGeneral() throws Exception {
String processId = "org.jbpm.process.compensation.event.subprocess.general";
String[] workItemNames = { "apple", "banana", "orange" };
List<String> eventList = new ArrayList<String>();
ExecutableProcess process = createNestedCompensationEventSubProcessProcess(processId, workItemNames, eventList);
Node toCompensateNode = findNode(process, "sub0");
String compensationEvent = CompensationScope.IMPLICIT_COMPENSATION_PREFIX + toCompensateNode.getMetaData().get("UniqueId");
ksession = createProcessRuntime(process);
runCompensationEventSubProcessGeneralTest(ksession, process, processId, workItemNames, eventList, compensationEvent);
}
use of io.automatiko.engine.workflow.process.executable.core.ExecutableProcess in project automatiko-engine by automatiko-io.
the class CompensationTest method testNestedCompensationBoundaryEventSpecific.
@Test
public void testNestedCompensationBoundaryEventSpecific() throws Exception {
String processId = "org.jbpm.process.compensation.boundary.nested";
String[] workItemNames = { "Don-Quixote", "Sancho", "Ricote" };
List<String> eventList = new ArrayList<String>();
ExecutableProcess process = createNestedCompensationBoundaryEventProcess(processId, workItemNames, eventList);
// run process
ksession = createProcessRuntime(process);
Node compensatedNode = findNode(process, "work-comp-1");
String compensationEvent = (String) compensatedNode.getMetaData().get("UniqueId");
runCompensationBoundaryEventSpecificTest(ksession, process, processId, workItemNames, eventList, compensationEvent);
}
use of io.automatiko.engine.workflow.process.executable.core.ExecutableProcess in project automatiko-engine by automatiko-io.
the class ProcessEventSupportTest method testProcessEventListener.
@Test
public void testProcessEventListener() throws Exception {
// create a simple package with one process to test the events
ExecutableProcess process = new ExecutableProcess();
process.setId("org.company.core.process.event");
process.setName("Event Process");
StartNode startNode = new StartNode();
startNode.setName("Start");
startNode.setId(1);
process.addNode(startNode);
ActionNode actionNode = new ActionNode();
actionNode.setName("Print");
ProcessAction action = new ConsequenceAction("java", null);
action.setMetaData("Action", new Action() {
public void execute(ProcessContext context) throws Exception {
logger.info("Executed action");
}
});
actionNode.setAction(action);
actionNode.setId(2);
process.addNode(actionNode);
new ConnectionImpl(startNode, Node.CONNECTION_DEFAULT_TYPE, actionNode, Node.CONNECTION_DEFAULT_TYPE);
EndNode endNode = new EndNode();
endNode.setName("End");
endNode.setId(3);
process.addNode(endNode);
new ConnectionImpl(actionNode, Node.CONNECTION_DEFAULT_TYPE, endNode, Node.CONNECTION_DEFAULT_TYPE);
InternalProcessRuntime processRuntime = new ProcessRuntimeImpl(Collections.singletonMap(process.getId(), process));
final List<ProcessEvent> processEventList = new ArrayList<ProcessEvent>();
final ProcessEventListener processEventListener = new ProcessEventListener() {
public void afterNodeLeft(ProcessNodeLeftEvent event) {
processEventList.add(event);
}
public void afterNodeTriggered(ProcessNodeTriggeredEvent event) {
processEventList.add(event);
}
public void afterProcessCompleted(ProcessCompletedEvent event) {
processEventList.add(event);
}
public void afterProcessStarted(ProcessStartedEvent event) {
processEventList.add(event);
}
public void beforeNodeLeft(ProcessNodeLeftEvent event) {
processEventList.add(event);
}
public void beforeNodeTriggered(ProcessNodeTriggeredEvent event) {
processEventList.add(event);
}
public void beforeProcessCompleted(ProcessCompletedEvent event) {
processEventList.add(event);
}
public void beforeProcessStarted(ProcessStartedEvent event) {
processEventList.add(event);
}
public void beforeVariableChanged(ProcessVariableChangedEvent event) {
processEventList.add(event);
}
public void afterVariableChanged(ProcessVariableChangedEvent event) {
processEventList.add(event);
}
};
processRuntime.addEventListener(processEventListener);
// execute the process
processRuntime.startProcess("org.company.core.process.event");
assertEquals(16, processEventList.size());
assertEquals("org.company.core.process.event", ((ProcessStartedEvent) processEventList.get(0)).getProcessInstance().getProcessId());
assertEquals("Start", ((ProcessNodeTriggeredEvent) processEventList.get(1)).getNodeInstance().getNodeName());
assertEquals("Start", ((ProcessNodeLeftEvent) processEventList.get(2)).getNodeInstance().getNodeName());
assertEquals("Print", ((ProcessNodeTriggeredEvent) processEventList.get(3)).getNodeInstance().getNodeName());
assertEquals("Print", ((ProcessNodeLeftEvent) processEventList.get(4)).getNodeInstance().getNodeName());
assertEquals("End", ((ProcessNodeTriggeredEvent) processEventList.get(5)).getNodeInstance().getNodeName());
assertEquals("End", ((ProcessNodeLeftEvent) processEventList.get(6)).getNodeInstance().getNodeName());
assertEquals("org.company.core.process.event", ((ProcessCompletedEvent) processEventList.get(7)).getProcessInstance().getProcessId());
assertEquals("org.company.core.process.event", ((ProcessCompletedEvent) processEventList.get(8)).getProcessInstance().getProcessId());
assertEquals("End", ((ProcessNodeLeftEvent) processEventList.get(9)).getNodeInstance().getNodeName());
assertEquals("End", ((ProcessNodeTriggeredEvent) processEventList.get(10)).getNodeInstance().getNodeName());
assertEquals("Print", ((ProcessNodeLeftEvent) processEventList.get(11)).getNodeInstance().getNodeName());
assertEquals("Print", ((ProcessNodeTriggeredEvent) processEventList.get(12)).getNodeInstance().getNodeName());
assertEquals("Start", ((ProcessNodeLeftEvent) processEventList.get(13)).getNodeInstance().getNodeName());
assertEquals("Start", ((ProcessNodeTriggeredEvent) processEventList.get(14)).getNodeInstance().getNodeName());
assertEquals("org.company.core.process.event", ((ProcessStartedEvent) processEventList.get(15)).getProcessInstance().getProcessId());
}
Aggregations