use of org.kie.api.builder.KieBuilder in project drools by kiegroup.
the class KieBuilderTest method testMultipleKBaseWithDrlError.
@Test
public void testMultipleKBaseWithDrlError() {
// RHBRMS-2651
final String drl = "package org.drools.compiler;\n" + "rule \"test\"\n" + " when\n" + " Smurf\n" + " then\n" + "end";
final KieServices ks = KieServices.Factory.get();
final KieModuleModel kproj = ks.newKieModuleModel();
kproj.newKieBaseModel("kbase1").newKieSessionModel("ksession1").setDefault(true);
kproj.newKieBaseModel("kbase2").newKieSessionModel("ksession2");
final ReleaseId releaseId = ks.newReleaseId("org.kie", "test-kie-builder", "1.0.0");
final KieFileSystem kfs = ks.newKieFileSystem().generateAndWritePomXML(releaseId).writeKModuleXML(kproj.toXML());
final Resource drlResource = ResourceFactory.newByteArrayResource(drl.getBytes()).setResourceType(ResourceType.DRL).setSourcePath("kbase1/drl1.drl");
kfs.write("src/main/resources/org/drools/compiler/drl1.drl", drlResource);
final KieBuilder kb = ks.newKieBuilder(kfs).buildAll();
final List<org.kie.api.builder.Message> messages = kb.getResults().getMessages(org.kie.api.builder.Message.Level.ERROR);
assertEquals(4, messages.size());
assertTrue(messages.get(0).toString().contains("kbase1"));
assertTrue(messages.get(1).toString().contains("kbase1"));
assertTrue(messages.get(2).toString().contains("kbase2"));
assertTrue(messages.get(3).toString().contains("kbase2"));
}
use of org.kie.api.builder.KieBuilder in project drools by kiegroup.
the class KieDefaultPackageTest method testModelInDefaultPackage2.
@Test
public void testModelInDefaultPackage2() throws Exception {
// This Model will be in the "default package"
String model_drl = "" + "declare Smurf\n" + "Field1 : String\n" + "end\n";
// This DRL is in a named package, but imports the model (trying with defaultPkg prefix)
String drl = "" + "package org.smurf\n" + "import defaultpkg.Smurf\n" + "rule \"test\"\n" + "when\n" + "Smurf()\n" + "then\n" + "end";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
kfs.write("src/main/resources/model.drl", model_drl);
kfs.write("src/main/resources/drl.drl", drl);
KieBuilder builder = ks.newKieBuilder(kfs).buildAll();
assertEquals(0, builder.getResults().getMessages().size());
}
use of org.kie.api.builder.KieBuilder in project drools by kiegroup.
the class KieHelloWorldTest method testImport.
@Test
public void testImport() throws Exception {
// DROOLS-859
String drl1 = "package org.drools.compiler.integrationtests\n" + "import " + Message.class.getCanonicalName() + "\n" + "global java.util.List list\n" + "rule R1 when\n" + " $m : Message( message == \"Hello World\" )\n" + "then\n" + " list.add(\"ok\");\n" + "end\n";
String drl2 = "package org.drools.compiler.integrationtests\n" + "import " + Message.class.getCanonicalName() + "\n" + "global java.util.List list\n" + "rule R2 when\n" + " $m : Message( message == \"Hi Universe\" )\n" + "then\n" + " list.add(\"ko\");\n" + "end\n";
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId = ks.newReleaseId("org.kie", "test-import", "1.0-SNAPSHOT");
KieModuleModel kproj = ks.newKieModuleModel();
kproj.newKieBaseModel("kbase").addPackage("rules").newKieSessionModel("ksession").setDefault(true);
KieFileSystem kfs = ks.newKieFileSystem().generateAndWritePomXML(releaseId).write("src/main/resources/rules/r1.drl", drl1).write("src/main/resources/myrules/r2.drl", drl2).writeKModuleXML(kproj.toXML());
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
KieSession ksession = ks.newKieContainer(releaseId).newKieSession();
List<String> results = new ArrayList<String>();
ksession.setGlobal("list", results);
ksession.insert(new Message("Hello World"));
ksession.insert(new Message("Hi Universe"));
ksession.fireAllRules();
assertEquals(1, results.size());
assertEquals("ok", results.get(0));
}
use of org.kie.api.builder.KieBuilder in project drools by kiegroup.
the class KieHelloWorldTest method testErrorReportingWithWrongKmodule.
@Test
public void testErrorReportingWithWrongKmodule() throws Exception {
// RHDM-69
String kmodule = "<kmodule xmlns=\"http://jboss.org/kie/6.0.0/kmodule\">\n" + " <kbase name=\"ABC\" default=\"false\" eventProcessingMode=\"stream\" equalsBehavior=\"identity\"/>\n" + " <kbase name=\"ABC\" default=\"false\" eventProcessingMode=\"stream\" equalsBehavior=\"identity\"/>\n" + "</kmodule>\n";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", createDrl("R1"));
kfs.writeKModuleXML(kmodule);
KieBuilder kb = ks.newKieBuilder(kfs).buildAll();
assertEquals(1, kb.getResults().getMessages().size());
assertTrue(kb.getResults().getMessages().get(0).toString().contains("ABC"));
}
use of org.kie.api.builder.KieBuilder in project drools by kiegroup.
the class KieLoggersTest method populateKieFileSystem.
private KieServices populateKieFileSystem(Resource dt) {
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem().write(dt);
KieBuilder kb = ks.newKieBuilder(kfs).buildAll();
assertTrue(kb.getResults().getMessages().isEmpty());
return ks;
}
Aggregations