import org.jbpm.workflow.core.node.StartNode;
public class EventTest extends JbpmTestCase {
public void testEvent1() {
RuleFlowProcess process = new RuleFlowProcess();
process.setId("org.drools.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 {
System.out.println("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
);