assertEquals("SomeValue", list.get(0));
assertEquals(ProcessInstance.STATE_COMPLETED, processInstance.getState());
}
public void testNestedExceptionHandler() {
PackageBuilder builder = new PackageBuilder();
Reader source = new StringReader(
"<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +
"<process xmlns=\"http://drools.org/drools-5.0/process\"\n" +
" xmlns:xs=\"http://www.w3.org/2001/XMLSchema-instance\"\n" +
" xs:schemaLocation=\"http://drools.org/drools-5.0/process drools-processes-5.0.xsd\"\n" +
" type=\"RuleFlow\" name=\"flow\" id=\"org.drools.exception\" package-name=\"org.drools\" version=\"1\" >\n" +
"\n" +
" <header>\n" +
" <globals>\n" +
" <global identifier=\"list\" type=\"java.util.List\" />\n" +
" </globals>\n" +
" <exceptionHandlers>\n" +
" <exceptionHandler faultName=\"otherFault\" type=\"action\" >\n" +
" <action type=\"expression\" name=\"Print\" dialect=\"java\" >list.add(\"Triggered global exception scope\");</action>\n" +
" </exceptionHandler>\n" +
" </exceptionHandlers>\n" +
" </header>\n" +
"\n" +
" <nodes>\n" +
" <start id=\"1\" name=\"Start\" />\n" +
" <composite id=\"2\" name=\"Composite\" >\n" +
" <variables>\n" +
" <variable name=\"SomeVar\" >\n" +
" <type name=\"org.drools.process.core.datatype.impl.type.StringDataType\" />\n" +
" <value>SomeValue</value>\n" +
" </variable>\n" +
" <variable name=\"FaultVariable\" >\n" +
" <type name=\"org.drools.process.core.datatype.impl.type.StringDataType\" />\n" +
" </variable>\n" +
" </variables>\n" +
" <exceptionHandlers>\n" +
" <exceptionHandler faultName=\"MyFault\" type=\"action\" faultVariable=\"FaultVariable\" >\n" +
" <action type=\"expression\" name=\"Trigger\" dialect=\"java\" >((org.jbpm.workflow.instance.node.CompositeNodeInstance) context.getNodeInstance()).signalEvent(\"MyEvent\", null);</action>\n" +
" </exceptionHandler>\n" +
" </exceptionHandlers>\n" +
" <nodes>\n" +
" <fault id=\"1\" name=\"Fault\" faultName=\"MyFault\" faultVariable=\"SomeVar\" />\n" +
" <eventNode id=\"2\" name=\"Event\" >\n" +
" <eventFilters>\n" +
" <eventFilter type=\"eventType\" eventType=\"MyEvent\" />\n" +
" </eventFilters>\n" +
" </eventNode>\n" +
" <fault id=\"3\" name=\"Fault\" faultName=\"otherFault\" />\n" +
" </nodes>\n" +
" <connections>\n" +
" <connection from=\"2\" to=\"3\" />\n" +
" </connections>\n" +
" <in-ports>\n" +
" <in-port type=\"DROOLS_DEFAULT\" nodeId=\"1\" nodeInType=\"DROOLS_DEFAULT\" />\n" +
" </in-ports>\n" +
" </composite>\n" +
" <end id=\"3\" name=\"End\" />" +
" </nodes>\n" +
"\n" +
" <connections>\n" +
" <connection from=\"1\" to=\"2\" />\n" +
" <connection from=\"2\" to=\"3\" />\n" +
" </connections>\n" +
"\n" +
"</process>");
builder.addRuleFlow(source);
Package pkg = builder.getPackage();
RuleBase ruleBase = RuleBaseFactory.newRuleBase();
ruleBase.addPackage( pkg );
WorkingMemory workingMemory = ruleBase.newStatefulSession();
List<String> list = new ArrayList<String>();
workingMemory.setGlobal("list", list);