Search in sources :

Example 41 with KieModuleModel

use of org.kie.api.builder.model.KieModuleModel in project drools by kiegroup.

the class BaseModelTest method getDefaultKieModuleModel.

protected KieModuleModel getDefaultKieModuleModel(KieServices ks) {
    KieModuleModel kproj = ks.newKieModuleModel();
    kproj.newKieBaseModel("kbase").setDefault(true).newKieSessionModel("ksession").setDefault(true);
    return kproj;
}
Also used : KieModuleModel(org.kie.api.builder.model.KieModuleModel)

Example 42 with KieModuleModel

use of org.kie.api.builder.model.KieModuleModel in project drools by kiegroup.

the class BuildFromKJarTest method getDefaultKieModuleModel.

private KieModuleModel getDefaultKieModuleModel(KieServices ks) {
    KieModuleModel kproj = ks.newKieModuleModel();
    KieBaseModel kieBaseModel1 = kproj.newKieBaseModel("kbase").setDefault(true);
    KieSessionModel ksession1 = kieBaseModel1.newKieSessionModel("ksession").setDefault(true);
    return kproj;
}
Also used : KieBaseModel(org.kie.api.builder.model.KieBaseModel) KieModuleModel(org.kie.api.builder.model.KieModuleModel) KieSessionModel(org.kie.api.builder.model.KieSessionModel)

Example 43 with KieModuleModel

use of org.kie.api.builder.model.KieModuleModel in project drools by kiegroup.

the class KieContainerDefaultsTest method testTwoStatelessKieSessionsBothDefault.

/**
 * This test checks how StatelessKieSessions behave when more than one is set as default.
 */
@Test
public void testTwoStatelessKieSessionsBothDefault() {
    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(true);
    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 44 with KieModuleModel

use of org.kie.api.builder.model.KieModuleModel in project drools by kiegroup.

the class KieContainerDefaultsTest method testTwoKieBasesOneDefault.

/**
 * This test checks if default KieBases behave as expected.
 */
@Test
public void testTwoKieBasesOneDefault() {
    final KieModuleModel kieModule = kieServices.newKieModuleModel();
    kieModule.newKieBaseModel("firstKBase").setDefault(true);
    kieModule.newKieBaseModel("secondKBase").setDefault(false);
    buildKieModule(kieModule);
    final KieContainer kieContainer = kieServices.newKieContainer(RELEASE_ID);
    final KieBase firstKBase = kieContainer.getKieBase("firstKBase");
    final KieBase secondKBase = kieContainer.getKieBase("secondKBase");
    Assertions.assertThat(kieContainer.getKieBase()).isEqualTo(firstKBase);
    Assertions.assertThat(kieContainer.getKieBase()).isNotEqualTo(secondKBase);
}
Also used : KieModuleModel(org.kie.api.builder.model.KieModuleModel) KieBase(org.kie.api.KieBase) InternalKieContainer(org.drools.core.impl.InternalKieContainer) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 45 with KieModuleModel

use of org.kie.api.builder.model.KieModuleModel in project drools by kiegroup.

the class KieContainerDefaultsTest method testTwoKieSessionsOneDefault.

/**
 * This test checks if default KieSessions behave as expected.
 */
@Test
public void testTwoKieSessionsOneDefault() {
    final KieModuleModel kieModule = kieServices.newKieModuleModel();
    kieModule.newKieBaseModel("firstKBase").setDefault(true).newKieSessionModel("firstKSession").setDefault(true);
    kieModule.newKieBaseModel("secondKBase").setDefault(true).newKieSessionModel("secondKSession");
    buildKieModule(kieModule);
    final KieContainer kieContainer = kieServices.newKieContainer(RELEASE_ID);
    final KieSession firstKSession = kieContainer.newKieSession("firstKSession");
    final KieSession secondKSession = kieContainer.newKieSession("secondKSession");
    try {
        Assertions.assertThat(firstKSession).isEqualTo(((InternalKieContainer) kieContainer).getKieSession());
        Assertions.assertThat(secondKSession).isNotEqualTo(((InternalKieContainer) kieContainer).getKieSession());
    } finally {
        firstKSession.dispose();
        secondKSession.dispose();
    }
}
Also used : KieModuleModel(org.kie.api.builder.model.KieModuleModel) 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)

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