Search in sources :

Example 41 with Message

use of org.drools.mvel.compiler.Message in project drools by kiegroup.

the class SequentialTest method testKnowledgeRuntimeAccess.

@Test
public void testKnowledgeRuntimeAccess() throws Exception {
    String str = "";
    str += "package org.drools.mvel.compiler.test\n";
    str += "import org.drools.mvel.compiler.Message\n";
    str += "rule \"Hello World\"\n";
    str += "when\n";
    str += "    Message( )\n";
    str += "then\n";
    str += "    System.out.println( drools.getKieRuntime() );\n";
    str += "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(new Message("help"));
}
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 42 with Message

use of org.drools.mvel.compiler.Message in project drools by kiegroup.

the class StatefulSessionTest method testDispose.

@Test
public void testDispose() throws Exception {
    final StringBuilder rule = new StringBuilder();
    rule.append("package org.drools.mvel.compiler\n");
    rule.append("rule X\n");
    rule.append("when\n");
    rule.append("    Message()\n");
    rule.append("then\n");
    rule.append("end\n");
    // building stuff
    KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, rule.toString());
    KieSession ksession = kbase.newKieSession();
    ksession.insert(new Message("test"));
    final int rules = ksession.fireAllRules();
    assertEquals(1, rules);
    ksession.dispose();
    try {
        // the following should raise an IllegalStateException as the session was already disposed
        ksession.fireAllRules();
        fail("An IllegallStateException should have been raised as the session was disposed before the method call.");
    } catch (final IllegalStateException ise) {
    // success
    }
}
Also used : Message(org.drools.mvel.compiler.Message) KieBase(org.kie.api.KieBase) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Example 43 with Message

use of org.drools.mvel.compiler.Message in project drools by kiegroup.

the class ExecutionFlowControlTest method testDateEffective.

@Test
public void testDateEffective() throws Exception {
    // read in the source
    KieBase kbase = KieBaseUtil.getKieBaseFromClasspathResources(this.getClass(), kieBaseTestConfiguration, "test_EffectiveDate.drl");
    KieSession ksession = kbase.newKieSession();
    final List list = new ArrayList();
    ksession.setGlobal("list", list);
    // go !
    final Message message = new Message("hola");
    ksession.insert(message);
    ksession.fireAllRules();
    assertFalse(message.isFired());
}
Also used : Message(org.drools.mvel.compiler.Message) KieBase(org.kie.api.KieBase) ArrayList(java.util.ArrayList) KieSession(org.kie.api.runtime.KieSession) ArrayList(java.util.ArrayList) List(java.util.List) Test(org.junit.Test)

Example 44 with Message

use of org.drools.mvel.compiler.Message in project drools by kiegroup.

the class FirstOrderLogicTest method testOrs.

@Test
public void testOrs() throws Exception {
    String str = "package org.drools.mvel.integrationtests\n" + "import " + Message.class.getName() + "\n" + "rule X\n" + "    when\n" + "        Message( message == 'test' )\n" + "        Message( !fired ) or eval( !false )\n" + "    then\n" + "end\n";
    KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, str);
    KieSession ksession = kbase.newKieSession();
    ksession.insert(new Message("test"));
    int rules = ksession.fireAllRules();
    assertEquals(2, rules);
    ksession.dispose();
}
Also used : Message(org.drools.mvel.compiler.Message) KieBase(org.kie.api.KieBase) KieSession(org.kie.api.runtime.KieSession) SpecialString(org.drools.mvel.compiler.SpecialString) Test(org.junit.Test)

Example 45 with Message

use of org.drools.mvel.compiler.Message in project drools by kiegroup.

the class SerializedPackageMergeTest method getObject.

private Message getObject() throws ParseException {
    Message message = new Message();
    message.setMessage("hola");
    message.setNumber(50);
    message.getList().add("hello");
    message.setBirthday(DF.parse("10-Jul-1976"));
    return message;
}
Also used : Message(org.drools.mvel.compiler.Message)

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