Search in sources :

Example 56 with KieBuilder

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

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

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

the class DrlxCompiler method createKieContainer.

private static KieContainer createKieContainer(KieServices ks, KieFileSystem kfs, ReleaseId releaseId) {
    KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
    Results results = kieBuilder.getResults();
    if (results.hasMessages(Message.Level.ERROR)) {
        throw new RuntimeException(results.getMessages().toString());
    }
    return ks.newKieContainer(releaseId);
}
Also used : Results(org.kie.api.builder.Results) KieBuilder(org.kie.api.builder.KieBuilder)

Example 59 with KieBuilder

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

the class BaseModelTest method getKieContainer.

protected KieContainer getKieContainer(KieModuleModel model, KieFile... stringRules) {
    KieServices ks = KieServices.get();
    ReleaseId releaseId = ks.newReleaseId("org.kie", "kjar-test-" + UUID.randomUUID(), "1.0");
    KieBuilder kieBuilder = createKieBuilder(ks, model, releaseId, stringRules);
    return ks.newKieContainer(releaseId);
}
Also used : KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) KieBuilder(org.kie.api.builder.KieBuilder)

Example 60 with KieBuilder

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

the class BaseModelTest method createKieBuilder.

protected KieBuilder createKieBuilder(KieServices ks, KieModuleModel model, ReleaseId releaseId, boolean failIfBuildError, KieFile... stringRules) {
    ks.getRepository().removeKieModule(releaseId);
    KieFileSystem kfs = ks.newKieFileSystem();
    if (model != null) {
        kfs.writeKModuleXML(model.toXML());
    }
    kfs.writePomXML(KJARUtils.getPom(releaseId));
    for (int i = 0; i < stringRules.length; i++) {
        kfs.write(stringRules[i].path, stringRules[i].content);
    }
    KieBuilder kieBuilder;
    if (testRunType == RUN_TYPE.FLOW_DSL) {
        kieBuilder = ks.newKieBuilder(kfs).buildAll(ExecutableModelFlowProject.class);
    } else if (testRunType == RUN_TYPE.PATTERN_DSL) {
        kieBuilder = ks.newKieBuilder(kfs).buildAll(ExecutableModelProject.class);
    } else {
        kieBuilder = ks.newKieBuilder(kfs).buildAll();
    }
    if (failIfBuildError) {
        List<Message> messages = kieBuilder.getResults().getMessages();
        if (!messages.isEmpty()) {
            fail(messages.toString());
        }
    }
    return kieBuilder;
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Message(org.kie.api.builder.Message) KieBuilder(org.kie.api.builder.KieBuilder)

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