use of org.drools.core.command.runtime.rule.FireAllRulesCommand in project jbpm by kiegroup.
the class AgendaFilterTest method testActivationCancelled.
@Test
public void testActivationCancelled() {
// JBRULES-3376
String drl = "package org.jboss.qa.brms.agendafilter\n" + "declare CancelFact\n" + " cancel : boolean = true\n" + "end\n" + "rule NoCancel\n" + " ruleflow-group \"rfg\"\n" + " when\n" + " $fact : CancelFact ( cancel == false )\n" + " then\n" + " System.out.println(\"No cancel...\");\n" + " modify ($fact) {\n" + " setCancel(true);\n" + " }\n" + "end\n" + "rule PresenceOfBothFacts\n" + " ruleflow-group \"rfg\"\n" + " salience -1\n" + " when\n" + " $fact1 : CancelFact( cancel == false )\n" + " $fact2 : CancelFact( cancel == true )\n" + " then\n" + " System.out.println(\"Both facts!\");\n" + "end\n" + "rule PresenceOfFact\n" + " ruleflow-group \"rfg\"\n" + " when\n" + " $fact : CancelFact( )\n" + " then\n" + " System.out.println(\"We have a \" + ($fact.isCancel() ? \"\" : \"non-\") + \"cancelling fact!\");\n" + "end\n" + "rule Cancel\n" + " ruleflow-group \"rfg\"\n" + " when\n" + " $fact : CancelFact ( cancel == true )\n" + " then\n" + " System.out.println(\"Cancel!\");\n" + "end";
String rf = "<?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=\"bz761715\" package-name=\"org.jboss.qa.brms.agendafilter\" >\n" + " <header>\n" + " </header>\n" + " <nodes>\n" + " <start id=\"1\" name=\"Start\" x=\"16\" y=\"16\" width=\"48\" height=\"48\" />\n" + " <ruleSet id=\"2\" name=\"Rule\" x=\"208\" y=\"16\" width=\"80\" height=\"48\" ruleFlowGroup=\"rfg\" />\n" + " <actionNode id=\"3\" name=\"Script\" x=\"320\" y=\"16\" width=\"80\" height=\"48\" >\n" + " <action type=\"expression\" dialect=\"java\" >System.out.println(\"Finishing process...\");</action>\n" + " </actionNode>\n" + " <end id=\"4\" name=\"End\" x=\"432\" y=\"16\" width=\"48\" height=\"48\" />\n" + " <actionNode id=\"5\" name=\"Script\" x=\"96\" y=\"16\" width=\"80\" height=\"48\" >\n" + " <action type=\"expression\" dialect=\"java\" >System.out.println(\"Starting process...\");</action>\n" + " </actionNode>\n" + " </nodes>\n" + " <connections>\n" + " <connection from=\"5\" to=\"2\" />\n" + " <connection from=\"2\" to=\"3\" />\n" + " <connection from=\"3\" to=\"4\" />\n" + " <connection from=\"1\" to=\"5\" />\n" + " </connections>\n" + "</process>";
KnowledgeBuilder kbuilder = KnowledgeBuilderFactory.newKnowledgeBuilder();
kbuilder.add(ResourceFactory.newByteArrayResource(drl.getBytes()), ResourceType.DRL);
kbuilder.add(ResourceFactory.newByteArrayResource(rf.getBytes()), ResourceType.DRF);
if (kbuilder.hasErrors()) {
fail(kbuilder.getErrors().toString());
}
InternalKnowledgeBase kbase = KnowledgeBaseFactory.newKnowledgeBase();
kbase.addPackages(kbuilder.getKnowledgePackages());
KieSession ksession = kbase.newKieSession();
ksession.addEventListener(new DebugAgendaEventListener());
ksession.addEventListener(new DebugProcessEventListener());
List<Command<?>> commands = new ArrayList<Command<?>>();
commands.add(CommandFactory.newInsert(newCancelFact(ksession, false)));
commands.add(CommandFactory.newInsert(newCancelFact(ksession, true)));
commands.add(CommandFactory.newStartProcess("bz761715"));
commands.add(new FireAllRulesCommand(new CancelAgendaFilter()));
commands.add(new FireAllRulesCommand(new CancelAgendaFilter()));
commands.add(new FireAllRulesCommand(new CancelAgendaFilter()));
ksession.execute(CommandFactory.newBatchExecution(commands));
}
Aggregations