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")));
}
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")));
}
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());
}
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());
}
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());
}
Aggregations