@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); }
@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 testFailingHelloWorld() throws Exception { String drl = "package org.drools\n" + "rule R1 when\n" + " $m : Message( mesage == \"Hello World\" )\n" + "then\n" + "end\n"; KieServices ks = KieServices.Factory.get(); KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", drl); KieBuilder kb = ks.newKieBuilder(kfs).buildAll(); assertEquals(1, kb.getResults().getMessages().size()); }
private void buildVersion(KieServices ks, String message, String version) { String drl = "package org.drools\n" + "rule R1 when\n" + " $m : Message( message == \"" + message + "\" )\n" + "then\n" + "end\n"; ReleaseId releaseId = ks.newReleaseId("org.kie", "hello-world", version); KieFileSystem kfs = ks.newKieFileSystem() .generateAndWritePomXML(releaseId) .write("src/main/resources/KBase1/org/pkg1/r1.drl", drl) .writeKModuleXML(createKieProjectWithPackages(ks, "*").toXML()); ks.newKieBuilder(kfs).buildAll(); }