Search in sources :

Example 71 with Results

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

the class QueryTest method testQueryWithIncompatibleArgs.

@Test
public void testQueryWithIncompatibleArgs() {
    String drl = "global java.util.List list; " + "" + "query foo( String $s, String $s, String $s ) end " + "" + "rule React \n" + "when\n" + "  $i : Integer() " + "  foo( $i, $x, $i ; ) " + "then\n" + "end";
    KieHelper helper = new KieHelper();
    helper.addContent(drl, ResourceType.DRL);
    Results results = helper.verify();
    assertTrue(results.hasMessages(Message.Level.ERROR));
    assertEquals(2, results.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) Test(org.junit.Test)

Example 72 with Results

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

the class QueryTest method testNotExistingDeclarationInQuery.

@Test
public void testNotExistingDeclarationInQuery() {
    // DROOLS-414
    String drl = "import org.drools.compiler.Person\n" + "global java.util.List persons;\n" + "\n" + "query checkLength(String $s, int $l)\n" + "    $s := String( length == $l )\n" + "end\n" + "\n" + "rule R when\n" + "    $i : Integer()\n" + "    $p : Person()\n" + "    checkLength( $p.name, 1 + $x + $p.age; )\n" + "then\n" + "    persons.add( $p );\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) FlatQueryResults(org.drools.core.runtime.rule.impl.FlatQueryResults) Results(org.kie.api.builder.Results) KieServices(org.kie.api.KieServices) Test(org.junit.Test)

Example 73 with Results

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

the class AbductionTest method testAbductiveLogicWithWrongTypeArgsMapping.

@Test
public void testAbductiveLogicWithWrongTypeArgsMapping() {
    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, int $x ) \n" + "   @Abductive( target=Foo.class, args={ $x, $name } ) \n" + "end \n" + "rule R0 " + "when " + "   $f := foo( \"name_test\", 99 ; ) " + "then " + "   list.add( $f ); " + "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 74 with Results

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

the class AbductionTest method testAbductiveLogicNoConstructorFoundError.

@Test
public void testAbductiveLogicNoConstructorFoundError() {
    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 : Integer @key \n" + "end \n" + "query foo( String $x ) \n" + // Foo does not have a String constructor
    "   @Abductive( target=Foo.class ) \n" + "end \n" + "rule R1 " + "when " + "   $x : foo( \"x\" ; ) " + "then " + "   list.add( $x ); " + "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 75 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