Search in sources :

Example 96 with KieFileSystem

use of org.kie.api.builder.KieFileSystem 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 97 with KieFileSystem

use of org.kie.api.builder.KieFileSystem 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)

Example 98 with KieFileSystem

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

the class IncrementalCompilationTest method testIncrementalCompilationDuplicateXLSResources.

@Test
public void testIncrementalCompilationDuplicateXLSResources() throws Exception {
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem();
    InputStream in1 = null;
    InputStream in2 = null;
    try {
        // Add XLS decision table
        in1 = this.getClass().getResourceAsStream("incrementalBuild.dtable.xls");
        kfs.write("src/main/resources/incrementalBuild1.dtable.xls", KieServices.Factory.get().getResources().newInputStreamResource(in1));
        // Expect no errors
        KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
        assertEquals(0, kieBuilder.getResults().getMessages(org.kie.api.builder.Message.Level.ERROR).size());
        // Add the same XLS decision table again as a different resource
        in2 = this.getClass().getResourceAsStream("incrementalBuild.dtable.xls");
        kfs.write("src/main/resources/incrementalBuild2.dtable.xls", KieServices.Factory.get().getResources().newInputStreamResource(in2));
        IncrementalResults addResults = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/incrementalBuild2.dtable.xls").build();
        // Expect duplicate rule errors
        assertEquals(1, addResults.getAddedMessages().size());
        assertEquals(0, addResults.getRemovedMessages().size());
        // Check errors on a full build
        List<Message> messages = ks.newKieBuilder(kfs).buildAll().getResults().getMessages();
        assertFalse(messages.isEmpty());
    } finally {
        if (in1 != null) {
            in1.close();
        }
        if (in2 != null) {
            in2.close();
        }
    }
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Message(org.kie.api.builder.Message) InputStream(java.io.InputStream) KieServices(org.kie.api.KieServices) InternalKieBuilder(org.kie.internal.builder.InternalKieBuilder) KieBuilder(org.kie.api.builder.KieBuilder) IncrementalResults(org.kie.internal.builder.IncrementalResults) Test(org.junit.Test)

Example 99 with KieFileSystem

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

the class XlsFormulaTest method getKieSession.

private KieSession getKieSession(Resource dt) {
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem().write(dt);
    KieBuilder kb = ks.newKieBuilder(kfs).buildAll();
    assertTrue(kb.getResults().getMessages().isEmpty());
    // get the session
    KieSession ksession = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).newKieSession();
    return ksession;
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) KieBuilder(org.kie.api.builder.KieBuilder)

Example 100 with KieFileSystem

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

the class DrlxCompiler method createKieFileSystem.

private static KieFileSystem createKieFileSystem(KieServices ks, ReleaseId releaseId) {
    KieModuleModel kproj = ks.newKieModuleModel();
    KieFileSystem kfs = ks.newKieFileSystem();
    kfs.writeKModuleXML(kproj.toXML());
    kfs.writePomXML(getPom(releaseId));
    return kfs;
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) KieModuleModel(org.kie.api.builder.model.KieModuleModel)

Aggregations

KieFileSystem (org.kie.api.builder.KieFileSystem)297 KieServices (org.kie.api.KieServices)241 Test (org.junit.Test)211 KieBuilder (org.kie.api.builder.KieBuilder)179 KieSession (org.kie.api.runtime.KieSession)101 KieModuleModel (org.kie.api.builder.model.KieModuleModel)79 KieContainer (org.kie.api.runtime.KieContainer)74 ReleaseId (org.kie.api.builder.ReleaseId)64 Results (org.kie.api.builder.Results)60 InternalKieBuilder (org.kie.internal.builder.InternalKieBuilder)53 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)39 KieBase (org.kie.api.KieBase)38 IncrementalResults (org.kie.internal.builder.IncrementalResults)36 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)32 KieBaseModel (org.kie.api.builder.model.KieBaseModel)31 ArrayList (java.util.ArrayList)30 Message (org.kie.api.builder.Message)26 KieModule (org.kie.api.builder.KieModule)22 Message (org.drools.compiler.Message)20 Resource (org.kie.api.io.Resource)18