use of org.kie.api.builder.KieFileSystem in project drools by kiegroup.
the class MessageImplTests method testMessageFromInvalidDSL.
@Test
public // See DROOLS-193 (KnowledgeBuilderResult does not always contain a Resource)
void testMessageFromInvalidDSL() throws Exception {
// Some suitably duff DSL
String dsl = "bananna\n";
// Some suitably valid DRL
String drl = "import org.drools.compiler.Person;\n" + "rule R1\n" + "when\n" + "There is a Person\n" + "then\n" + "end\n";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/dsl.dsl", dsl).write("src/main/resources/drl.dslr", drl);
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
Results results = kieBuilder.getResults();
assertEquals(3, results.getMessages().size());
}
use of org.kie.api.builder.KieFileSystem in project drools by kiegroup.
the class Misc2Test method testEvalInSubnetwork.
@Test
public void testEvalInSubnetwork() {
// DROOLS-460
String str = "global java.util.List list;\n" + "\n" + "declare StatusEvent\n" + "@role(event)\n" + "timestamp : int\n" + "end\n" + "\n" + "rule R when\n" + "$i : Integer()\n" + "eval(true)\n" + "exists(\n" + "Integer(intValue > $i.intValue)\n" + "and eval(true)\n" + ")\n" + "then\n" + "list.add($i.intValue());\n" + "end";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", str);
ks.newKieBuilder(kfs).buildAll();
KieSession ksession = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession();
List<Integer> list = new ArrayList<Integer>();
ksession.setGlobal("list", list);
ksession.insert(0);
ksession.fireAllRules();
ksession.insert(1);
ksession.fireAllRules();
assertEquals(1, list.size());
assertEquals(0, (int) list.get(0));
}
use of org.kie.api.builder.KieFileSystem in project drools by kiegroup.
the class CommonTestMethodBase method createJar.
public static byte[] createJar(KieServices ks, String kmoduleContent, Predicate<String> classFilter, ReleaseId releaseId, Resource... resources) {
KieFileSystem kfs = ks.newKieFileSystem().generateAndWritePomXML(releaseId).writeKModuleXML(kmoduleContent);
for (int i = 0; i < resources.length; i++) {
if (resources[i] != null) {
kfs.write(resources[i]);
}
}
KieBuilder kieBuilder = ks.newKieBuilder(kfs);
((InternalKieBuilder) kieBuilder).buildAll(classFilter);
Results results = kieBuilder.getResults();
if (results.hasMessages(Message.Level.ERROR)) {
throw new IllegalStateException(results.getMessages(Message.Level.ERROR).toString());
}
InternalKieModule kieModule = (InternalKieModule) ks.getRepository().getKieModule(releaseId);
byte[] jar = kieModule.getBytes();
return jar;
}
use of org.kie.api.builder.KieFileSystem in project drools by kiegroup.
the class KnowledgeBuilderTest method testMalformedDrl.
@Test
public void testMalformedDrl() throws Exception {
// DROOLS-928
byte[] content = new byte[] { 0x04, 0x44, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00 };
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", new String(content));
Results results = ks.newKieBuilder(kfs).buildAll().getResults();
assertTrue(results.getMessages().size() > 0);
}
use of org.kie.api.builder.KieFileSystem in project drools by kiegroup.
the class AbductionTest method testBindNonAbductiveQueryError.
@Test
public void testBindNonAbductiveQueryError() {
String droolsSource = "package org.drools.abductive.test; \n" + "" + "" + "query foo() \n" + "end \n" + "rule R1 " + "when " + " $x : foo( ) " + "then " + "end \n" + "";
// ///////////////////////////////////
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
kfs.write(ks.getResources().newByteArrayResource(droolsSource.getBytes()).setSourcePath("drl1.drl").setResourceType(ResourceType.DRL));
KieBuilder kieBuilder = ks.newKieBuilder(kfs);
kieBuilder.buildAll();
Results res = kieBuilder.getResults();
assertTrue(res.hasMessages(Message.Level.ERROR));
}
Aggregations