use of org.kie.api.builder.model.KieModuleModel in project drools by kiegroup.
the class KieContainerDefaultsTest method testTwoStatelessKieSessionsDefaultNotSet.
/**
* This test checks how StatelessKieSessions behave when default state isn't explicitly set.
*/
@Test
public void testTwoStatelessKieSessionsDefaultNotSet() {
final KieModuleModel kieModule = kieServices.newKieModuleModel();
kieModule.newKieBaseModel("firstKBase").setDefault(true).newKieSessionModel("firstKSession").setType(KieSessionModel.KieSessionType.STATELESS);
kieModule.newKieBaseModel("secondKBase").setDefault(true).newKieSessionModel("secondKSession").setType(KieSessionModel.KieSessionType.STATELESS);
buildKieModule(kieModule);
final KieContainer kieContainer = kieServices.newKieContainer(RELEASE_ID);
Assertions.assertThatThrownBy(() -> kieContainer.newStatelessKieSession()).isInstanceOf(RuntimeException.class).hasMessageContaining("Cannot find a default StatelessKieSession");
}
use of org.kie.api.builder.model.KieModuleModel in project drools by kiegroup.
the class KieContainerDefaultsTest method testTwoStatelessKieSessionsOneDefault.
/**
* This test checks if default StatelessKieSessions behave as expected.
*/
@Test
public void testTwoStatelessKieSessionsOneDefault() {
final KieModuleModel kieModule = kieServices.newKieModuleModel();
kieModule.newKieBaseModel("firstKBase").setDefault(true).newKieSessionModel("firstKSession").setType(KieSessionModel.KieSessionType.STATELESS).setDefault(true);
kieModule.newKieBaseModel("secondKBase").setDefault(true).newKieSessionModel("secondKSession").setType(KieSessionModel.KieSessionType.STATELESS).setDefault(false);
buildKieModule(kieModule);
final KieContainer kieContainer = kieServices.newKieContainer(RELEASE_ID);
final StatelessKieSession firstKSession = kieContainer.newStatelessKieSession("firstKSession");
final StatelessKieSession secondKSession = kieContainer.newStatelessKieSession("secondKSession");
Assertions.assertThat(firstKSession).isEqualTo(((InternalKieContainer) kieContainer).getStatelessKieSession());
Assertions.assertThat(secondKSession).isNotEqualTo(((InternalKieContainer) kieContainer).getStatelessKieSession());
}
use of org.kie.api.builder.model.KieModuleModel in project drools by kiegroup.
the class KieModuleModelExample method go.
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);
// kieModule is automatically deployed to KieRepository if successfully built.
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();
}
use of org.kie.api.builder.model.KieModuleModel in project drools by kiegroup.
the class KieContainerTest method createKieModule.
/**
* Helper method creating simple KieModule with given ReleaseId.
*/
private void createKieModule(final ReleaseId releaseId) {
final KieModuleModel kmodule = kieServices.newKieModuleModel();
kmodule.newKieBaseModel("defaultKBase").setDefault(true).newKieSessionModel(SESSION_NAME);
final KieFileSystem kfs = kieServices.newKieFileSystem();
kfs.generateAndWritePomXML(releaseId);
kfs.writeKModuleXML(kmodule.toXML());
kfs.write("src/main/resources/defaultKBase/test.drl", kieServices.getResources().newByteArrayResource(DRL.getBytes()));
final KieBuilder kbuilder = kieServices.newKieBuilder(kfs);
kbuilder.buildAll();
}
use of org.kie.api.builder.model.KieModuleModel in project drools by kiegroup.
the class DMNExtensionRegisterTest method testUsingKModuleProperty_WrongClasses.
@Test
public void testUsingKModuleProperty_WrongClasses() {
final KieServices ks = KieServices.Factory.get();
final KieFileSystem kfs = ks.newKieFileSystem();
KieModuleModel kmm = ks.newKieModuleModel();
kmm.setConfigurationProperty("org.kie.dmn.profiles.FirstNameLastNameProfile", "foo");
kfs.writeKModuleXML(kmm.toXML());
kfs.write(ks.getResources().newClassPathResource("0001-input-data-string-with-extensions.dmn", this.getClass()));
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
Results results = kieBuilder.getResults();
LOG.info("buildAll() completed.");
results.getMessages(Level.WARNING).forEach(e -> LOG.warn("{}", e));
assertTrue(results.getMessages(Level.WARNING).size() > 0);
final KieContainer kieContainer = ks.newKieContainer(ks.getRepository().getDefaultReleaseId());
DMNRuntime runtime = kieContainer.newKieSession().getKieRuntime(DMNRuntime.class);
DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn", "0001-input-data-string");
assertThat(dmnModel, notNullValue());
assertThat(formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
assertEquals(3, dmnModel.getDefinitions().getDrgElement().size());
InputData inputData1 = (InputData) dmnModel.getDefinitions().getDrgElement().get(1);
assertEquals("First Name", inputData1.getName());
DMNElement.ExtensionElements id1elements = inputData1.getExtensionElements();
assertTrue(id1elements != null);
assertEquals(0, id1elements.getAny().size());
InputData inputData2 = (InputData) dmnModel.getDefinitions().getDrgElement().get(2);
assertEquals("Last Name", inputData2.getName());
DMNElement.ExtensionElements id2elements = inputData2.getExtensionElements();
assertTrue(id2elements != null);
assertEquals(0, id2elements.getAny().size());
}
Aggregations