session2.halt();
}
@SuppressWarnings("unchecked")
public void testVariableSimpleProcess() throws Exception {
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.timer\" package-name=\"org.jbpm\" version=\"1\" >\n" +
"\n" +
" <header>\n" +
" <imports>\n" +
" <import name=\"org.jbpm.Message\" />\n" +
" </imports>\n" +
" <globals>\n" +
" <global identifier=\"myList\" type=\"java.util.List\" />\n" +
" </globals>\n" +
" <variables>\n" +
" <variable name=\"x\" >\n" +
" <type name=\"org.drools.process.core.datatype.impl.type.IntegerDataType\" />\n" +
" </variable>\n" +
" <variable name=\"y\" >\n" +
" <type name=\"org.drools.process.core.datatype.impl.type.IntegerDataType\" />\n" +
" </variable>\n" +
" </variables>\n" +
" </header>\n" +
"\n" +
" <nodes>\n" +
" <start id=\"1\" name=\"Start\" />\n" +
" <end id=\"2\" name=\"End\" />\n" +
" <timerNode id=\"3\" name=\"Timer\" delay=\"#{x}ms\" period=\"#{y}ms\" />\n" +
" <actionNode id=\"4\" name=\"Action\" >\n" +
" <action type=\"expression\" dialect=\"java\" >System.out.println(\"Triggered\");\n" +
"myList.add( new Message() );\n" +
"insert( new Message() );\n" +
"</action>\n" +
" </actionNode>\n" +
" <milestone id=\"5\" name=\"Wait\" >\n" +
" <constraint type=\"rule\" dialect=\"mvel\" >Number( intValue >= 5 ) from accumulate ( m: Message( ), count( m ) )</constraint>\n" +
" </milestone>\n" +
" </nodes>\n" +
"\n" +
" <connections>\n" +
" <connection from=\"5\" to=\"2\" />\n" +
" <connection from=\"1\" to=\"3\" />\n" +
" <connection from=\"3\" to=\"4\" />\n" +
" <connection from=\"4\" to=\"5\" />\n" +
" </connections>\n" +
"\n" +
"</process>");
builder.addRuleFlow(source);
if (!builder.getErrors().isEmpty()) {
for (DroolsError error: builder.getErrors().getErrors()) {
System.err.println(error);
}
fail("Could not build process");
}
Package pkg = builder.getPackage();
RuleBase ruleBase = RuleBaseFactory.newRuleBase();
ruleBase.addPackage( pkg );
final StatefulSession session = ruleBase.newStatefulSession();
List<Message> myList = new ArrayList<Message>();
session.setGlobal("myList", myList);