public void testProcessEventListener() throws Exception {
KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
// create a simple package with one process to test the events
final Package pkg = new Package( "org.drools.test" );
RuleFlowProcess process = new RuleFlowProcess();
process.setId("org.drools.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");
DroolsAction action = new DroolsConsequenceAction("java", null);
action.setMetaData("Action", new Action() {
public void execute(ProcessContext context) throws Exception {
System.out.println("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
);
pkg.addProcess(process);
List<KnowledgePackage> pkgs = new ArrayList<KnowledgePackage>();
pkgs.add( new KnowledgePackageImp( pkg ) );
kbase.addKnowledgePackages( pkgs );
StatefulKnowledgeSession session = kbase.newStatefulKnowledgeSession();