use of org.drools.mvel.compiler.Message in project drools by kiegroup.
the class Misc2Test method testPackagingJarWithTypeDeclarations.
@Test
public void testPackagingJarWithTypeDeclarations() throws Exception {
// BZ-1054823
String drl1 = "package org.drools.compiler\n" + "import org.drools.compiler.Message\n" + "declare Message\n" + " @role (event)\n" + "end\n" + "rule R1 when\n" + " $m : Message()\n" + "then\n" + "end\n";
KieServices ks = KieServices.Factory.get();
// Create an in-memory jar for version 1.0.0
ReleaseId releaseId = ks.newReleaseId("org.kie", "test-upgrade", "1.0.0");
KieModule km = KieUtil.getKieModuleFromDrls(releaseId, kieBaseTestConfiguration, drl1);
// Create a session and fire rules
KieContainer kc = ks.newKieContainer(km.getReleaseId());
KieSession ksession = kc.newKieSession();
ksession.insert(new Message("Hello World"));
ksession.fireAllRules();
}
use of org.drools.mvel.compiler.Message in project drools by kiegroup.
the class Misc2Test method testInsertModifyInteractionsWithLockOnActive.
@Test
public void testInsertModifyInteractionsWithLockOnActive() {
String drl = "package org.drools.mvel.integrationtests;\n" + "import org.drools.mvel.compiler.Message;\n" + "global Message m2;\n" + "rule r1 lock-on-active\n" + " when\n" + " m: Message()\n" + " then\n" + " modify( m ){ setMessage2( 'msg2' ) };\n" + " m2 = new Message( 'msg1' );\n" + " kcontext.getKnowledgeRuntime().setGlobal( 'm2', m2 ); \n" + " insert( m2 );\n" + "end\n" + "rule r2 lock-on-active salience 1000\n" + " when\n" + " m : Message()\n" + " then\n" + " modify( m ){ setMessage3( 'msg3' ) };\n" + "end\n";
KieBase kbase = KieBaseUtil.getKieBaseFromKieModuleFromDrl("test", kieBaseTestConfiguration, drl);
KieSession ksession = kbase.newKieSession();
Message m1 = new Message("msg1");
ksession.insert(m1);
assertEquals(2, ksession.fireAllRules());
Message m2 = (Message) ksession.getGlobal("m2");
assertEquals("msg1", m1.getMessage());
assertEquals("msg2", m1.getMessage2());
assertEquals("msg3", m1.getMessage3());
assertEquals("msg1", m2.getMessage());
// r1 does not fire for m2
assertEquals("Two", m2.getMessage2());
assertEquals("Three", m2.getMessage3());
}
use of org.drools.mvel.compiler.Message in project drools by kiegroup.
the class JBRULESTest method testJBRULES3326.
@Test
public void testJBRULES3326() 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(!!!false)\n");
rule.append("then\n");
rule.append("end\n");
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();
}
use of org.drools.mvel.compiler.Message in project drools by kiegroup.
the class KieCompilationCacheTest method testHelloWorldWithPackagesAnd2KieBases.
@Test
public void testHelloWorldWithPackagesAnd2KieBases() throws Exception {
String drl1 = "package org.pkg1\n" + "import " + Message.class.getCanonicalName() + "\n" + "rule R11 when\n" + " $m : Message( message == \"Hello World\" )\n" + "then\n" + "end\n" + "rule R12 when\n" + " $m : Message( message == \"Hi Universe\" )\n" + "then\n" + "end\n";
String drl2 = "package org.pkg2\n" + "import " + Message.class.getCanonicalName() + "\n" + "rule R21 when\n" + " $m : Message( message == \"Hello World\" )\n" + "then\n" + "end\n" + "rule R22 when\n" + " $m : Message( message == \"Aloha Earth\" )\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.drl", drl1).write("src/main/resources/KBase1/org/pkg2/r2.drl", drl2).writeKModuleXML(createKieProjectWithPackagesAnd2KieBases(ks).toXML());
final KieBuilder kieBuilder = KieUtil.getKieBuilderFromKieFileSystem(kieBaseTestConfiguration, kfs, false);
InternalKieModule kieModule = (InternalKieModule) ks.getRepository().getKieModule(releaseId);
byte[] jar = kieModule.getBytes();
MemoryFileSystem mfs = MemoryFileSystem.readFromJar(jar);
File file = mfs.getFile(KieBuilderImpl.getCompilationCachePath(releaseId, "KBase1"));
assertNotNull(file);
file = mfs.getFile(KieBuilderImpl.getCompilationCachePath(releaseId, "KBase2"));
assertNotNull(file);
Resource jarRes = ks.getResources().newByteArrayResource(jar);
KieModule km = ks.getRepository().addKieModule(jarRes);
KieSession ksession = ks.newKieContainer(km.getReleaseId()).newKieSession("KSession1");
ksession.insert(new Message("Hello World"));
assertEquals(1, ksession.fireAllRules());
ksession = ks.newKieContainer(km.getReleaseId()).newKieSession("KSession1");
ksession.insert(new Message("Hi Universe"));
assertEquals(1, ksession.fireAllRules());
ksession = ks.newKieContainer(km.getReleaseId()).newKieSession("KSession1");
ksession.insert(new Message("Aloha Earth"));
assertEquals(0, ksession.fireAllRules());
ksession = ks.newKieContainer(km.getReleaseId()).newKieSession("KSession2");
ksession.insert(new Message("Hello World"));
assertEquals(1, ksession.fireAllRules());
ksession = ks.newKieContainer(km.getReleaseId()).newKieSession("KSession2");
ksession.insert(new Message("Hi Universe"));
assertEquals(0, ksession.fireAllRules());
ksession = ks.newKieContainer(km.getReleaseId()).newKieSession("KSession2");
ksession.insert(new Message("Aloha Earth"));
assertEquals(1, ksession.fireAllRules());
}
use of org.drools.mvel.compiler.Message in project drools by kiegroup.
the class KieHelloWorldTest method testHelloWorldWithPackages.
@Test
public void testHelloWorldWithPackages() 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/KBase1/org/pkg1/r1.drl", createDrl("org.pkg1", "R1")).write("src/main/resources/KBase1/org/pkg2/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"));
int count = ksession.fireAllRules();
assertEquals(1, count);
}
Aggregations