Search in sources :

Example 1 with Message

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)));
}
Also used : Message(org.drools.mvel.compiler.Message) KieBase(org.kie.api.KieBase) StatelessKieSession(org.kie.api.runtime.StatelessKieSession) KieModule(org.kie.api.builder.KieModule) DynamicRulesTest(org.drools.mvel.integrationtests.DynamicRulesTest) Test(org.junit.Test)

Example 2 with Message

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());
}
Also used : Message(org.drools.mvel.compiler.Message) KieBase(org.kie.api.KieBase) StatelessKieSession(org.kie.api.runtime.StatelessKieSession) KieServices(org.kie.api.KieServices) ArrayList(java.util.ArrayList) List(java.util.List) KieModule(org.kie.api.builder.KieModule) KieContainer(org.kie.api.runtime.KieContainer) DynamicRulesTest(org.drools.mvel.integrationtests.DynamicRulesTest) Test(org.junit.Test)

Example 3 with Message

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());
}
Also used : Message(org.drools.mvel.compiler.Message) FactWithString(org.drools.mvel.integrationtests.facts.FactWithString) KieBuilder(org.kie.api.builder.KieBuilder) Test(org.junit.Test)

Example 4 with Message

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();
}
Also used : Message(org.drools.mvel.compiler.Message) KieBase(org.kie.api.KieBase) KieSession(org.kie.api.runtime.KieSession) StatelessKieSession(org.kie.api.runtime.StatelessKieSession) FactWithString(org.drools.mvel.integrationtests.facts.FactWithString) Test(org.junit.Test)

Example 5 with Message

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());
}
Also used : InternalAgenda(org.drools.core.common.InternalAgenda) Message(org.drools.mvel.compiler.Message) KieBase(org.kie.api.KieBase) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) IteratorToList(org.drools.mvel.integrationtests.IteratorToList) List(java.util.List) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Aggregations

Message (org.drools.mvel.compiler.Message)45 Test (org.junit.Test)42 KieSession (org.kie.api.runtime.KieSession)35 KieServices (org.kie.api.KieServices)22 KieBase (org.kie.api.KieBase)18 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)17 KieFileSystem (org.kie.api.builder.KieFileSystem)14 ReleaseId (org.kie.api.builder.ReleaseId)14 KieModule (org.kie.api.builder.KieModule)12 ArrayList (java.util.ArrayList)10 KieRuntimeLogger (org.kie.api.logger.KieRuntimeLogger)8 FactWithString (org.drools.mvel.integrationtests.facts.FactWithString)6 KieBuilder (org.kie.api.builder.KieBuilder)6 Resource (org.kie.api.io.Resource)6 KieContainer (org.kie.api.runtime.KieContainer)6 File (java.io.File)5 List (java.util.List)5 DynamicRulesTest (org.drools.mvel.integrationtests.DynamicRulesTest)4 KieModuleModel (org.kie.api.builder.model.KieModuleModel)4 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)2