use of org.drools.compiler.Message in project drools by kiegroup.
the class KnowledgeContextTest method testKnowledgeContext.
private void testKnowledgeContext(final String drlResourceName) {
final KieBase kbase = loadKnowledgeBase(drlResourceName);
final KieSession ksession = createKnowledgeSession(kbase);
final List<String> list = new ArrayList<String>();
ksession.setGlobal("list", list);
ksession.insert(new Message());
ksession.fireAllRules();
assertEquals(1, list.size());
assertEquals("Hello World", list.get(0));
}
use of org.drools.compiler.Message in project drools by kiegroup.
the class DynamicRuleLoadTest method updateToVersion.
public void updateToVersion() {
KieServices ks = KieServices.Factory.get();
// Create a new jar for version 1.1.0
ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.0");
KieModule km = createAndDeployJar(ks, releaseId2, drl1, drl2_2);
// try to update the container to version 1.1.0
kieContainer.updateToVersion(releaseId2);
// create and use a new session
ksession.insert(new Message("Hello World"));
}
use of org.drools.compiler.Message in project drools by kiegroup.
the class ConstraintsTest method testExpressionConstraints1.
@Test
public void testExpressionConstraints1() {
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" + " $folderType : getDefaultFolderType(),\n" + " FolderType.INBOX == $folderType,\n" + " $folderType == FolderType.INBOX,\n" + " $mailForFolder2 : getMailTypeForFolderType(getDefaultFolderType()),\n" + " FolderType.SENT != getDefaultFolderType(), \n" + " getDefaultFolderType() != FolderType.SENT, \n" + " getMailTypeForFolderType($folderType) == MailType.WORK,\n" + " 1 > 0\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);
}
use of org.drools.compiler.Message in project drools by kiegroup.
the class ConstraintsTest method testExpressionConstraints3.
@Test
public void testExpressionConstraints3() {
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" + " $type1 : FolderType.INBOX,\n" + " $type2 : org.drools.compiler.Mailbox$FolderType.INBOX,\n" + " $work1 : getFolder(null),\n" + " $work2 : getFolder(org.drools.compiler.Mailbox$FolderType.INBOX),\n" + " $work3 : getFolder(FolderType.INBOX),\n" + " getFolder($type1) != null,\n" + " getFolder($type1).size() > 0,\n" + " ! getFolder($type1).isEmpty(),\n" + " $work6 : folders,\n" + " $work7 : folders.size,\n" + " //folders.containsKey(FolderType.INBOX),\n" + " folders.containsKey(org.drools.compiler.Mailbox$FolderType.INBOX),\n" + " folders.containsKey($type2),\n" + " !folders.isEmpty,\n" + " getFolder(FolderType.INBOX) != null,\n" + " //$v1 : folders[FolderType.INBOX], \n" + " //$v2 : folders[com.sample.Mailbox.FolderType.INBOX],\n" + " //$v3 : folders[com.sample.Mailbox$FolderType.INBOX],\n" + " //folders[$type1]!=null,\n" + " //folders.get(FolderType.INBOX)!=null, // sun.reflect.generics.reflectiveObjects.ParameterizedTypeImpl cannot be cast to java.lang.Class\n" + " //folders.isEmpty(), // SAME ERROR\n" + " 0 < 1\n" + " )\n" + " then\n" + "end";
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);
}
use of org.drools.compiler.Message in project drools by kiegroup.
the class IncrementalCompilationTest method testIncrementalCompilationWithRemovedError.
@Test
public void testIncrementalCompilationWithRemovedError() throws Exception {
String drl1 = "package org.drools.compiler\n" + "rule R1 when\n" + " $m : Message()\n" + "then\n" + "end\n";
String drl2_1 = "package org.drools.compiler\n" + "rule R2_1 when\n" + " $m : Message( nonExistentField == \"Hello World\" )\n" + "then\n" + "end\n";
String drl2_2 = "package org.drools.compiler\n" + "rule R2_2 when\n" + " $m : Message( message == \"Hello World\" )\n" + "then\n" + "end\n";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", drl1).write("src/main/resources/r2.drl", drl2_1);
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
assertEquals(1, kieBuilder.getResults().getMessages(org.kie.api.builder.Message.Level.ERROR).size());
kfs.write("src/main/resources/r2.drl", drl2_2);
IncrementalResults results = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/r2.drl").build();
assertEquals(0, results.getAddedMessages().size());
assertEquals(1, results.getRemovedMessages().size());
KieContainer kieContainer = ks.newKieContainer(ks.getRepository().getDefaultReleaseId());
KieSession ksession = kieContainer.newKieSession();
ksession.insert(new Message("Hello World"));
assertEquals(2, ksession.fireAllRules());
}
Aggregations