use of org.kie.api.builder.KieBuilder in project drools by kiegroup.
the class WireChannelTest method build.
private void build(KieServices ks, ReleaseId releaseId) throws IOException {
KieModuleModel kproj = ks.newKieModuleModel();
KieSessionModel ksession1 = kproj.newKieBaseModel("KBase1").newKieSessionModel("KSession1").setDefault(true);
ksession1.newChannelModel("testChannel", RecordingChannel.class.getName());
KieFileSystem kfs = ks.newKieFileSystem();
kfs.writeKModuleXML(kproj.toXML()).writePomXML(generatePomXml(releaseId)).write("src/main/resources/KBase1/rules.drl", createDRL());
KieBuilder kieBuilder = ks.newKieBuilder(kfs);
assertTrue(kieBuilder.buildAll().getResults().getMessages().isEmpty());
}
use of org.kie.api.builder.KieBuilder in project drools by kiegroup.
the class AbstractKnowledgeTest method createKieModule.
public KieModuleModel createKieModule(String namespace, boolean createJar, String version) throws IOException, ClassNotFoundException, InterruptedException {
KieModuleModel kproj = new KieModuleModelImpl();
KieBaseModel kieBaseModel1 = kproj.newKieBaseModel(namespace + ".KBase1").setEqualsBehavior(EqualityBehaviorOption.EQUALITY).setEventProcessingMode(EventProcessingOption.STREAM).addPackage(namespace + ".KBase1").setDefault(true);
kieBaseModel1.newKieSessionModel(namespace + ".KSession1").setType(KieSessionType.STATELESS).setClockType(ClockTypeOption.get("realtime")).setDefault(true);
kieBaseModel1.newKieSessionModel(namespace + ".KSession2").setType(KieSessionType.STATEFUL).setClockType(ClockTypeOption.get("pseudo"));
kieBaseModel1.newKieSessionModel(namespace + ".KSessionDefault").setType(KieSessionType.STATEFUL).setClockType(ClockTypeOption.get("pseudo")).setDefault(true);
KieBaseModel kieBaseModel2 = kproj.newKieBaseModel(namespace + ".KBase2").setEqualsBehavior(EqualityBehaviorOption.IDENTITY).addPackage(namespace + ".KBase2").setEventProcessingMode(EventProcessingOption.CLOUD);
kieBaseModel2.newKieSessionModel(namespace + ".KSession3").setType(KieSessionType.STATEFUL).setClockType(ClockTypeOption.get("pseudo"));
KieBaseModel kieBaseModel3 = kproj.newKieBaseModel(namespace + ".KBase3").addInclude(kieBaseModel1.getName()).addInclude(kieBaseModel2.getName()).setEqualsBehavior(EqualityBehaviorOption.IDENTITY).setEventProcessingMode(EventProcessingOption.CLOUD);
kieBaseModel3.newKieSessionModel(namespace + ".KSession4").setType(KieSessionType.STATELESS).setClockType(ClockTypeOption.get("pseudo"));
KieServices ks = KieServices.Factory.get();
KieFileSystemImpl kfs = (KieFileSystemImpl) ks.newKieFileSystem();
kfs.write("src/main/resources/META-INF/beans.xml", generateBeansXML());
kfs.writeKModuleXML(((KieModuleModelImpl) kproj).toXML());
ReleaseId releaseId = ks.newReleaseId(namespace, "art1", version);
kfs.generateAndWritePomXML(releaseId);
String kBase1R1 = getRule(namespace + ".test1", "rule1", version);
String kBase1R2 = getRule(namespace + ".test1", "rule2", version);
String kbase2R1 = getRule(namespace + ".test2", "rule1", version);
String kbase2R2 = getRule(namespace + ".test2", "rule2", version);
String fldKB1 = "src/main/resources/" + kieBaseModel1.getName().replace('.', '/');
String fldKB2 = "src/main/resources/" + kieBaseModel2.getName().replace('.', '/');
kfs.write(fldKB1 + "/rule1.drl", kBase1R1.getBytes());
kfs.write(fldKB1 + "/rule2.drl", kBase1R2.getBytes());
kfs.write(fldKB2 + "/rule1.drl", kbase2R1.getBytes());
kfs.write(fldKB2 + "/rule2.drl", kbase2R2.getBytes());
kfs.write("src/main/java/org/drools/compiler/cdi/test/KProjectTestClass" + namespace + ".java", generateKProjectTestClass(kproj, namespace));
KieBuilder kBuilder = ks.newKieBuilder(kfs);
kBuilder.buildAll();
if (kBuilder.getResults().hasMessages(Level.ERROR)) {
fail("should not have errors" + kBuilder.getResults());
}
MemoryKieModule kieModule = (MemoryKieModule) kBuilder.getKieModule();
MemoryFileSystem trgMfs = kieModule.getMemoryFileSystem();
if (createJar) {
trgMfs.writeAsJar(fileManager.getRootDirectory(), namespace + "-" + version);
} else {
java.io.File file = fileManager.newFile(namespace + "-" + version);
trgMfs.writeAsFs(file);
}
return kproj;
}
use of org.kie.api.builder.KieBuilder in project drools by kiegroup.
the class SimulateTestBase method createKJarWithMultipleResources.
public static ReleaseId createKJarWithMultipleResources(String id, String[] resources, ResourceType[] types) {
KieServices ks = KieServices.Factory.get();
KieModuleModel kproj = ks.newKieModuleModel();
KieFileSystem kfs = ks.newKieFileSystem();
for (int i = 0; i < resources.length; i++) {
String res = resources[i];
String type = types[i].getDefaultExtension();
kfs.write("src/main/resources/" + id.replaceAll("\\.", "/") + "/org/test/res" + i + "." + type, res);
}
KieBaseModel kBase1 = kproj.newKieBaseModel(id).setEqualsBehavior(EqualityBehaviorOption.EQUALITY).setEventProcessingMode(EventProcessingOption.STREAM);
KieSessionModel ksession1 = kBase1.newKieSessionModel(id + ".KSession1").setDefault(true).setType(KieSessionModel.KieSessionType.STATEFUL).setClockType(ClockTypeOption.get("pseudo"));
kfs.writeKModuleXML(kproj.toXML());
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
assertTrue(kieBuilder.getResults().getMessages().isEmpty());
KieModule kieModule = kieBuilder.getKieModule();
return kieModule.getReleaseId();
}
use of org.kie.api.builder.KieBuilder 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.builder.KieBuilder 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();
}
Aggregations