KieModuleModelExample { public void go(PrintStream out) { KieServices ks = KieServices.Factory.get(); KieFileSystem kfs = ks.newKieFileSystem(); Resource ex1Res = ks.getResources().newFileSystemResource(getFile("named-kiesession")); Resource ex2Res = ks.getResources().newFileSystemResource(getFile("kiebase-inclusion")); ReleaseId rid = ks.newReleaseId("org.drools", "kiemodulemodel-example", Drools.getFullVersion()); kfs.generateAndWritePomXML(rid); KieModuleModel kModuleModel = ks.newKieModuleModel(); kModuleModel.newKieBaseModel("kiemodulemodel") .addInclude("kbase1") .addInclude("kbase2") .newKieSessionModel("ksession6"); kfs.writeKModuleXML(kModuleModel.toXML()); kfs.write("src/main/resources/kiemodulemodel/HAL6.drl", getRule()); KieBuilder kb = ks.newKieBuilder(kfs); kb.setDependencies(ex1Res, ex2Res); kb.buildAll(); if (kb.getResults().hasMessages(Level.ERROR)) { throw new RuntimeException("Build Errors:\n" + kb.getResults().toString()); } KieContainer kContainer = ks.newKieContainer(rid); KieSession kSession = kContainer.newKieSession("ksession6"); kSession.setGlobal("out", out); Object msg1 = createMessage(kContainer, "Dave", "Hello, HAL. Do you read me, HAL?"); kSession.insert(msg1); kSession.fireAllRules(); Object msg2 = createMessage(kContainer, "Dave", "Open the pod bay doors, HAL."); kSession.insert(msg2); kSession.fireAllRules(); Object msg3 = createMessage(kContainer, "Dave", "What's the problem?"); kSession.insert(msg3); kSession.fireAllRules(); }  void go(PrintStream out); static void main(String[] args); static File getFile(String exampleName);  }
@Test public void testGo() { ByteArrayOutputStream baos = new ByteArrayOutputStream(); PrintStream ps = new PrintStream(baos); new KieModuleModelExample().go(ps); ps.close(); String actual = new String(baos.toByteArray()); String expected = "" + "Dave: Hello, HAL. Do you read me, HAL?" + NL + "HAL: Dave. I read you." + NL + "Dave: Open the pod bay doors, HAL." + NL + "HAL: I'm sorry, Dave. I'm afraid I can't do that." + NL + "Dave: What's the problem?" + NL + "HAL: I think you know what the problem is just as well as I do." + NL; assertEquals(expected, actual); }