Search in sources :

Example 16 with Results

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

the class KieContainerTest method testUpdateToNonExistingRelease.

@Test
public void testUpdateToNonExistingRelease() {
    // DROOLS-1562
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId = ks.newReleaseId("org.kie", "test-release", "1.0.0");
    createAndDeployJar(ks, releaseId, createDRL("ruleA"));
    KieContainer kieContainer = ks.newKieContainer(releaseId);
    Results results = kieContainer.updateToVersion(ks.newReleaseId("org.kie", "test-release", "1.0.1"));
    assertEquals(1, results.getMessages(Level.ERROR).size());
    assertEquals("1.0.0", ((InternalKieContainer) kieContainer).getContainerReleaseId().getVersion());
}
Also used : Results(org.kie.api.builder.Results) KieServices(org.kie.api.KieServices) InternalKieContainer(org.drools.core.impl.InternalKieContainer) ReleaseId(org.kie.api.builder.ReleaseId) InternalKieContainer(org.drools.core.impl.InternalKieContainer) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 17 with Results

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

the class Misc2Test method testMultilineStatement.

@Test
public void testMultilineStatement() {
    // BZ-1092502
    String str = "rule \"test\"\n" + "dialect \"mvel\"\n" + "when\n" + "then\n" + "System  \n" + "  .out  \n" + "  .println(\"hello\");\n" + "end\n";
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", str);
    Results results = ks.newKieBuilder(kfs).buildAll().getResults();
    assertEquals(0, results.getMessages().size());
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Results(org.kie.api.builder.Results) KnowledgeBuilderResults(org.kie.internal.builder.KnowledgeBuilderResults) KieServices(org.kie.api.KieServices) Test(org.junit.Test)

Example 18 with Results

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

the class MessageImplTests method testMessageFromInvalidDSL.

@Test
public // See DROOLS-193 (KnowledgeBuilderResult does not always contain a Resource)
void testMessageFromInvalidDSL() throws Exception {
    // Some suitably duff DSL
    String dsl = "bananna\n";
    // Some suitably valid DRL
    String drl = "import org.drools.compiler.Person;\n" + "rule R1\n" + "when\n" + "There is a Person\n" + "then\n" + "end\n";
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/dsl.dsl", dsl).write("src/main/resources/drl.dslr", drl);
    KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
    Results results = kieBuilder.getResults();
    assertEquals(3, results.getMessages().size());
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Results(org.kie.api.builder.Results) IncrementalResults(org.kie.internal.builder.IncrementalResults) KieServices(org.kie.api.KieServices) InternalKieBuilder(org.kie.internal.builder.InternalKieBuilder) KieBuilder(org.kie.api.builder.KieBuilder) Test(org.junit.Test)

Example 19 with Results

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

the class CommonTestMethodBase method createJar.

public static byte[] createJar(KieServices ks, String kmoduleContent, Predicate<String> classFilter, ReleaseId releaseId, Resource... resources) {
    KieFileSystem kfs = ks.newKieFileSystem().generateAndWritePomXML(releaseId).writeKModuleXML(kmoduleContent);
    for (int i = 0; i < resources.length; i++) {
        if (resources[i] != null) {
            kfs.write(resources[i]);
        }
    }
    KieBuilder kieBuilder = ks.newKieBuilder(kfs);
    ((InternalKieBuilder) kieBuilder).buildAll(classFilter);
    Results results = kieBuilder.getResults();
    if (results.hasMessages(Message.Level.ERROR)) {
        throw new IllegalStateException(results.getMessages(Message.Level.ERROR).toString());
    }
    InternalKieModule kieModule = (InternalKieModule) ks.getRepository().getKieModule(releaseId);
    byte[] jar = kieModule.getBytes();
    return jar;
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) InternalKieBuilder(org.kie.internal.builder.InternalKieBuilder) Results(org.kie.api.builder.Results) InternalKieBuilder(org.kie.internal.builder.InternalKieBuilder) KieBuilder(org.kie.api.builder.KieBuilder) InternalKieModule(org.drools.compiler.kie.builder.impl.InternalKieModule)

Example 20 with Results

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

the class KnowledgeBuilderTest method testMalformedDrl.

@Test
public void testMalformedDrl() throws Exception {
    // DROOLS-928
    byte[] content = new byte[] { 0x04, 0x44, 0x00, 0x00, 0x60, 0x00, 0x00, 0x00 };
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", new String(content));
    Results results = ks.newKieBuilder(kfs).buildAll().getResults();
    assertTrue(results.getMessages().size() > 0);
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Results(org.kie.api.builder.Results) KieServices(org.kie.api.KieServices) Test(org.junit.Test)

Aggregations

Results (org.kie.api.builder.Results)92 Test (org.junit.Test)81 KieServices (org.kie.api.KieServices)72 KieFileSystem (org.kie.api.builder.KieFileSystem)60 KieContainer (org.kie.api.runtime.KieContainer)36 KieBuilder (org.kie.api.builder.KieBuilder)32 KieSession (org.kie.api.runtime.KieSession)25 IncrementalResults (org.kie.internal.builder.IncrementalResults)20 ReleaseId (org.kie.api.builder.ReleaseId)19 QueryResults (org.kie.api.runtime.rule.QueryResults)17 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)15 KieBase (org.kie.api.KieBase)14 InternalKieBuilder (org.kie.internal.builder.InternalKieBuilder)13 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)11 KieHelper (org.kie.internal.utils.KieHelper)11 KieModuleModel (org.kie.api.builder.model.KieModuleModel)10 FactType (org.kie.api.definition.type.FactType)10 ArrayList (java.util.ArrayList)9 FlatQueryResults (org.drools.core.runtime.rule.impl.FlatQueryResults)9 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)7