use of org.kie.api.builder.model.KieModuleModel in project drools-wb by kiegroup.
the class ScenarioRunnerServiceTest method initKieSession.
private void initKieSession(String... resourceNames) {
final KieServices kieServices = KieServices.Factory.get();
final KieModuleModel kieModuleModel = kieServices.newKieModuleModel();
final KieBaseModel kieBaseModel = kieModuleModel.newKieBaseModel("defaultKieBase").setDefault(true).setEqualsBehavior(EqualityBehaviorOption.EQUALITY).setEventProcessingMode(EventProcessingOption.STREAM);
kieBaseModel.newKieSessionModel("defaultKieSession").setDefault(true).setType(KieSessionModel.KieSessionType.STATEFUL).setClockType(ClockTypeOption.get("pseudo")).newWorkItemHandlerModel("Rest", "org.drools.workbench.screens.testscenario.backend.server.GithubContributorsWIH");
final KieFileSystem kfs = kieServices.newKieFileSystem();
kfs.writeKModuleXML(kieModuleModel.toXML());
for (String resource : resourceNames) {
kfs.write(ResourceFactory.newUrlResource(this.getClass().getResource(resource).toString()));
}
kieServices.newKieBuilder(kfs).buildAll();
kieContainer = kieServices.newKieContainer(kieServices.getRepository().getDefaultReleaseId());
kieSession = kieContainer.newKieSession();
doReturn(kieSession).when(sessionService).newDefaultKieSessionWithPseudoClock(any(KieModule.class));
}
use of org.kie.api.builder.model.KieModuleModel in project drools by kiegroup.
the class KieProjectRuntimeModulesTest method createMultpleJarAndFileResources.
@Test
public void createMultpleJarAndFileResources() throws IOException, ClassNotFoundException, InterruptedException {
KieModuleModel kProjModel1 = createKieModule("jar1", true);
KieModuleModel kProjModel2 = createKieModule("jar2", true);
KieModuleModel kProjModel3 = createKieModule("jar3", true);
KieModuleModel kProjModel4 = createKieModule("fol4", false);
ReleaseId releaseId1 = KieServices.Factory.get().newReleaseId("jar1", "art1", "1.0-SNAPSHOT");
ReleaseId releaseId2 = KieServices.Factory.get().newReleaseId("jar2", "art1", "1.0-SNAPSHOT");
ReleaseId releaseId3 = KieServices.Factory.get().newReleaseId("jar3", "art1", "1.0-SNAPSHOT");
ReleaseId releaseId4 = KieServices.Factory.get().newReleaseId("fol4", "art1", "1.0-SNAPSHOT");
java.io.File file1 = fileManager.newFile("jar1-1.0-SNAPSHOT.jar");
java.io.File file2 = fileManager.newFile("jar2-1.0-SNAPSHOT.jar");
java.io.File file3 = fileManager.newFile("jar3-1.0-SNAPSHOT.jar");
java.io.File fol4 = fileManager.newFile("fol4-1.0-SNAPSHOT");
ZipKieModule mod1 = new ZipKieModule(releaseId1, kProjModel1, file1);
ZipKieModule mod2 = new ZipKieModule(releaseId2, kProjModel2, file2);
ZipKieModule mod3 = new ZipKieModule(releaseId3, kProjModel3, file3);
FileKieModule mod4 = new FileKieModule(releaseId4, kProjModel4, fol4);
mod1.addKieDependency(mod2);
mod1.addKieDependency(mod3);
mod1.addKieDependency(mod4);
KieModuleKieProject kProject = new KieModuleKieProject(mod1);
KieContainer kContainer = new KieContainerImpl(kProject, null);
KieBase kBase = kContainer.getKieBase("jar1.KBase1");
ClassLoader cl = ((KnowledgeBaseImpl) kBase).getRootClassLoader();
Class cls = cl.loadClass("org.drools.compiler.cdi.test.KProjectTestClassjar1");
assertNotNull(cls);
cls = cl.loadClass("org.drools.compiler.cdi.test.KProjectTestClassjar2");
assertNotNull(cls);
cls = cl.loadClass("org.drools.compiler.cdi.test.KProjectTestClassjar3");
assertNotNull(cls);
testEntry(new KProjectTestClassImpl("jar1", kContainer), "jar1");
testEntry(new KProjectTestClassImpl("jar2", kContainer), "jar2");
testEntry(new KProjectTestClassImpl("jar3", kContainer), "jar3");
testEntry(new KProjectTestClassImpl("fol4", kContainer), "fol4");
}
use of org.kie.api.builder.model.KieModuleModel in project drools by kiegroup.
the class KieBuilderTest method testGetKieBaseAfterKieSessionCreation.
@Test
public void testGetKieBaseAfterKieSessionCreation() {
final String KBASE_NAME = "kieBase";
final String KSESSION_NAME = "kieSession";
final String drl = "declare TestEvent\n" + " @role( event )\n" + " name : String\n" + "end\n" + "\n" + "declare window DeclaredTimeWindow\n" + " TestEvent ( name == \"timeDec\" ) over window:time( 50ms ) from entry-point EventStream\n" + "end";
final KieServices ks = KieServices.Factory.get();
final KieFileSystem kfs = ks.newKieFileSystem();
kfs.write("src/main/resources/window.drl", drl);
final KieModuleModel kmoduleModel = ks.newKieModuleModel();
kmoduleModel.newKieBaseModel(KBASE_NAME).addPackage("*").newKieSessionModel(KSESSION_NAME).setDefault(true).setClockType(ClockTypeOption.get("pseudo"));
kfs.writeKModuleXML(kmoduleModel.toXML());
final KieBuilder builder = ks.newKieBuilder(kfs).buildAll();
assertEquals(0, builder.getResults().getMessages().size());
ks.getRepository().addKieModule(builder.getKieModule());
final KieSession kieSession = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession(KSESSION_NAME);
assertNotNull(kieSession);
final KieBase kieBase = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).getKieBase(KBASE_NAME);
assertNotNull(kieBase);
}
use of org.kie.api.builder.model.KieModuleModel in project drools by kiegroup.
the class KieBuilderTest method testKieBuilderWithDotFiles.
@Test
public void testKieBuilderWithDotFiles() {
// BZ-1044409
final String KBASE_NAME = "kieBase";
final String KSESSION_NAME = "kieSession";
// This can be any DRL, or any file recognised by drools-compiler
final String drl = "declare TestEvent\n" + " name : String\n" + "end\n";
final String dotDrl = "Meta-data used by kie-wb";
final KieServices ks = KieServices.Factory.get();
final KieFileSystem kfs = ks.newKieFileSystem();
kfs.write("src/main/resources/drlFile.drl", drl);
kfs.write("src/main/resources/.drlFile.drl", dotDrl);
final KieModuleModel kmoduleModel = ks.newKieModuleModel();
kmoduleModel.newKieBaseModel(KBASE_NAME).addPackage("*").newKieSessionModel(KSESSION_NAME).setDefault(true);
kfs.writeKModuleXML(kmoduleModel.toXML());
final KieBuilder builder = ks.newKieBuilder(kfs).buildAll();
for (final org.kie.api.builder.Message m : builder.getResults().getMessages()) {
System.out.println(m);
}
assertEquals(0, builder.getResults().getMessages().size());
ks.getRepository().addKieModule(builder.getKieModule());
final KieSession kieSession = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession(KSESSION_NAME);
assertNotNull(kieSession);
final KieBase kieBase = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).getKieBase(KBASE_NAME);
assertNotNull(kieBase);
}
use of org.kie.api.builder.model.KieModuleModel in project drools by kiegroup.
the class KieHelloWorldTest method testHelloWorldWithKBaseInclude.
@Test
public void testHelloWorldWithKBaseInclude() throws Exception {
String drl = "package org.drools.compiler.integrationtests\n" + "declare CancelFact\n" + " cancel : boolean = true\n" + "end\n" + "rule R1 when\n" + " $m : CancelFact( cancel == true )\n" + "then\n" + "end\n";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", drl);
KieModuleModel module = ks.newKieModuleModel();
// define first kbase
final String defaultBaseName = "defaultKBase";
KieBaseModel defaultBase = module.newKieBaseModel(defaultBaseName);
defaultBase.setDefault(true);
defaultBase.addPackage("*");
defaultBase.newKieSessionModel("defaultKSession").setDefault(true);
// define second kbase including resources of the first one
final String includingBaseName = "includingKBase";
KieBaseModel includingBase = module.newKieBaseModel(includingBaseName);
includingBase.setDefault(false);
includingBase.addInclude(defaultBaseName);
includingBase.newKieSessionModel("includingKSession").setDefault(false);
kfs.writeKModuleXML(module.toXML());
KieBuilder kb = ks.newKieBuilder(kfs).buildAll();
assertEquals(0, kb.getResults().getMessages().size());
KieSession ksession = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession();
FactType factType = ksession.getKieBase().getFactType("org.drools.compiler.integrationtests", "CancelFact");
assertNotNull(factType);
ksession.insert(factType.newInstance());
int count = ksession.fireAllRules();
assertEquals(1, count);
}
Aggregations