Search in sources :

Example 76 with KieModuleModel

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();
    }
}
Also used : KieModuleModel(org.kie.api.builder.model.KieModuleModel) StatelessKieSession(org.kie.api.runtime.StatelessKieSession) StatelessKieSession(org.kie.api.runtime.StatelessKieSession) KieSession(org.kie.api.runtime.KieSession) InternalKieContainer(org.drools.core.impl.InternalKieContainer) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 77 with KieModuleModel

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");
}
Also used : KieModuleModel(org.kie.api.builder.model.KieModuleModel) InternalKieContainer(org.drools.core.impl.InternalKieContainer) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 78 with KieModuleModel

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");
}
Also used : KieModuleModel(org.kie.api.builder.model.KieModuleModel) InternalKieContainer(org.drools.core.impl.InternalKieContainer) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 79 with KieModuleModel

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");
}
Also used : KieModuleModel(org.kie.api.builder.model.KieModuleModel) InternalKieContainer(org.drools.core.impl.InternalKieContainer) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 80 with KieModuleModel

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");
}
Also used : KieModuleModel(org.kie.api.builder.model.KieModuleModel) InternalKieContainer(org.drools.core.impl.InternalKieContainer) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Aggregations

KieModuleModel (org.kie.api.builder.model.KieModuleModel)126 KieFileSystem (org.kie.api.builder.KieFileSystem)78 KieServices (org.kie.api.KieServices)76 Test (org.junit.Test)67 KieBuilder (org.kie.api.builder.KieBuilder)56 KieBaseModel (org.kie.api.builder.model.KieBaseModel)55 KieContainer (org.kie.api.runtime.KieContainer)50 ReleaseId (org.kie.api.builder.ReleaseId)38 KieSession (org.kie.api.runtime.KieSession)27 KieSessionModel (org.kie.api.builder.model.KieSessionModel)25 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)18 InternalKieContainer (org.drools.core.impl.InternalKieContainer)14 KieModule (org.kie.api.builder.KieModule)14 KieBase (org.kie.api.KieBase)11 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)10 Results (org.kie.api.builder.Results)10 Resource (org.kie.api.io.Resource)9 ArrayList (java.util.ArrayList)8 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)8 Before (org.junit.Before)7