Search in sources :

Example 21 with Results

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

the class AbductionTest method testBindNonAbductiveQueryError.

@Test
public void testBindNonAbductiveQueryError() {
    String droolsSource = "package org.drools.abductive.test; \n" + "" + "" + "query foo() \n" + "end \n" + "rule R1 " + "when " + "   $x : foo( ) " + "then " + "end \n" + "";
    // ///////////////////////////////////
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem();
    kfs.write(ks.getResources().newByteArrayResource(droolsSource.getBytes()).setSourcePath("drl1.drl").setResourceType(ResourceType.DRL));
    KieBuilder kieBuilder = ks.newKieBuilder(kfs);
    kieBuilder.buildAll();
    Results res = kieBuilder.getResults();
    assertTrue(res.hasMessages(Message.Level.ERROR));
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) QueryResults(org.kie.api.runtime.rule.QueryResults) FlatQueryResults(org.drools.core.runtime.rule.impl.FlatQueryResults) Results(org.kie.api.builder.Results) KieServices(org.kie.api.KieServices) KieBuilder(org.kie.api.builder.KieBuilder) Test(org.junit.Test)

Example 22 with Results

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

the class AbductionTest method testAbductiveLogicWithNonExistingArgsMapping.

@Test
public void testAbductiveLogicWithNonExistingArgsMapping() {
    String droolsSource = "package org.drools.abductive.test; \n" + "" + "import " + Abducible.class.getName() + "; \n" + "global java.util.List list; \n" + "" + "declare Foo \n" + "   @Abducible \n" + "   id : String @key \n" + "   name : String @key \n" + "end \n" + "query foo( String $name ) \n" + "   @Abductive( target=Foo.class, args={ $missing, $name } ) \n" + "end \n" + "";
    // ///////////////////////////////////
    KieHelper kieHelper = new KieHelper();
    kieHelper.addContent(droolsSource, ResourceType.DRL);
    Results res = kieHelper.verify();
    assertEquals(1, res.getMessages(Message.Level.ERROR).size());
}
Also used : QueryResults(org.kie.api.runtime.rule.QueryResults) FlatQueryResults(org.drools.core.runtime.rule.impl.FlatQueryResults) Results(org.kie.api.builder.Results) KieHelper(org.kie.internal.utils.KieHelper) Abducible(org.drools.core.beliefsystem.abductive.Abducible) Test(org.junit.Test)

Example 23 with Results

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

the class AbductionTest method getSessionFromString.

protected KieSession getSessionFromString(String drlString, KieBaseConfiguration kbConf) {
    KieHelper kieHelper = new KieHelper();
    kieHelper.addContent(drlString, ResourceType.DRL);
    Results res = kieHelper.verify();
    if (res.hasMessages(Message.Level.ERROR)) {
        fail(res.getMessages(Message.Level.ERROR).toString());
    }
    if (kbConf == null) {
        kbConf = KieServices.Factory.get().newKieBaseConfiguration();
    }
    kbConf.setOption(EqualityBehaviorOption.EQUALITY);
    KieBase kieBase = kieHelper.build(kbConf);
    KieSessionConfiguration ksConf = KnowledgeBaseFactory.newKnowledgeSessionConfiguration();
    ((SessionConfiguration) ksConf).setBeliefSystemType(BeliefSystemType.DEFEASIBLE);
    return kieBase.newKieSession(ksConf, null);
}
Also used : QueryResults(org.kie.api.runtime.rule.QueryResults) FlatQueryResults(org.drools.core.runtime.rule.impl.FlatQueryResults) Results(org.kie.api.builder.Results) KieBase(org.kie.api.KieBase) KieHelper(org.kie.internal.utils.KieHelper) KieSessionConfiguration(org.kie.api.runtime.KieSessionConfiguration) KieSessionConfiguration(org.kie.api.runtime.KieSessionConfiguration) SessionConfiguration(org.drools.core.SessionConfiguration)

Example 24 with Results

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

the class AccumulateTest method testIncompatibleTypeOnAccumulateFunction.

@Test
public void testIncompatibleTypeOnAccumulateFunction() {
    // DROOLS-1243
    String drl = "import " + MyPerson.class.getCanonicalName() + ";\n" + "import " + BigDecimal.class.getCanonicalName() + ";\n" + "global java.util.List list;\n" + "rule R when\n" + "  $theFrom : BigDecimal() from accumulate(MyPerson( $val : age ); \n" + "                                          sum( $val ) )\n" + "then\n" + "  list.add($theFrom);\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) QueryResults(org.kie.api.runtime.rule.QueryResults) Results(org.kie.api.builder.Results) KieServices(org.kie.api.KieServices) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 25 with Results

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

the class KieBaseTest method testKieBaseCompilation.

@Test
public void testKieBaseCompilation() {
    KieServices ks = KieServices.Factory.get();
    Results rs = ks.getKieClasspathContainer().verify();
    System.out.println(rs.getMessages());
    assertFalse(rs.hasMessages(Message.Level.ERROR));
}
Also used : 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