use of org.jbpm.ruleflow.core.RuleFlowProcess in project jbpm by kiegroup.
the class CompensationTest method testCompensationBoundaryEventGeneral.
@Test
public void testCompensationBoundaryEventGeneral() throws Exception {
String processId = "org.jbpm.process.compensation.boundary";
String[] workItemNames = { "Don-Quixote", "Sancho", "Ricote" };
List<String> eventList = new ArrayList<String>();
RuleFlowProcess process = createCompensationBoundaryEventProcess(processId, workItemNames, eventList);
// run process
ksession = createKieSession(process);
String compensationEvent = CompensationScope.IMPLICIT_COMPENSATION_PREFIX + processId;
runCompensationBoundaryEventGeneralTest(ksession, process, processId, workItemNames, eventList, compensationEvent);
}
use of org.jbpm.ruleflow.core.RuleFlowProcess in project jbpm by kiegroup.
the class EventTest method testEvent1.
@Test
public void testEvent1() {
RuleFlowProcess process = new RuleFlowProcess();
process.setId("org.drools.core.process.event");
process.setName("Event 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);
StartNode startNode = new StartNode();
startNode.setName("Start");
startNode.setId(1);
process.addNode(startNode);
MilestoneNode milestoneNode = new MilestoneNode();
milestoneNode.setName("Milestone");
milestoneNode.setConstraint("eval(false)");
milestoneNode.setId(2);
process.addNode(milestoneNode);
new ConnectionImpl(startNode, Node.CONNECTION_DEFAULT_TYPE, milestoneNode, Node.CONNECTION_DEFAULT_TYPE);
EventNode eventNode = new EventNode();
EventTypeFilter eventFilter = new EventTypeFilter();
eventFilter.setType("myEvent");
eventNode.addEventFilter(eventFilter);
eventNode.setVariableName("event");
eventNode.setId(3);
process.addNode(eventNode);
final List<String> myList = new ArrayList<String>();
ActionNode actionNode = new ActionNode();
actionNode.setName("Print");
DroolsAction action = new DroolsConsequenceAction("java", null);
action.setMetaData("Action", new Action() {
public void execute(ProcessContext context) throws Exception {
logger.info("Detected event for person {}", ((Person) context.getVariable("event")).getName());
myList.add("Executed action");
}
});
actionNode.setAction(action);
actionNode.setId(4);
process.addNode(actionNode);
new ConnectionImpl(eventNode, Node.CONNECTION_DEFAULT_TYPE, actionNode, Node.CONNECTION_DEFAULT_TYPE);
Join join = new Join();
join.setName("XOR Join");
join.setType(Join.TYPE_XOR);
join.setId(5);
process.addNode(join);
new ConnectionImpl(milestoneNode, Node.CONNECTION_DEFAULT_TYPE, join, Node.CONNECTION_DEFAULT_TYPE);
new ConnectionImpl(actionNode, Node.CONNECTION_DEFAULT_TYPE, join, Node.CONNECTION_DEFAULT_TYPE);
EndNode endNode = new EndNode();
endNode.setName("EndNode");
endNode.setId(6);
process.addNode(endNode);
new ConnectionImpl(join, Node.CONNECTION_DEFAULT_TYPE, endNode, Node.CONNECTION_DEFAULT_TYPE);
KieSession ksession = createKieSession(process);
TestProcessEventListener procEventListener = new TestProcessEventListener();
ksession.addEventListener(procEventListener);
ProcessInstance processInstance = ksession.startProcess("org.drools.core.process.event");
assertEquals(0, myList.size());
Person jack = new Person();
jack.setName("Jack");
processInstance.signalEvent("myEvent", jack);
assertEquals(1, myList.size());
assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
verifyEventHistory(test1EventOrder, procEventListener.getEventHistory());
}
use of org.jbpm.ruleflow.core.RuleFlowProcess in project jbpm by kiegroup.
the class EventTest method testEvent4.
@Test
public void testEvent4() {
RuleFlowProcess process = new RuleFlowProcess();
process.setId("org.drools.core.process.event");
process.setName("Event 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);
StartNode startNode = new StartNode();
startNode.setName("Start");
startNode.setId(1);
process.addNode(startNode);
EventNode eventNode = new EventNode();
EventTypeFilter eventFilter = new EventTypeFilter();
eventFilter.setType("myEvent");
eventNode.addEventFilter(eventFilter);
eventNode.setId(3);
process.addNode(eventNode);
final List<String> myList = new ArrayList<String>();
ActionNode actionNode = new ActionNode();
actionNode.setName("Print");
DroolsAction action = new DroolsConsequenceAction("java", null);
action.setMetaData("Action", new Action() {
public void execute(ProcessContext context) throws Exception {
myList.add("Executed action");
}
});
actionNode.setAction(action);
actionNode.setId(4);
process.addNode(actionNode);
new ConnectionImpl(eventNode, Node.CONNECTION_DEFAULT_TYPE, actionNode, Node.CONNECTION_DEFAULT_TYPE);
EventNode eventNode2 = new EventNode();
eventFilter = new EventTypeFilter();
eventFilter.setType("myEvent");
eventNode2.addEventFilter(eventFilter);
eventNode2.setId(5);
process.addNode(eventNode2);
ActionNode actionNode2 = new ActionNode();
actionNode2.setName("Print");
action = new DroolsConsequenceAction("java", null);
action.setMetaData("Action", new Action() {
public void execute(ProcessContext context) throws Exception {
myList.add("Executed action");
}
});
actionNode2.setAction(action);
actionNode2.setId(6);
process.addNode(actionNode2);
new ConnectionImpl(eventNode2, Node.CONNECTION_DEFAULT_TYPE, actionNode2, Node.CONNECTION_DEFAULT_TYPE);
Join join = new Join();
join.setName("AND Join");
join.setType(Join.TYPE_AND);
join.setId(7);
process.addNode(join);
new ConnectionImpl(startNode, Node.CONNECTION_DEFAULT_TYPE, join, Node.CONNECTION_DEFAULT_TYPE);
new ConnectionImpl(actionNode, Node.CONNECTION_DEFAULT_TYPE, join, Node.CONNECTION_DEFAULT_TYPE);
new ConnectionImpl(actionNode2, Node.CONNECTION_DEFAULT_TYPE, join, Node.CONNECTION_DEFAULT_TYPE);
EndNode endNode = new EndNode();
endNode.setName("EndNode");
endNode.setId(8);
process.addNode(endNode);
new ConnectionImpl(join, Node.CONNECTION_DEFAULT_TYPE, endNode, Node.CONNECTION_DEFAULT_TYPE);
KieSession ksession = createKieSession(process);
TestProcessEventListener procEventListener = new TestProcessEventListener();
ksession.addEventListener(procEventListener);
ProcessInstance processInstance = ksession.startProcess("org.drools.core.process.event");
assertEquals(0, myList.size());
processInstance.signalEvent("myEvent", null);
assertEquals(2, myList.size());
assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
verifyEventHistory(test4EventOrder, procEventListener.getEventHistory());
}
use of org.jbpm.ruleflow.core.RuleFlowProcess in project jbpm by kiegroup.
the class EventTest method testEvent2.
@Test
public void testEvent2() {
RuleFlowProcess process = new RuleFlowProcess();
process.setId("org.drools.core.process.event");
process.setName("Event 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);
StartNode startNode = new StartNode();
startNode.setName("Start");
startNode.setId(1);
process.addNode(startNode);
MilestoneNode milestoneNode = new MilestoneNode();
milestoneNode.setName("Milestone");
milestoneNode.setConstraint("eval(false)");
milestoneNode.setId(2);
process.addNode(milestoneNode);
new ConnectionImpl(startNode, Node.CONNECTION_DEFAULT_TYPE, milestoneNode, Node.CONNECTION_DEFAULT_TYPE);
EndNode endNode = new EndNode();
endNode.setName("EndNode");
endNode.setId(3);
process.addNode(endNode);
new ConnectionImpl(milestoneNode, Node.CONNECTION_DEFAULT_TYPE, endNode, Node.CONNECTION_DEFAULT_TYPE);
EventNode eventNode = new EventNode();
EventTypeFilter eventFilter = new EventTypeFilter();
eventFilter.setType("myEvent");
eventNode.addEventFilter(eventFilter);
eventNode.setVariableName("event");
eventNode.setId(4);
process.addNode(eventNode);
final List<String> myList = new ArrayList<String>();
ActionNode actionNode = new ActionNode();
actionNode.setName("Print");
DroolsAction action = new DroolsConsequenceAction("java", null);
action.setMetaData("Action", new Action() {
public void execute(ProcessContext context) throws Exception {
logger.info("Detected event for person {}", ((Person) context.getVariable("event")).getName());
myList.add("Executed action");
}
});
actionNode.setAction(action);
actionNode.setId(5);
process.addNode(actionNode);
new ConnectionImpl(eventNode, Node.CONNECTION_DEFAULT_TYPE, actionNode, Node.CONNECTION_DEFAULT_TYPE);
EndNode endNode2 = new EndNode();
endNode2.setName("EndNode");
endNode2.setTerminate(false);
endNode2.setId(6);
process.addNode(endNode2);
new ConnectionImpl(actionNode, Node.CONNECTION_DEFAULT_TYPE, endNode2, Node.CONNECTION_DEFAULT_TYPE);
KieSession ksession = createKieSession(process);
TestProcessEventListener procEventListener = new TestProcessEventListener();
ksession.addEventListener(procEventListener);
ProcessInstance processInstance = ksession.startProcess("org.drools.core.process.event");
assertEquals(0, myList.size());
Person jack = new Person();
jack.setName("Jack");
processInstance.signalEvent("myEvent", jack);
assertEquals(1, myList.size());
Person john = new Person();
john.setName("John");
processInstance.signalEvent("myEvent", john);
assertEquals(2, myList.size());
verifyEventHistory(test2EventOrder, procEventListener.getEventHistory());
}
use of org.jbpm.ruleflow.core.RuleFlowProcess in project jbpm by kiegroup.
the class EventTest method testEvent5.
@Test
public void testEvent5() {
RuleFlowProcess process = new RuleFlowProcess();
process.setId("org.drools.core.process.event");
process.setName("Event 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);
StartNode startNode = new StartNode();
startNode.setName("Start");
startNode.setId(1);
process.addNode(startNode);
CompositeNode compositeNode = new CompositeNode();
compositeNode.setName("CompositeNode");
compositeNode.setId(2);
process.addNode(compositeNode);
new ConnectionImpl(startNode, Node.CONNECTION_DEFAULT_TYPE, compositeNode, Node.CONNECTION_DEFAULT_TYPE);
MilestoneNode milestoneNode = new MilestoneNode();
milestoneNode.setName("Milestone");
milestoneNode.setConstraint("eval(false)");
compositeNode.addNode(milestoneNode);
compositeNode.linkIncomingConnections(Node.CONNECTION_DEFAULT_TYPE, milestoneNode.getId(), Node.CONNECTION_DEFAULT_TYPE);
EventNode eventNode = new EventNode();
EventTypeFilter eventFilter = new EventTypeFilter();
eventFilter.setType("myEvent");
eventNode.addEventFilter(eventFilter);
eventNode.setVariableName("event");
compositeNode.addNode(eventNode);
final List<String> myList = new ArrayList<String>();
ActionNode actionNode = new ActionNode();
actionNode.setName("Print");
DroolsAction action = new DroolsConsequenceAction("java", null);
action.setMetaData("Action", new Action() {
public void execute(ProcessContext context) throws Exception {
logger.info("Detected event for person {}", ((Person) context.getVariable("event")).getName());
myList.add("Executed action");
}
});
actionNode.setAction(action);
compositeNode.addNode(actionNode);
new ConnectionImpl(eventNode, Node.CONNECTION_DEFAULT_TYPE, actionNode, Node.CONNECTION_DEFAULT_TYPE);
Join join = new Join();
join.setName("XOR Join");
join.setType(Join.TYPE_XOR);
compositeNode.addNode(join);
new ConnectionImpl(milestoneNode, Node.CONNECTION_DEFAULT_TYPE, join, Node.CONNECTION_DEFAULT_TYPE);
new ConnectionImpl(actionNode, Node.CONNECTION_DEFAULT_TYPE, join, Node.CONNECTION_DEFAULT_TYPE);
compositeNode.linkOutgoingConnections(join.getId(), Node.CONNECTION_DEFAULT_TYPE, Node.CONNECTION_DEFAULT_TYPE);
EndNode endNode = new EndNode();
endNode.setName("EndNode");
endNode.setId(3);
process.addNode(endNode);
new ConnectionImpl(compositeNode, Node.CONNECTION_DEFAULT_TYPE, endNode, Node.CONNECTION_DEFAULT_TYPE);
KieSession ksession = createKieSession(process);
TestProcessEventListener procEventListener = new TestProcessEventListener();
ksession.addEventListener(procEventListener);
ProcessInstance processInstance = ksession.startProcess("org.drools.core.process.event");
assertEquals(0, myList.size());
Person jack = new Person();
jack.setName("Jack");
processInstance.signalEvent("myEvent", jack);
assertEquals(1, myList.size());
assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
verifyEventHistory(test5EventOrder, procEventListener.getEventHistory());
}
Aggregations