Search in sources :

Example 81 with Results

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

the class OOPathReactiveTests method testInvalidDoubleNonReactivePart.

@Test
public void testInvalidDoubleNonReactivePart() {
    final String drl = "import org.drools.compiler.oopath.model.*;\n" + "global java.util.List list\n" + "\n" + "rule R when\n" + "  Man( $toy: /wife?/children[age > 10]?/toys )\n" + "then\n" + "  list.add( $toy.getName() );\n" + "end\n";
    final KieServices ks = KieServices.Factory.get();
    final KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", drl);
    final Results results = ks.newKieBuilder(kfs).buildAll().getResults();
    assertTrue(results.hasMessages(Message.Level.ERROR));
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Results(org.kie.api.builder.Results) KieServices(org.kie.api.KieServices) Test(org.junit.Test)

Example 82 with Results

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

the class FromTest method testFromWithInterfaceAndFinalClass.

@Test
public void testFromWithInterfaceAndFinalClass() {
    String drl = "import " + Container3.class.getCanonicalName() + "\n" + "import " + CustomIntegerMarker.class.getCanonicalName() + "\n" + "global java.util.List out;\n" + "rule R1 when\n" + "    $c3 : Container3( )\n" + "    $s : CustomIntegerMarker() from $c3.singleValue\n" + "then\n" + "    out.add($s);\n" + "end\n";
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", drl);
    Results results = ks.newKieBuilder(kfs).buildAll().getResults();
    // Integer is final class, so there cannot be ever the case of pattern matching in the `from` on a non-extended interface to ever match.
    assertFalse(results.getMessages().isEmpty());
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Results(org.kie.api.builder.Results) KieServices(org.kie.api.KieServices) Test(org.junit.Test)

Example 83 with Results

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

the class FromTest method testFromWithSingleValueAndIncompatibleType.

@Test
public void testFromWithSingleValueAndIncompatibleType() {
    // DROOLS-1243
    String drl = "import " + ListsContainer.class.getCanonicalName() + "\n" + "global java.util.List out;\n" + "rule R1 when\n" + "    $list : ListsContainer( )\n" + "    $s : String() from $list.singleValue\n" + "then\n" + "    out.add($s);\n" + "end\n";
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", drl);
    Results results = ks.newKieBuilder(kfs).buildAll().getResults();
    assertFalse(results.getMessages().isEmpty());
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Results(org.kie.api.builder.Results) KieServices(org.kie.api.KieServices) Test(org.junit.Test)

Example 84 with Results

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

the class KieHelper method createJar.

public static byte[] createJar(KieServices ks, ReleaseId releaseId, Resource... resources) {
    KieFileSystem kfs = ks.newKieFileSystem().generateAndWritePomXML(releaseId);
    for (int i = 0; i < resources.length; i++) {
        if (resources[i] != null) {
            kfs.write(resources[i]);
        }
    }
    KieBuilder kieBuilder = ks.newKieBuilder(kfs);
    ((InternalKieBuilder) kieBuilder).buildAll(o -> true);
    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 85 with Results

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

the class DMNRuntimeTypeCheckTest method getRuntimeWithTypeCheckOption.

private DMNRuntime getRuntimeWithTypeCheckOption(String typeCheckKModuleOption, Resource... resources) {
    final KieFileSystem kfs = ks.newKieFileSystem();
    KieModuleModel kmm = ks.newKieModuleModel();
    kmm.setConfigurationProperty(RuntimeTypeCheckOption.PROPERTY_NAME, typeCheckKModuleOption);
    kfs.writeKModuleXML(kmm.toXML());
    for (Resource r : resources) {
        kfs.write(r);
    }
    KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
    Results results = kieBuilder.getResults();
    assertThat(results.getMessages().toString(), results.hasMessages(org.kie.api.builder.Message.Level.ERROR), is(false));
    final KieContainer kieContainer = ks.newKieContainer(ks.getRepository().getDefaultReleaseId());
    final DMNRuntime runtime = kieContainer.newKieSession().getKieRuntime(DMNRuntime.class);
    return runtime;
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Results(org.kie.api.builder.Results) KieModuleModel(org.kie.api.builder.model.KieModuleModel) Resource(org.kie.api.io.Resource) KieBuilder(org.kie.api.builder.KieBuilder) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) KieContainer(org.kie.api.runtime.KieContainer)

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