use of org.kie.api.builder.KieBuilder 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.KieBuilder 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.KieBuilder 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));
}
use of org.kie.api.builder.KieBuilder in project drools by kiegroup.
the class KieBuilderTest method testNotExistingInclude.
@Test
public void testNotExistingInclude() throws Exception {
String drl = "package org.drools.compiler.integrationtests\n" + "declare CancelFact\n" + " cancel : boolean = true\n" + "end\n" + "rule R1 when\n" + " $m : CancelFact( cancel == true )\n" + "then\n" + "end\n";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", drl);
KieModuleModel module = ks.newKieModuleModel();
final String defaultBaseName = "defaultKBase";
KieBaseModel defaultBase = module.newKieBaseModel(defaultBaseName).addInclude("notExistingKB1").addInclude("notExistingKB2");
defaultBase.setDefault(true);
defaultBase.addPackage("*");
defaultBase.newKieSessionModel("defaultKSession").setDefault(true);
kfs.writeKModuleXML(module.toXML());
KieBuilder kb = ks.newKieBuilder(kfs).buildAll();
assertEquals(2, kb.getResults().getMessages().size());
}
use of org.kie.api.builder.KieBuilder in project drools by kiegroup.
the class KieBuilderTest method testInvalidProjectXml.
@Test
public void testInvalidProjectXml() throws ClassNotFoundException, InterruptedException, IOException {
String namespace = "org.kie.test";
KieModuleModel kProj = createKieProject(namespace);
ReleaseId releaseId = KieServices.Factory.get().newReleaseId(namespace, "memory", "1.0-SNAPSHOT");
KieFileSystem kfs = KieServices.Factory.get().newKieFileSystem();
generatePomXML(kfs, releaseId);
kfs.writeKModuleXML("xxxx");
generateMessageClass(kfs, namespace);
generateRule(kfs, namespace);
KieBuilder kieBuilder = createKieBuilder(kfs);
kieBuilder.buildAll();
assertTrue(kieBuilder.getResults().hasMessages(Level.ERROR));
}
Aggregations