Search in sources :

Example 71 with KieModuleModel

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

the class JpaPersistentStatefulSessionTest method testSessionConfigurationFromContainer.

@Test
public void testSessionConfigurationFromContainer() {
    // DROOLS-1002
    String str = "rule R when then end";
    KieServices ks = KieServices.Factory.get();
    KieModuleModel kmodel = ks.newKieModuleModel();
    kmodel.newKieBaseModel("kbase1").newKieSessionModel("ksession1").setClockType(ClockTypeOption.get("pseudo"));
    KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", str).writeKModuleXML(kmodel.toXML());
    ks.newKieBuilder(kfs).buildAll();
    KieContainer kcontainer = ks.newKieContainer(ks.getRepository().getDefaultReleaseId());
    KieSessionConfiguration conf = kcontainer.getKieSessionConfiguration("ksession1");
    assertEquals("pseudo", conf.getOption(ClockTypeOption.class).getClockType());
    KieSession ksession = ks.getStoreServices().newKieSession(kcontainer.getKieBase("kbase1"), conf, env);
    assertTrue(ksession.getSessionClock() instanceof SessionPseudoClock);
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) SessionPseudoClock(org.kie.api.time.SessionPseudoClock) KieModuleModel(org.kie.api.builder.model.KieModuleModel) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) KieSessionConfiguration(org.kie.api.runtime.KieSessionConfiguration) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 72 with KieModuleModel

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

the class KieBaseUtil method getKieModuleAndBuildInstallModule.

public static KieModule getKieModuleAndBuildInstallModule(final ReleaseId releaseId, final KieBaseTestConfiguration kieBaseTestConfiguration, final Resource... resources) {
    final KieModuleModel module = KieUtil.createKieModuleModel();
    kieBaseTestConfiguration.getKieBaseModel(module);
    return KieUtil.buildAndInstallKieModuleIntoRepo(kieBaseTestConfiguration, releaseId, module, resources);
}
Also used : KieModuleModel(org.kie.api.builder.model.KieModuleModel)

Example 73 with KieModuleModel

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

the class KieUtil method getDefaultKieModuleModel.

public static KieModuleModel getDefaultKieModuleModel(KieServices ks) {
    final KieModuleModel kproj = KieServices.get().newKieModuleModel();
    final KieBaseModel kieBaseModel1 = kproj.newKieBaseModel("kbase").setDefault(true);
    final 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 74 with KieModuleModel

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

the class KieSessionUtil method getKieSessionFromKieBaseModel.

public static Session getKieSessionFromKieBaseModel(final String moduleGroupId, final KieBaseTestConfiguration kieBaseTestConfiguration, final KieSessionTestConfiguration kieSessionTestConfiguration, final Resource... resources) {
    final KieModuleModel module = KieUtil.createKieModuleModel();
    final KieBaseModel kieBaseModel = kieBaseTestConfiguration.getKieBaseModel(module);
    kieSessionTestConfiguration.getKieSessionModel(kieBaseModel);
    final KieModule kieModule = KieUtil.buildAndInstallKieModuleIntoRepo(kieBaseTestConfiguration, moduleGroupId, module, resources);
    return getDefaultKieSessionFromReleaseId(kieModule.getReleaseId(), kieSessionTestConfiguration.isStateful(), false);
}
Also used : KieBaseModel(org.kie.api.builder.model.KieBaseModel) KieModuleModel(org.kie.api.builder.model.KieModuleModel) KieModule(org.kie.api.builder.KieModule)

Example 75 with KieModuleModel

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

the class KieContainerDefaultsTest method testTwoKieSessionsNoneDefault.

/**
 * This test checks how KieSessions behave when all are explicitly set not to be default.
 */
@Test
public void testTwoKieSessionsNoneDefault() {
    final KieModuleModel kieModule = kieServices.newKieModuleModel();
    kieModule.newKieBaseModel("firstKBase").setDefault(true).newKieSessionModel("firstKSession").setDefault(false);
    kieModule.newKieBaseModel("secondKBase").setDefault(true).newKieSessionModel("secondKSession").setDefault(false);
    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