Search in sources :

Example 6 with Message

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

the class KieHelloWorldTest method testHelloWorldUsingPackages.

@Test
public void testHelloWorldUsingPackages() throws Exception {
    String drlDef = "package org.pkg1\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");
    KieFileSystem kfs = ks.newKieFileSystem().generateAndWritePomXML(releaseId).write("src/main/resources/KBase1/r1_1.drl", drlDef).write("src/main/resources/KBase1/r1_2.drl", createDrl("org.pkg1", "R1")).write("src/main/resources/KBase1/r2.drl", createDrl("org.pkg2", "R2")).writeKModuleXML(createKieProjectWithPackages(ks, "org.pkg1").toXML());
    KieUtil.getKieBuilderFromKieFileSystem(kieBaseTestConfiguration, kfs, false);
    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.mvel.compiler.Message) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) ReleaseId(org.kie.api.builder.ReleaseId) Test(org.junit.Test)

Example 7 with Message

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

the class KieHelloWorldTest method testHelloWorld.

@Test
public void testHelloWorld() throws Exception {
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", createDrl("R1"));
    KieUtil.getKieBuilderFromKieFileSystem(kieBaseTestConfiguration, kfs, false);
    KieSession ksession = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession();
    ksession.insert(new Message("Hello World"));
    int count = ksession.fireAllRules();
    assertEquals(1, count);
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Message(org.drools.mvel.compiler.Message) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Example 8 with Message

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

the class KieHelloWorldTest method testHelloWorldWithEmptyFile.

@Test
public void testHelloWorldWithEmptyFile() throws Exception {
    String drl = createDrl("R1");
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", drl).write("src/main/resources/empty.drl", ks.getResources().newInputStreamResource(new ByteArrayInputStream(new byte[0])));
    KieUtil.getKieBuilderFromKieFileSystem(kieBaseTestConfiguration, kfs, false);
    KieSession ksession = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession();
    ksession.insert(new Message("Hello World"));
    int count = ksession.fireAllRules();
    assertEquals(1, count);
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Message(org.drools.mvel.compiler.Message) ByteArrayInputStream(java.io.ByteArrayInputStream) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) Test(org.junit.Test)

Example 9 with Message

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

the class KieHelloWorldTest method testHelloWorldUsingFolders.

@Test
public void testHelloWorldUsingFolders() throws Exception {
    String drlDef = "package org.drools.mvel.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");
    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").setConfigurationProperty("drools.groupDRLsInKieBasesByFolder", "true").toXML());
    KieUtil.getKieBuilderFromKieFileSystem(kieBaseTestConfiguration, kfs, false);
    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.mvel.compiler.Message) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) ReleaseId(org.kie.api.builder.ReleaseId) Test(org.junit.Test)

Example 10 with Message

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

the class KieHelloWorldTest method testHelloWorldWithWildcardPackages.

@Test
public void testHelloWorldWithWildcardPackages() throws Exception {
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId("org.kie", "hello-world", "1.0");
    KieFileSystem kfs = ks.newKieFileSystem().generateAndWritePomXML(releaseId).write("src/main/resources/org/pkg1/test/r1.drl", createDrlWithGlobal("org.pkg1.test", "R1")).write("src/main/resources/org/pkg2/test/r2.drl", createDrlWithGlobal("org.pkg2.test", "R2")).writeKModuleXML(createKieProjectWithPackages(ks, "org.pkg1.*").toXML());
    KieUtil.getKieBuilderFromKieFileSystem(kieBaseTestConfiguration, kfs, false);
    KieSession ksession = ks.newKieContainer(releaseId).newKieSession("KSession1");
    ksession.insert(new Message("Hello World"));
    List<String> list = new ArrayList<String>();
    ksession.setGlobal("list", list);
    assertEquals(1, ksession.fireAllRules());
    assertEquals(1, list.size());
    assertEquals("R1", list.get(0));
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Message(org.drools.mvel.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)

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