use of org.kie.api.KieServices in project drools by kiegroup.
the class OOPathCastTest method testInvalidCast.
@Test
public void testInvalidCast() {
final String drl = "import org.drools.compiler.oopath.model.*;\n" + "global java.util.List list\n" + "\n" + "rule R when\n" + " Man( $toy: /wife/children#Man/toys )\n" + "then\n" + " list.add( $toy.getName() );\n" + "end\n";
final KieServices ks = KieServices.Factory.get();
final KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", drl);
final Results results = ks.newKieBuilder(kfs).buildAll().getResults();
assertTrue(results.hasMessages(Message.Level.ERROR));
}
use of org.kie.api.KieServices in project drools by kiegroup.
the class GetKieContainerCommand method execute.
public KieContainer execute(Context context) {
// use the new API to retrieve the session by ID
KieServices kieServices = KieServices.Factory.get();
KieContainer kieContainer = kieServices.newKieContainer(releaseId);
((RegistryContext) context).register(KieContainer.class, kieContainer);
return kieContainer;
}
use of org.kie.api.KieServices in project drools by kiegroup.
the class Misc2Test method testNonSerializableInEvaluatorWrapper.
@Test
public void testNonSerializableInEvaluatorWrapper() throws Exception {
// BZ-1315143
String str = "package org.drools.compiler\n" + "rule B\n" + " when\n" + " $m1 : Message( $message1 : message, $date1 : birthday )\n" + " $m2 : Message( this != $m1, message != $message1, birthday after $date1 )\n" + " then\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());
KieSession ksession1 = ks.newKieContainer(kbuilder.getKieModule().getReleaseId()).newKieSession();
Message message1 = new Message();
message1.setMessage("Hello World");
message1.setBirthday(new SimpleDateFormat("yyyy-MM-dd").parse("2015-12-15"));
Message message2 = new Message();
message2.setMessage("Goodbye World");
message2.setBirthday(new SimpleDateFormat("yyyy-MM-dd").parse("2015-12-16"));
ksession1.insert(message1);
ksession1.insert(message2);
int fired1 = ksession1.fireAllRules();
assertEquals(1, fired1);
ksession1.dispose();
// Force deepClone
KieSession ksession2 = ks.newKieContainer(kbuilder.getKieModule().getReleaseId()).newKieSession();
Message message3 = new Message();
message3.setMessage("Hello World");
message3.setBirthday(new SimpleDateFormat("yyyy-MM-dd").parse("2015-12-15"));
Message message4 = new Message();
message4.setMessage("Goodbye World");
message4.setBirthday(new SimpleDateFormat("yyyy-MM-dd").parse("2015-12-16"));
ksession2.insert(message3);
ksession2.insert(message4);
int fired2 = ksession2.fireAllRules();
assertEquals(1, fired2);
ksession2.dispose();
}
use of org.kie.api.KieServices in project drools by kiegroup.
the class Misc2Test method testAutomaticallySwitchFromReteOOToPhreak.
@Test
public void testAutomaticallySwitchFromReteOOToPhreak() {
String str = "rule R when then end\n";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
kfs.write("src/main/resources/rule.drl", str);
KieBuilder kbuilder = ks.newKieBuilder(kfs);
kbuilder.buildAll();
assertEquals(0, kbuilder.getResults().getMessages().size());
KieBase kbase = ks.newKieContainer(kbuilder.getKieModule().getReleaseId()).getKieBase();
KieSession ksession = kbase.newKieSession();
ksession.fireAllRules();
}
use of org.kie.api.KieServices in project drools by kiegroup.
the class Misc2Test method testExtendingDate.
@Test
public void testExtendingDate() {
// BZ-1072629
String str = "import " + MyDate.class.getCanonicalName() + " \n" + "rule 'sample rule' \n" + "when \n" + " $date: MyDate() \n" + "then \n" + "$date.setDescription(\"test\"); \n" + "end \n";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", str);
Results results = ks.newKieBuilder(kfs).buildAll().getResults();
assertEquals(0, results.getMessages().size());
}
Aggregations