use of org.kie.api.builder.model.KieModuleModel in project drools by kiegroup.
the class KieContainerDefaultsTest method testTwoKieSessionsOneStatelessDefault.
/**
* This test checks if default KieSessions behave as expected even if one of them is Stateless.
*/
@Test
public void testTwoKieSessionsOneStatelessDefault() {
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").setDefault(false);
buildKieModule(kieModule);
final KieContainer kieContainer = kieServices.newKieContainer(RELEASE_ID);
final StatelessKieSession firstKSession = kieContainer.newStatelessKieSession("firstKSession");
final KieSession secondKSession = kieContainer.newKieSession("secondKSession");
try {
Assertions.assertThat(firstKSession).isEqualTo(((InternalKieContainer) kieContainer).getStatelessKieSession());
Assertions.assertThat(secondKSession).isNotEqualTo(((InternalKieContainer) kieContainer).getStatelessKieSession());
} finally {
secondKSession.dispose();
}
}
use of org.kie.api.builder.model.KieModuleModel in project drools by kiegroup.
the class KieContainerDefaultsTest method testTwoKieBasesNoneDefault.
/**
* This test checks how KieBases behave when all are explicitly set not to be default.
*/
@Test
public void testTwoKieBasesNoneDefault() {
final KieModuleModel kieModule = kieServices.newKieModuleModel();
kieModule.newKieBaseModel("firstKBase").setDefault(false);
kieModule.newKieBaseModel("secondKBase").setDefault(false);
buildKieModule(kieModule);
final KieContainer kieContainer = kieServices.newKieContainer(RELEASE_ID);
Assertions.assertThatThrownBy(() -> kieContainer.getKieBase()).isInstanceOf(RuntimeException.class).hasMessageContaining("Cannot find a default KieBase");
}
use of org.kie.api.builder.model.KieModuleModel in project drools by kiegroup.
the class KieContainerDefaultsTest method testTwoStatelessKieSessionsNoneDefault.
/**
* This test checks how StatelessKieSessions behave when all are explicitly set not to be default.
*/
@Test
public void testTwoStatelessKieSessionsNoneDefault() {
final KieModuleModel kieModule = kieServices.newKieModuleModel();
kieModule.newKieBaseModel("firstKBase").setDefault(true).newKieSessionModel("firstKSession").setType(KieSessionModel.KieSessionType.STATELESS).setDefault(false);
kieModule.newKieBaseModel("secondKBase").setDefault(true).newKieSessionModel("secondKSession").setType(KieSessionModel.KieSessionType.STATELESS).setDefault(false);
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 testTwoKieSessionsDefaultNotSet.
/**
* This test checks how KieSessions behave when default state isn't explicitly set.
*/
@Test
public void testTwoKieSessionsDefaultNotSet() {
final KieModuleModel kieModule = kieServices.newKieModuleModel();
kieModule.newKieBaseModel("firstKBase").setDefault(true).newKieSessionModel("firstKSession");
kieModule.newKieBaseModel("secondKBase").setDefault(false).newKieSessionModel("secondKSession");
buildKieModule(kieModule);
final KieContainer kieContainer = kieServices.newKieContainer(RELEASE_ID);
Assertions.assertThatThrownBy(() -> kieContainer.newKieSession()).isInstanceOf(RuntimeException.class).hasMessageContaining("Cannot find a default KieSession");
}
use of org.kie.api.builder.model.KieModuleModel in project drools by kiegroup.
the class KieContainerDefaultsTest method testTwoKieSessionsBothDefault.
/**
* This test checks how KieSessions behave when more than one is set as default.
*/
@Test
public void testTwoKieSessionsBothDefault() {
final KieModuleModel kieModule = kieServices.newKieModuleModel();
kieModule.newKieBaseModel("firstKBase").setDefault(true).newKieSessionModel("firstKSession").setDefault(true);
kieModule.newKieBaseModel("secondKBase").setDefault(true).newKieSessionModel("secondKSession").setDefault(true);
buildKieModule(kieModule);
final KieContainer kieContainer = kieServices.newKieContainer(RELEASE_ID);
Assertions.assertThatThrownBy(() -> kieContainer.newKieSession()).isInstanceOf(RuntimeException.class).hasMessageContaining("Cannot find a default KieSession");
}
Aggregations