Search in sources :

Example 46 with Results

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

the class AccumulateTest method testFromAccumulateWithoutSeparator.

@Test
public void testFromAccumulateWithoutSeparator() throws Exception {
    // DROOLS-602
    String str = "rule R when\n" + "    $count : Number( ) from accumulate (\n" + "        $s: String()\n" + "        count($s)\n" + "    )\n" + "then\n" + "    System.out.println($count);\n" + "end";
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", str);
    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) Test(org.junit.Test)

Example 47 with Results

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

the class LengthSlidingWindowTest method testCompilationFailureWithUnknownWindow.

@Test
public void testCompilationFailureWithUnknownWindow() {
    // DROOLS-841
    String drl = "import " + StockTick.class.getCanonicalName() + "\n" + "global java.util.List list;\n" + "declare StockTick @role( event ) end\n" + "declare window RhtStocksWindow\n" + "    StockTick() over window:length( 3 )\n" + "end\n" + "rule R\n" + "when \n" + "   accumulate( StockTick( company == \"RHT\", $price : price ) from window AbcStocksWindow; $total : sum($price) )\n" + "then \n" + "    list.add($total);\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();
    assertEquals(1, results.getMessages().size());
}
Also used : StockTick(org.drools.compiler.StockTick) KieFileSystem(org.kie.api.builder.KieFileSystem) Results(org.kie.api.builder.Results) KieServices(org.kie.api.KieServices) Test(org.junit.Test)

Example 48 with Results

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

the class MessageImplTests method testMessageWithIncrementalBuild.

@Test
public void testMessageWithIncrementalBuild() throws Exception {
    // Some suitably duff DSL to generate errors
    String dsl1 = "bananna\n";
    // Some suitably valid DRL
    String drl1 = "import org.drools.compiler.Person;\n" + "rule R1\n" + "when\n" + "There is a Person\n" + "then\n" + "end\n";
    // Some suitably valid DRL
    String drl2 = "rule R2\n" + "when\n" + "then\n" + "end\n";
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/dsl.dsl", dsl1).write("src/main/resources/drl.dslr", drl1);
    KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
    Results fullBuildResults = kieBuilder.getResults();
    assertEquals(3, fullBuildResults.getMessages().size());
    kfs.write("src/main/resources/r2.drl", drl2);
    IncrementalResults incrementalBuildResults = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/r2.drl").build();
    assertEquals(0, incrementalBuildResults.getAddedMessages().size());
    assertEquals(0, incrementalBuildResults.getRemovedMessages().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) IncrementalResults(org.kie.internal.builder.IncrementalResults) Test(org.junit.Test)

Example 49 with Results

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

the class DslTest method testGreedyDsl.

@Test
public void testGreedyDsl() {
    // BZ-1078839
    String dsl = "[when]There is a number with value of {value}=i:Integer(intValue() == {value})\n" + "[when]There is a number with=i:Integer()\n";
    String dslr = "package org.test \n" + "rule 'sample rule' \n" + "when \n" + "  There is a number with value of 10\n" + "then \n" + "end \n";
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.dslr", dslr).write("src/main/resources/r1.dsl", dsl);
    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) KieServices(org.kie.api.KieServices) Test(org.junit.Test)

Example 50 with Results

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

the class EnumTest method testEnumsWithCompositeBuildingProcess.

@Test
public void testEnumsWithCompositeBuildingProcess() throws Exception {
    final String drl = "package org.test; " + "" + "declare enum DaysOfWeek " + "    SUNDAY, MONDAY, TUESDAY, WEDNESDAY, THURSDAY, FRIDAY, SATURDAY;\n" + "end\n" + "declare Test " + "  field: DaysOfWeek " + "end";
    final KieHelper kieHelper = new KieHelper();
    kieHelper.addContent(drl, ResourceType.DRL);
    final Results res = kieHelper.verify();
    assertEquals(0, res.getMessages().size());
}
Also used : Results(org.kie.api.builder.Results) KieHelper(org.kie.internal.utils.KieHelper) 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