rule += "then\n";
rule += " list.add( $p );\n";
rule += "end";
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(new ByteArrayResource(rule.getBytes()), ResourceType.DRL);
String process =
"<?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=\"ruleflow\" id=\"org.test.ruleflow\" package-name=\"org.test\" >\n" +
" <header>\n" +
" </header>\n" +
" <nodes>\n" +
" <start id=\"1\" name=\"Start\" />\n" +
" <ruleSet id=\"2\" name=\"Hello\" ruleFlowGroup=\"hello\" />\n" +
" <end id=\"3\" name=\"End\" />\n" +
" </nodes>\n" +
" <connections>\n" +
" <connection from=\"1\" to=\"2\"/>\n" +
" <connection from=\"2\" to=\"3\"/>\n" +
" </connections>\n" +
"</process>";
kbuilder.add(new ByteArrayResource(process.getBytes()), ResourceType.DRF);
final KnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
StatefulKnowledgeSession ksession = kbase.newStatefulKnowledgeSession();
List<String> list = new ArrayList<String>();
ksession.setGlobal( "list", list );
Person p = new Person( "bobba fet", 32);
ksession.insert( p );
org.drools.runtime.process.ProcessInstance processInstance = ksession.startProcess("org.test.ruleflow");
assertEquals(1, ksession.getProcessInstances().size());
String process2 =
"<?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=\"ruleflow\" id=\"org.test.ruleflow2\" package-name=\"org.test\" >\n" +
" <header>\n" +
" <globals>\n" +
" <global identifier=\"list\" type=\"java.util.List\" />\n" +
" </globals>\n" +
" </header>\n" +
" <nodes>\n" +
" <start id=\"1\" name=\"Start\" />\n" +
" <ruleSet id=\"2\" name=\"Hello\" ruleFlowGroup=\"hello\" />\n" +
" <actionNode id=\"4\" name=\"Action\" >" +
" <action type=\"expression\" dialect=\"java\">System.out.println();\n" +
"list.add(\"Executed\");</action>\n" +
" </actionNode>\n" +
" <end id=\"3\" name=\"End\" />\n" +
" </nodes>\n" +
" <connections>\n" +
" <connection from=\"1\" to=\"2\"/>\n" +
" <connection from=\"2\" to=\"4\"/>\n" +
" <connection from=\"4\" to=\"3\"/>\n" +
" </connections>\n" +
"</process>";
kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(new ByteArrayResource(process2.getBytes()), ResourceType.DRF);
kbase.addKnowledgePackages(kbuilder.getKnowledgePackages());
WorkflowProcessInstanceUpgrader.upgradeProcessInstance(
ksession, processInstance.getId(), "org.test.ruleflow2", new HashMap<String, Long>());
assertEquals("org.test.ruleflow2", processInstance.getProcessId());