use of org.drools.compiler.Message in project drools by kiegroup.
the class HelloWorldTest method testHelloWorld.
@Test
public void testHelloWorld() throws Exception {
// load up the knowledge base
KieBase kbase = readKnowledgeBase();
KieSession ksession = createKnowledgeSession(kbase);
File testTmpDir = new File("target/test-tmp/");
testTmpDir.mkdirs();
KieRuntimeLogger logger = KnowledgeRuntimeLoggerFactory.newFileLogger(ksession, "target/test-tmp/testHelloWorld");
ksession.getAgendaEventListeners().size();
// go !
Message message = new Message();
message.setMessage("Hello World");
message.setStatus(Message.HELLO);
ksession.insert(message);
ksession.fireAllRules();
logger.close();
}
use of org.drools.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");
byte[] jar = createKJar(ks, releaseId, null, drl1);
KieModule km = deployJar(ks, jar);
// 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.compiler.Message in project drools by kiegroup.
the class Misc2Test method testNPEOnMutableGlobal.
@Test
public void testNPEOnMutableGlobal() throws Exception {
// BZ-1019473
String str = "package org.drools.compiler\n" + "global java.util.List context\n" + "rule B\n" + " when\n" + " Message( message == \"b\" )\n" + " $s : String() from context\n" + " then\n" + " System.out.println($s);\n" + "end";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
kfs.write(ResourceFactory.newByteArrayResource(str.getBytes()).setTargetPath("org/drools/compiler/rules.drl"));
KieBuilder kbuilder = KieServices.Factory.get().newKieBuilder(kfs);
kbuilder.buildAll();
assertEquals(0, kbuilder.getResults().getMessages().size());
ks.newKieContainer(kbuilder.getKieModule().getReleaseId()).getKieBase();
KieSession ksession = ks.newKieContainer(kbuilder.getKieModule().getReleaseId()).newKieSession();
assertNotNull(ksession);
List<String> context = new ArrayList<String>();
ksession.setGlobal("context", context);
FactHandle b = ksession.insert(new Message("b"));
ksession.delete(b);
int fired = ksession.fireAllRules(1);
assertEquals(0, fired);
ksession.dispose();
}
use of org.drools.compiler.Message in project drools by kiegroup.
the class DynamicRuleLoadTest method testKJarUpgrade.
@Test
public void testKJarUpgrade() throws Exception {
// DROOLS-919
KieServices ks = KieServices.Factory.get();
// Create an in-memory jar for version 1.0.0
ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-upgrade", "1.0.0");
KieModule km = createAndDeployJar(ks, releaseId1, drl1, drl2_1);
// Create a session and fire rules
kieContainer = ks.newKieContainer(km.getReleaseId());
ksession = kieContainer.newKieSession();
ksession.setGlobal("test", this);
ksession.insert(new Message("Hi Universe"));
ksession.fireAllRules();
assertTrue(done);
}
use of org.drools.compiler.Message in project drools by kiegroup.
the class ConstraintsTest method testExpressionConstraints2.
@Test
public void testExpressionConstraints2() {
final String drl = "package org.drools.compiler.integrationtests\n" + "import " + Mailbox.FolderType.class.getCanonicalName() + ";\n" + "import " + Mailbox.class.getCanonicalName() + ";\n" + "rule R1\n" + " dialect \"mvel\"\n" + " when\n" + " $m : Mailbox( \n" + " $me : owneremail,\n" + " recentContacts[Mailbox.TEST_EMAIL] != null,\n" + " recentContacts[\"me@test.com\"] != null,\n" + " $d1 : recentContacts[Mailbox.TEST_EMAIL],\n" + " $d2 : recentContacts[\"me@test.com\"],\n" + " recentContacts.get(owneremail) != null,\n" + " recentContacts.get($me) != null,\n" + " recentContacts[$me] != null,\n" + " $d3: recentContacts.get(owneremail),\n" + " // Waiting for MVEL fixes for the following 2 scenarios" + " // recentContacts[owneremail] != null,\n" + " // recentContacts[getOwneremail()] != null,\n" + " 0 < 1\n" + " )\n" + " then\n" + "end\n";
final KieBase kbase = loadKnowledgeBaseFromString(drl);
final KieSession ksession = createKnowledgeSession(kbase);
final Mailbox mbox = new Mailbox(Mailbox.TEST_EMAIL);
final Message message = new Message();
message.setMessage("Welcome");
message.setStatus(Message.HELLO);
mbox.getFolder(FolderType.INBOX).add(message);
ksession.insert(mbox);
ksession.insert(message);
final int rules = ksession.fireAllRules();
assertEquals(1, rules);
}
Aggregations