use of org.drools.mvel.compiler.Message in project drools by kiegroup.
the class SequentialTest method testSharedSegment.
@Test
public void testSharedSegment() throws Exception {
// BZ-1228313
String str = "package org.drools.mvel.compiler.test\n" + "import \n" + Message.class.getCanonicalName() + ";" + "rule R1 when\n" + " $s : String()\n" + " $m : Message()\n" + " $i : Integer( this < $s.length )\n" + "then\n" + " modify($m) { setMessage($s) };\n" + "end\n" + "\n" + "rule R2 when\n" + " $s : String()\n" + " $m : Message()\n" + " $i : Integer( this > $s.length )\n" + "then\n" + "end\n";
final KieModule kieModule = KieUtil.getKieModuleFromDrls("test", kieBaseTestConfiguration, str);
final KieBase kbase = KieBaseUtil.newKieBaseFromKieModuleWithAdditionalOptions(kieModule, kieBaseTestConfiguration, SequentialOption.YES);
StatelessKieSession ksession = kbase.newStatelessKieSession();
ksession.execute(CommandFactory.newInsertElements(Arrays.asList("test", new Message(), 3, 5)));
}
use of org.drools.mvel.compiler.Message in project drools by kiegroup.
the class SequentialTest method testSequentialWithNoLoop.
@Test(timeout = 10000L)
public void testSequentialWithNoLoop() throws Exception {
// BZ-1228098
String str = "package org.drools.mvel.compiler.test\n" + "import \n" + Message.class.getCanonicalName() + ";" + "rule R1 no-loop when\n" + " $s : String( )" + " $m : Message( )\n" + "then\n" + " modify($m) { setMessage($s) };\n" + "end\n";
KieServices ks = KieServices.Factory.get();
final KieModule kieModule = KieUtil.getKieModuleFromDrls("test", kieBaseTestConfiguration, str);
KieContainer kieContainer = ks.newKieContainer(kieModule.getReleaseId());
final KieBase kbase = KieBaseUtil.newKieBaseFromKieModuleWithAdditionalOptions(kieModule, kieBaseTestConfiguration, SequentialOption.YES);
StatelessKieSession sequentialKsession = kbase.newStatelessKieSession();
List result = (List) sequentialKsession.execute(CommandFactory.newInsertElements(Arrays.asList("test", new Message())));
assertEquals(2, result.size());
StatelessKieSession ksession = kieContainer.getKieBase().newStatelessKieSession();
result = (List) ksession.execute(CommandFactory.newInsertElements(Arrays.asList("test", new Message())));
assertEquals(2, result.size());
}
use of org.drools.mvel.compiler.Message in project drools by kiegroup.
the class Misc2Test method testAddSameResourceTwice.
@Test
public void testAddSameResourceTwice() {
// DROOLS-180
String str = "rule R when\n" + " $s : String()\n" + "then\n" + "end\n";
KieBuilder kieBuilder = KieUtil.getKieBuilderFromDrls(kieBaseTestConfiguration, false, str, str);
List<org.kie.api.builder.Message> messages = kieBuilder.getResults().getMessages();
// Duplicate rule name
assertFalse("Should have any message", messages.isEmpty());
}
use of org.drools.mvel.compiler.Message in project drools by kiegroup.
the class Misc2Test method testNoLoopWithNamedConsequences.
@Test
public void testNoLoopWithNamedConsequences() {
// DROOLS-327
String drl = "import " + Message.class.getCanonicalName() + "\n" + "rule \"Hello World\" no-loop\n" + " when\n" + " m : Message( myMessage : message )\n" + " if (status == 0) do[sayHello]\n" + " then\n" + " System.out.println( myMessage );\n" + " m.setMessage( \"Goodbye cruel world\" );\n" + " m.setStatus( Message.GOODBYE );\n" + " update( m );\n" + " then[sayHello]\n" + " System.out.println(\"Hello, I'm here!\");\n" + "end\n";
KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, drl);
KieSession ksession = kbase.newKieSession();
ksession.insert(new Message("Hello World"));
ksession.fireAllRules();
}
use of org.drools.mvel.compiler.Message in project drools by kiegroup.
the class MarshallingTest method testAccumulate.
@Test
public void testAccumulate() throws Exception {
String rule = "package org.drools\n" + "import " + Message.class.getCanonicalName() + "\n" + "global java.util.List results\n" + "rule MyRule\n" + " when\n" + " $n : Number( intValue >= 2 ) from accumulate ( m: Message( ), count( m ) )\n" + " then\n" + " results.add($n);\n" + "end";
KieBase kBase = loadKnowledgeBaseFromString(rule);
KieSession ksession = getSerialisedStatefulKnowledgeSession(kBase.newKieSession(), true);
ksession = getSerialisedStatefulKnowledgeSession(ksession, true);
ksession.setGlobal("results", new ArrayList());
ksession = getSerialisedStatefulKnowledgeSession(ksession, true);
ksession.insert(new Message());
ksession = getSerialisedStatefulKnowledgeSession(ksession, true);
List results = (List) ksession.getGlobal("results");
ksession.insert(new Message());
ksession.insert(new Message());
ksession.fireAllRules();
assertEquals(3, ((Number) results.get(0)).intValue());
ksession = getSerialisedStatefulKnowledgeSession(ksession, true);
ksession.insert(new Message());
ksession.insert(new Message());
ksession = getSerialisedStatefulKnowledgeSession(ksession, true);
assertEquals(1, ((InternalAgenda) ksession.getAgenda()).getAgendaGroupsManager().agendaSize());
ksession.fireAllRules();
assertEquals(5, ((Number) results.get(1)).intValue());
}
Aggregations