@Test public void testHelloWorldWithEmptyFile() throws Exception { String drl = "package org.drools\n" + "rule R1 when\n" + " $m : Message( message == \"Hello World\" )\n" + "then\n" + "end\n"; KieServices ks = KieServices.Factory.get(); KieFileSystem kfs = ks.newKieFileSystem() .write("src/main/resources/r1.drl", drl) .write( "src/main/resources/empty.drl", ks.getResources().newInputStreamResource(new ByteArrayInputStream(new byte[0]))); ks.newKieBuilder(kfs).buildAll(); KieSession ksession = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession(); ksession.insert(new Message("Hello World")); int count = ksession.fireAllRules(); assertEquals(1, count); }
@Test public void testHelloWorldWithPackages() throws Exception { String drl1 = "package org.drools\n" + "rule R1 when\n" + " $m : Message( message == \"Hello World\" )\n" + "then\n" + "end\n"; String drl2 = "package org.drools\n" + "rule R2 when\n" + " $m : Message( message == \"Hello World\" )\n" + "then\n" + "end\n"; KieServices ks = KieServices.Factory.get(); ReleaseId releaseId = ks.newReleaseId("org.kie", "hello-world", "1.0-SNAPSHOT"); KieFileSystem kfs = ks.newKieFileSystem() .generateAndWritePomXML(releaseId) .write("src/main/resources/KBase1/org/pkg1/r1.drl", drl1) .write("src/main/resources/KBase1/org/pkg2/r2.drl", drl2) .writeKModuleXML(createKieProjectWithPackages(ks, "org.pkg1").toXML()); ks.newKieBuilder(kfs).buildAll(); KieSession ksession = ks.newKieContainer(releaseId).newKieSession("KSession1"); ksession.insert(new Message("Hello World")); int count = ksession.fireAllRules(); assertEquals(1, count); }
private void checkKSession(KieSession ksession, Object... results) { List<String> list = new ArrayList<String>(); ksession.setGlobal("list", list); ksession.fireAllRules(); ksession.dispose(); assertEquals(results.length, list.size()); for (Object result : results) { assertTrue(list.contains(result)); } }
public void go(PrintStream out) { KieServices ks = KieServices.Factory.get(); KieRepository kr = ks.getRepository(); KieModule kModule = kr.addKieModule(ks.getResources().newFileSystemResource(getFile("named-kiesession"))); KieContainer kContainer = ks.newKieContainer(kModule.getReleaseId()); KieSession kSession = kContainer.newKieSession("ksession1"); kSession.setGlobal("out", out); Object msg1 = createMessage(kContainer, "Dave", "Hello, HAL. Do you read me, HAL?"); kSession.insert(msg1); kSession.fireAllRules(); }
@Test public void testHelloWorldOnVersionRange() throws Exception { KieServices ks = KieServices.Factory.get(); buildVersion(ks, "Hello World", "1.0"); buildVersion(ks, "Aloha Earth", "1.1"); buildVersion(ks, "Hi Universe", "1.2"); ReleaseId latestReleaseId = ks.newReleaseId("org.kie", "hello-world", "LATEST"); KieSession ksession = ks.newKieContainer(latestReleaseId).newKieSession("KSession1"); ksession.insert(new Message("Hello World")); assertEquals(0, ksession.fireAllRules()); ksession = ks.newKieContainer(latestReleaseId).newKieSession("KSession1"); ksession.insert(new Message("Hi Universe")); assertEquals(1, ksession.fireAllRules()); ReleaseId releaseId1 = ks.newReleaseId("org.kie", "hello-world", "1.0"); ksession = ks.newKieContainer(releaseId1).newKieSession("KSession1"); ksession.insert(new Message("Hello World")); assertEquals(1, ksession.fireAllRules()); ksession = ks.newKieContainer(releaseId1).newKieSession("KSession1"); ksession.insert(new Message("Hi Universe")); assertEquals(0, ksession.fireAllRules()); ReleaseId releaseId2 = ks.newReleaseId("org.kie", "hello-world", "[1.0,1.2)"); ksession = ks.newKieContainer(releaseId2).newKieSession("KSession1"); ksession.insert(new Message("Aloha Earth")); assertEquals(1, ksession.fireAllRules()); ksession = ks.newKieContainer(releaseId2).newKieSession("KSession1"); ksession.insert(new Message("Hi Universe")); assertEquals(0, ksession.fireAllRules()); }