use of org.jbpm.process.test.TestWorkItemHandler in project jbpm by kiegroup.
the class CompensationTest method runCompensationBoundaryEventGeneralTest.
public static void runCompensationBoundaryEventGeneralTest(KieSession ksession, RuleFlowProcess 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("Compensation should not have fired yet.", 0, eventList.size());
// 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("Compensation should not have fired yet.", 0, eventList.size());
// general compensation should now cause the compensation handlers to fire in reverse order
ksession.signalEvent("Compensation", compensationEvent, processInstance.getId());
assertEquals("Compensation should have fired.", 2, eventList.size());
// complete work 3 and finish
ksession.getWorkItemManager().completeWorkItem(workItemHandler.getWorkItems().removeLast().getId(), null);
assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
}
use of org.jbpm.process.test.TestWorkItemHandler in project jbpm by kiegroup.
the class CompensationTest method runCompensationBoundaryEventSpecificTest.
public static void runCompensationBoundaryEventSpecificTest(KieSession ksession, RuleFlowProcess 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("Compensation should not have fired yet.", 0, eventList.size());
// 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("Compensation should have fired.", 1, eventList.size());
// 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 org.jbpm.process.test.TestWorkItemHandler in project jbpm by kiegroup.
the class CompensationTest method runCompensationEventSubProcessGeneralTest.
public static void runCompensationEventSubProcessGeneralTest(KieSession ksession, RuleFlowProcess 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("Compensation should have fired once.", 1, eventList.size());
// post work item
ksession.getWorkItemManager().completeWorkItem(workItemHandler.getWorkItems().removeLast().getId(), null);
assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
}
use of org.jbpm.process.test.TestWorkItemHandler in project jbpm by kiegroup.
the class CompensationTest method runCompensationEventSubProcessSpecificTest.
public static void runCompensationEventSubProcessSpecificTest(KieSession ksession, RuleFlowProcess 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("Compensation should not have fired yet.", 0, eventList.size());
// 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("Compensation should not have fired yet.", 0, eventList.size());
// sub process work item
ksession.getWorkItemManager().completeWorkItem(workItemHandler.getWorkItems().removeLast().getId(), null);
// sub-process has completed
ksession.signalEvent("Compensation", compensationEvent, processInstance.getId());
assertEquals("Compensation should have fired once.", 1, eventList.size());
// post work item
ksession.getWorkItemManager().completeWorkItem(workItemHandler.getWorkItems().removeLast().getId(), null);
assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
}
use of org.jbpm.process.test.TestWorkItemHandler in project jbpm by kiegroup.
the class EventSubProcessTest method testNestedEventSubProcess.
@Test
public void testNestedEventSubProcess() throws Exception {
RuleFlowProcess process = new RuleFlowProcess();
process.setAutoComplete(true);
String processId = "org.jbpm.process.event.subprocess";
process.setId(processId);
process.setName("Event SubProcess Process");
List<Variable> variables = new ArrayList<Variable>();
Variable variable = new Variable();
variable.setName("event");
ObjectDataType personDataType = new ObjectDataType();
personDataType.setClassName("org.drools.Person");
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<CompositeNode> compNodeCreator = new NodeCreator<CompositeNode>(process, CompositeNode.class);
// outer process
StartNode startNode = startNodeCreator.createNode("start0");
CompositeNode compositeNode = compNodeCreator.createNode("comp0");
connect(startNode, compositeNode);
EndNode endNode = endNodeCreator.createNode("end0");
connect(compositeNode, endNode);
// 1rst level nested subprocess
startNodeCreator.setNodeContainer(compositeNode);
endNodeCreator.setNodeContainer(compositeNode);
compNodeCreator.setNodeContainer(compositeNode);
startNode = startNodeCreator.createNode("start1");
compositeNode = compNodeCreator.createNode("comp1");
connect(startNode, compositeNode);
endNode = endNodeCreator.createNode("end1");
connect(compositeNode, endNode);
// 2nd level subprocess
startNodeCreator.setNodeContainer(compositeNode);
endNodeCreator.setNodeContainer(compositeNode);
NodeCreator<WorkItemNode> workItemNodeCreator = new NodeCreator<WorkItemNode>(compositeNode, WorkItemNode.class);
startNode = startNodeCreator.createNode("start2");
WorkItemNode workItemNode = workItemNodeCreator.createNode("workItem2");
Work work = new WorkImpl();
String workItemName = "play";
work.setName(workItemName);
workItemNode.setWork(work);
connect(startNode, workItemNode);
endNode = endNodeCreator.createNode("end2");
connect(workItemNode, endNode);
// (3rd level) event sub process in 2nd level subprocess
NodeCreator<EventSubProcessNode> espNodeCreator = new NodeCreator<EventSubProcessNode>(compositeNode, EventSubProcessNode.class);
EventSubProcessNode espNode = espNodeCreator.createNode("eventSub2");
EventTypeFilter eventFilter = new EventTypeFilter();
String EVENT_NAME = "subEvent";
eventFilter.setType(EVENT_NAME);
espNode.addEvent(eventFilter);
startNodeCreator.setNodeContainer(espNode);
endNodeCreator.setNodeContainer(espNode);
NodeCreator<ActionNode> actionNodeCreator = new NodeCreator<ActionNode>(espNode, ActionNode.class);
startNode = startNodeCreator.createNode("start3*");
ActionNode actionNode = actionNodeCreator.createNode("print3*");
actionNode.setName("Print");
final List<String> eventList = new ArrayList<String>();
DroolsAction action = new DroolsConsequenceAction("java", null);
action.setMetaData("Action", new Action() {
public void execute(ProcessContext context) throws Exception {
eventList.add("Executed action");
}
});
actionNode.setAction(action);
connect(startNode, actionNode);
endNode = endNodeCreator.createNode("end3*");
connect(actionNode, endNode);
// run process
KieSession ksession = createKieSession(process);
TestProcessEventListener procEventListener = new TestProcessEventListener();
ksession.addEventListener(procEventListener);
TestWorkItemHandler workItemHandler = new TestWorkItemHandler();
ksession.getWorkItemManager().registerWorkItemHandler(workItemName, workItemHandler);
ProcessInstance processInstance = ksession.startProcess(processId);
processInstance.signalEvent(EVENT_NAME, null);
assertEquals("Event " + EVENT_NAME + " did not fire!", 1, eventList.size());
ksession.getWorkItemManager().completeWorkItem(workItemHandler.getWorkItems().removeLast().getId(), null);
assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
verifyEventHistory(nestedEventOrder, procEventListener.getEventHistory());
}
Aggregations