Search in sources :

Example 6 with Results

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

the class IncrementalCompilationTest method testIncrementalCompilation.

private void testIncrementalCompilation(ReleaseId releaseId1, ReleaseId releaseId2, boolean useDeclaredType) {
    String drl1 = "package org.drools.compiler\n" + "global java.util.List list\n" + "rule R0 when then list.add( \"000\" ); end \n" + "" + "rule R1 when\n" + " $s : String() " + "then\n" + " list.add( \"a\" + $s );" + "end\n";
    String drl2 = useDeclaredType ? "package org.drools.compiler\n" + "global java.util.List list\n" + "declare StringWrapper\n" + " s : String\n" + "end\n" + "rule RInit when\n" + " $s : String() \n" + "then\n" + " insert( new StringWrapper( $s ) );" + "end\n" + "rule R2 when\n" + " $s : StringWrapper() \n" + "then\n" + " list.add( \"b\" + $s.getS() );" + "end\n" : "package org.drools.compiler\n" + "global java.util.List list\n" + "rule R2 when\n" + " $s : String() \n" + "then\n" + " list.add( \"b\" + $s );" + "end\n";
    KieServices ks = KieServices.Factory.get();
    createAndDeployJar(ks, releaseId1, drl1);
    KieContainer kc = ks.newKieContainer(releaseId1);
    KieSession ksession = kc.newKieSession();
    List<String> list = new ArrayList<String>();
    ksession.setGlobal("list", list);
    ksession.insert("Foo");
    ksession.fireAllRules();
    assertEquals(2, list.size());
    assertTrue(list.containsAll(asList("000", "aFoo")));
    list.clear();
    createAndDeployJar(ks, releaseId2, drl1, drl2);
    Results updateResults = kc.updateToVersion(releaseId2);
    assertEquals(0, updateResults.getMessages().size());
    ksession.insert("Bar");
    ksession.fireAllRules();
    assertEquals(3, list.size());
    assertTrue(list.containsAll(asList("bBar", "bFoo", "aBar")));
}
Also used : IncrementalResults(org.kie.internal.builder.IncrementalResults) Results(org.kie.api.builder.Results) ArrayList(java.util.ArrayList) KieServices(org.kie.api.KieServices) StatelessKieSession(org.kie.api.runtime.StatelessKieSession) KieSession(org.kie.api.runtime.KieSession) KieContainer(org.kie.api.runtime.KieContainer)

Example 7 with Results

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

the class IncrementalCompilationTest method testAddPackageToKieBaseModel.

@Test
public void testAddPackageToKieBaseModel() throws Exception {
    // DROOLS-1287
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-remove-pkg", "1.0");
    ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-remove-pkg", "1.1");
    createKJarWIthPackages(ks, releaseId1, "pkg2");
    KieContainer container = ks.newKieContainer(releaseId1);
    KieSession ksession = container.newKieSession();
    List<String> list = new ArrayList<String>();
    ksession.setGlobal("list", list);
    ksession.insert("test");
    ksession.fireAllRules();
    assertEquals(1, list.size());
    assertTrue(list.containsAll(asList("R2")));
    createKJarWIthPackages(ks, releaseId2, "pkg1", "pkg2");
    Results results = container.updateToVersion(releaseId2);
    assertEquals(0, results.getMessages().size());
    ksession = container.newKieSession();
    list = new ArrayList<String>();
    ksession.setGlobal("list", list);
    ksession.insert("test");
    ksession.fireAllRules();
    assertEquals(2, list.size());
    assertTrue(list.containsAll(asList("R1", "R2")));
}
Also used : IncrementalResults(org.kie.internal.builder.IncrementalResults) Results(org.kie.api.builder.Results) ArrayList(java.util.ArrayList) KieServices(org.kie.api.KieServices) StatelessKieSession(org.kie.api.runtime.StatelessKieSession) KieSession(org.kie.api.runtime.KieSession) ReleaseId(org.kie.api.builder.ReleaseId) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 8 with Results

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

the class IncrementalCompilationTest method testIncrementalCompilationWithRedeclares.

@Test
public void testIncrementalCompilationWithRedeclares() {
    // DROOLS-363
    String drl1 = "package org.drools.compiler\n" + "global java.util.List list\n" + "" + "declare Fooz id : int end \n" + "" + "rule R0 when then insert( new Fooz( 1 ) ); end \n" + "" + "";
    String drl2 = "package org.drools.compiler\n" + "global java.util.List list\n" + "" + "declare Fooz id : int end \n" + "" + "declare Barz end \n" + "" + "rule R2 when then insert( new Fooz( 2 ) ); end \n" + "" + "rule R1 when\n" + " $f : Fooz() " + "then\n" + " list.add( $f.getId() );" + " System.out.println( \"Foo in \" + $f + \" >> \" + System.identityHashCode( $f.getClass() ) ); \n" + "end\n" + "";
    KieServices ks = KieServices.Factory.get();
    ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-upgrade", "1.0.0");
    ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.0");
    createAndDeployJar(ks, releaseId1, drl1);
    KieContainer kc = ks.newKieContainer(releaseId1);
    KieSession ksession = kc.newKieSession();
    List<String> list = new ArrayList<String>();
    ksession.setGlobal("list", list);
    ksession.fireAllRules();
    createAndDeployJar(ks, releaseId2, drl1, drl2);
    Results updateResults = kc.updateToVersion(releaseId2);
    assertEquals(0, updateResults.getMessages().size());
    ksession.fireAllRules();
    assertEquals(2, list.size());
}
Also used : IncrementalResults(org.kie.internal.builder.IncrementalResults) Results(org.kie.api.builder.Results) ArrayList(java.util.ArrayList) KieServices(org.kie.api.KieServices) StatelessKieSession(org.kie.api.runtime.StatelessKieSession) KieSession(org.kie.api.runtime.KieSession) ReleaseId(org.kie.api.builder.ReleaseId) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 9 with Results

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

the class RuleUnitTest method testNotExistingDataSource.

@Test
public void testNotExistingDataSource() throws Exception {
    String drl1 = "import " + Person.class.getCanonicalName() + "\n" + "import " + AdultUnit.class.getCanonicalName() + "\n" + "rule Adult @Unit( AdultUnit.class ) when\n" + "    Person(age >= 18, $name : name) from adults\n" + "then\n" + "    System.out.println($name + \" is adult\");\n" + "end";
    KieServices ks = KieServices.get();
    KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", drl1);
    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 10 with Results

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

the class StrictAnnotationTest method testImportedAnnotation.

@Test
public void testImportedAnnotation() throws Exception {
    String str = "package org.simple \n" + "import " + Xyz.class.getCanonicalName() + " \n" + "@Xyz rule yyy \n" + "when \n" + "  $s : String()\n" + "then \n" + "end  \n";
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", str).writeKModuleXML(ks.newKieModuleModel().setConfigurationProperty(LanguageLevelOption.PROPERTY_NAME, LanguageLevelOption.DRL6_STRICT.toString()).toXML());
    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)

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