Search in sources :

Example 51 with KieBuilder

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

the class DroolsAbstractPMMLTest method getModelSession.

protected KieSession getModelSession(String[] pmmlSources, boolean verbose) {
    KieServices ks = KieServices.Factory.get();
    KieRepository kr = ks.getRepository();
    KieFileSystem kfs = ks.newKieFileSystem();
    for (int j = 0; j < pmmlSources.length; j++) {
        Resource res = ResourceFactory.newClassPathResource(pmmlSources[j]).setResourceType(ResourceType.PMML);
        kfs.write(res);
    }
    KieModuleModel model = ks.newKieModuleModel();
    model.setConfigurationProperty("drools.propertySpecific", "ALLOWED");
    KieBaseModel kbModel = model.newKieBaseModel(DEFAULT_KIEBASE).setDefault(true).addPackage(BASE_PACK).setEventProcessingMode(EventProcessingOption.STREAM);
    kfs.writeKModuleXML(model.toXML());
    KieBuilder kb = ks.newKieBuilder(kfs);
    kb.buildAll();
    if (kb.getResults().hasMessages(Message.Level.ERROR)) {
        throw new RuntimeException("Build Errors:\n" + kb.getResults().toString());
    }
    KieContainer kContainer = ks.newKieContainer(kr.getDefaultReleaseId());
    KieBase kieBase = kContainer.getKieBase();
    setKbase(kieBase);
    return kieBase.newKieSession();
}
Also used : KieBaseModel(org.kie.api.builder.model.KieBaseModel) KieRepository(org.kie.api.builder.KieRepository) KieFileSystem(org.kie.api.builder.KieFileSystem) KieModuleModel(org.kie.api.builder.model.KieModuleModel) KieBase(org.kie.api.KieBase) Resource(org.kie.api.io.Resource) KieServices(org.kie.api.KieServices) KieBuilder(org.kie.api.builder.KieBuilder) KieContainer(org.kie.api.runtime.KieContainer)

Example 52 with KieBuilder

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

the class PMMLErrorTest method testNoErrorDuringGeneration.

@Test
public void testNoErrorDuringGeneration() {
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem();
    kfs.write(ResourceFactory.newByteArrayResource(pmml.getBytes()).setResourceType(ResourceType.PMML).setSourcePath("pmml.pmml"));
    KieBuilder kb = ks.newKieBuilder(kfs);
    kb.buildAll();
    assertEquals(0, kb.getResults().getMessages(Message.Level.ERROR).size());
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) KieServices(org.kie.api.KieServices) KieBuilder(org.kie.api.builder.KieBuilder) Test(org.junit.Test)

Example 53 with KieBuilder

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

the class PMMLErrorTest method testErrorDuringGeneration.

@Test
public void testErrorDuringGeneration() {
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem();
    kfs.write(ResourceFactory.newByteArrayResource(pmlm.getBytes()).setResourceType(ResourceType.PMML).setSourcePath("pmlm.pmml"));
    KieBuilder kb = ks.newKieBuilder(kfs);
    kb.buildAll();
    assertEquals(1, kb.getResults().getMessages(Message.Level.ERROR).size());
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) KieServices(org.kie.api.KieServices) KieBuilder(org.kie.api.builder.KieBuilder) Test(org.junit.Test)

Example 54 with KieBuilder

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

the class CalendarTimerResourcesTest method init.

@Before
public void init() {
    final KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem();
    KieModuleModel kmodule = ks.newKieModuleModel();
    KieBaseModel baseModel = kmodule.newKieBaseModel("defaultKBase").setDefault(true).setEventProcessingMode(EventProcessingOption.STREAM);
    baseModel.newKieSessionModel("defaultKSession").setDefault(true).setClockType(ClockTypeOption.get("pseudo"));
    kfs.writeKModuleXML(kmodule.toXML());
    // README when path is set then test works
    kfs.write(ks.getResources().newClassPathResource("calendar_timer.xls", this.getClass()));
    KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
    assertEquals(0, kieBuilder.getResults().getMessages(org.kie.api.builder.Message.Level.ERROR).size());
    ksession = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession();
    clock = ksession.getSessionClock();
}
Also used : KieBaseModel(org.kie.api.builder.model.KieBaseModel) KieFileSystem(org.kie.api.builder.KieFileSystem) KieModuleModel(org.kie.api.builder.model.KieModuleModel) KieServices(org.kie.api.KieServices) KieBuilder(org.kie.api.builder.KieBuilder) Before(org.junit.Before)

Example 55 with KieBuilder

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

the class PrioritySetWithFormulaTest method init.

@Before
public void init() {
    final KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem();
    KieModuleModel kmodule = ks.newKieModuleModel();
    kfs.writeKModuleXML(kmodule.toXML());
    kfs.write(ks.getResources().newClassPathResource("prioritySetWithFormula.xls", this.getClass()));
    KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
    assertEquals(0, kieBuilder.getResults().getMessages(org.kie.api.builder.Message.Level.ERROR).size());
    kieBase = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).getKieBase();
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) KieModuleModel(org.kie.api.builder.model.KieModuleModel) KieServices(org.kie.api.KieServices) KieBuilder(org.kie.api.builder.KieBuilder) Before(org.junit.Before)

Aggregations

KieBuilder (org.kie.api.builder.KieBuilder)211 KieFileSystem (org.kie.api.builder.KieFileSystem)179 KieServices (org.kie.api.KieServices)145 Test (org.junit.Test)134 KieSession (org.kie.api.runtime.KieSession)59 KieModuleModel (org.kie.api.builder.model.KieModuleModel)57 InternalKieBuilder (org.kie.internal.builder.InternalKieBuilder)54 KieContainer (org.kie.api.runtime.KieContainer)48 IncrementalResults (org.kie.internal.builder.IncrementalResults)35 ReleaseId (org.kie.api.builder.ReleaseId)34 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)33 Results (org.kie.api.builder.Results)32 Message (org.kie.api.builder.Message)30 KieBase (org.kie.api.KieBase)29 ArrayList (java.util.ArrayList)22 KieBaseModel (org.kie.api.builder.model.KieBaseModel)22 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)21 Resource (org.kie.api.io.Resource)19 FactType (org.kie.api.definition.type.FactType)16 KieModule (org.kie.api.builder.KieModule)12