Search in sources :

Example 21 with Message

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

the class KieHelloWorldTest method testHelloWorldWithWildcardPackagesComplex.

@Test
public void testHelloWorldWithWildcardPackagesComplex() throws Exception {
    // BZ-1174563
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId("org.kie", "hello-world", "1.0-SNAPSHOT");
    KieFileSystem kfs = ks.newKieFileSystem().generateAndWritePomXML(releaseId).write("src/main/resources/rules/rules.drl", createDrlWithGlobal("R1")).write("src/main/resources/rules/tests/tests.drl", createDrlWithGlobal("R2")).write("src/main/resources/aaarules/aaarules.drl", createDrlWithGlobal("R3")).write("src/main/resources/sample/brms601_1310778/rules/rules.drl", createDrlWithGlobal("R4")).write("src/main/resources/sample/brms601_1310778/tests/tests.drl", createDrlWithGlobal("R5")).write("src/main/resources/tests/tests.drl", createDrlWithGlobal("R6")).write("src/main/resources/rules2/rules2.drl", createDrlWithGlobal("R7")).writeKModuleXML(createKieProjectWithPackages(ks, "rules.*").toXML());
    ks.newKieBuilder(kfs).buildAll();
    KieSession ksession = ks.newKieContainer(releaseId).newKieSession("KSession1");
    ksession.insert(new Message("Hello World"));
    List<String> list = new ArrayList<String>();
    ksession.setGlobal("list", list);
    assertEquals(2, ksession.fireAllRules());
    assertTrue(list.contains("R1"));
    assertTrue(list.contains("R2"));
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Message(org.drools.compiler.Message) ArrayList(java.util.ArrayList) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) ReleaseId(org.kie.api.builder.ReleaseId) Test(org.junit.Test)

Example 22 with Message

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

the class KieHelloWorldTest method testHelloWorldUsingPackages.

@Test
public void testHelloWorldUsingPackages() throws Exception {
    String drlDef = "package org.drools.compiler.integrationtests\n" + "import " + Message.class.getCanonicalName() + "\n" + "rule R_def when\n" + "   $m : Message( message == \"Hello World\" )\n" + "then\n" + "end\n";
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId("org.kie", "hello-world", "1.0-SNAPSHOT");
    KieFileSystem kfs = ks.newKieFileSystem().generateAndWritePomXML(releaseId).write("src/main/resources/KBase1/org/pkg1/r1_1.drl", drlDef).write("src/main/resources/KBase1/org/pkg1/r1_2.drl", createDrl("R1")).write("src/main/resources/KBase1/org/pkg2/r2.drl", createDrl("R2")).writeKModuleXML(createKieProjectWithPackages(ks, "org.pkg1").toXML());
    ks.newKieBuilder(kfs).buildAll();
    KieSession ksession = ks.newKieContainer(releaseId).newKieSession("KSession1");
    ksession.insert(new Message("Hello World"));
    assertEquals(2, ksession.fireAllRules());
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Message(org.drools.compiler.Message) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) ReleaseId(org.kie.api.builder.ReleaseId) Test(org.junit.Test)

Example 23 with Message

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

the class KieLoggersTest method testKieConsoleLogger.

@Test
public void testKieConsoleLogger() throws Exception {
    String drl = "package org.drools.integrationtests\n" + "import org.drools.compiler.Message;\n" + "rule \"Hello World\"\n" + "    when\n" + "        m : Message( myMessage : message )\n" + "    then\n" + "end";
    // get the resource
    Resource dt = ResourceFactory.newByteArrayResource(drl.getBytes()).setTargetPath("org/drools/integrationtests/hello.drl");
    // create the builder
    KieSession ksession = getKieSession(dt);
    KieRuntimeLogger logger = KieServices.Factory.get().getLoggers().newConsoleLogger(ksession);
    ksession.insert(new Message("Hello World"));
    int fired = ksession.fireAllRules();
    assertEquals(1, fired);
    logger.close();
}
Also used : KieRuntimeLogger(org.kie.api.logger.KieRuntimeLogger) Message(org.drools.compiler.Message) Resource(org.kie.api.io.Resource) StatelessKieSession(org.kie.api.runtime.StatelessKieSession) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Example 24 with Message

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

the class KieLoggersTest method testKieFileLogger.

@Test
public void testKieFileLogger() throws Exception {
    String drl = "package org.drools.integrationtests\n" + "import org.drools.compiler.Message;\n" + "rule \"Hello World\"\n" + "    when\n" + "        m : Message( myMessage : message )\n" + "    then\n" + "end";
    // get the resource
    Resource dt = ResourceFactory.newByteArrayResource(drl.getBytes()).setTargetPath("org/drools/integrationtests/hello.drl");
    // create the builder
    KieSession ksession = getKieSession(dt);
    String fileName = "target/testKieFileLogger";
    File file = new File(fileName + ".log");
    if (file.exists()) {
        file.delete();
    }
    KieRuntimeLogger logger = KieServices.Factory.get().getLoggers().newFileLogger(ksession, fileName);
    ksession.insert(new Message("Hello World"));
    int fired = ksession.fireAllRules();
    assertEquals(1, fired);
    logger.close();
    file = new File(fileName + ".log");
    assertTrue(file.exists());
    assertTrue(file.length() > 0);
    file.delete();
}
Also used : KieRuntimeLogger(org.kie.api.logger.KieRuntimeLogger) Message(org.drools.compiler.Message) Resource(org.kie.api.io.Resource) StatelessKieSession(org.kie.api.runtime.StatelessKieSession) KieSession(org.kie.api.runtime.KieSession) File(java.io.File) Test(org.junit.Test)

Example 25 with Message

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

the class ExecutionFlowControlTest method testDateEffective.

@Test
public void testDateEffective() throws Exception {
    // read in the source
    KieBase kbase = loadKnowledgeBase("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.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)

Aggregations

Message (org.drools.compiler.Message)68 Test (org.junit.Test)65 KieSession (org.kie.api.runtime.KieSession)59 KieServices (org.kie.api.KieServices)41 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)36 ReleaseId (org.kie.api.builder.ReleaseId)30 KieContainer (org.kie.api.runtime.KieContainer)25 KieModule (org.kie.api.builder.KieModule)24 KieBase (org.kie.api.KieBase)20 KieFileSystem (org.kie.api.builder.KieFileSystem)19 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)18 ArrayList (java.util.ArrayList)14 KieRuntimeLogger (org.kie.api.logger.KieRuntimeLogger)8 List (java.util.List)7 KieBuilder (org.kie.api.builder.KieBuilder)6 Resource (org.kie.api.io.Resource)6 File (java.io.File)5 DynamicRulesTest (org.drools.compiler.integrationtests.DynamicRulesTest)4 KieModuleModel (org.kie.api.builder.model.KieModuleModel)4 AfterMatchFiredEvent (org.kie.api.event.rule.AfterMatchFiredEvent)4