use of org.kie.internal.builder.IncrementalResults in project drools by kiegroup.
the class IncrementalCompilationTest method testIncrementalCompilationWithExtendsRule.
@Test
public void testIncrementalCompilationWithExtendsRule() {
// DROOLS-1405
final String drl1 = "rule \"test1\" when then end\n";
final String drl2 = "rule \"test2\" extends \"test1\" when then end\n" + "rule \"test3\" extends \"test1\" when then end\n";
final KieServices ks = KieServices.Factory.get();
final KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", drl1);
final KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll(DrlProject.class);
assertEquals(0, kieBuilder.getResults().getMessages(org.kie.api.builder.Message.Level.ERROR).size());
kfs.write("src/main/resources/r2.drl", drl2);
final IncrementalResults addResults = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/r2.drl").build();
assertEquals(0, addResults.getAddedMessages().size());
}
use of org.kie.internal.builder.IncrementalResults in project drools by kiegroup.
the class IncrementalCompilationTest method testIncrementalCompilationFromEmptyProject.
@Test
public void testIncrementalCompilationFromEmptyProject() {
// DROOLS-5547
final String drl1 = "rule \"test1\" when then end\n";
final String drl2 = "rule \"test2\" extends \"test1\" when then end\n" + "rule \"test3\" extends \"test1\" when then end\n";
final KieServices ks = KieServices.Factory.get();
final KieFileSystem kfs = ks.newKieFileSystem();
final KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll(DrlProject.class);
assertEquals(0, kieBuilder.getResults().getMessages(org.kie.api.builder.Message.Level.ERROR).size());
kfs.write("src/main/resources/r1.drl", drl1);
final IncrementalResults addResults1 = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/r1.drl").build();
assertEquals(0, addResults1.getAddedMessages().size());
kfs.write("src/main/resources/r2.drl", drl2);
final IncrementalResults addResults2 = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/r2.drl").build();
assertEquals(0, addResults2.getAddedMessages().size());
}
use of org.kie.internal.builder.IncrementalResults in project drools by kiegroup.
the class IncrementalCompilationTest method testIncrementalCompilationRemovingParentRule.
@Test
public void testIncrementalCompilationRemovingParentRule() {
// DROOLS-1031
final String drl1 = "package org.drools.compiler\n" + "rule R1 when\n" + " $s : String()\n" + "then\n" + "end\n";
final String drl2 = "package org.drools.compiler\n" + "rule R2 extends R1 when\n" + " $i : Integer()\n" + "then\n" + "end\n";
final KieServices ks = KieServices.Factory.get();
final KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", drl1).write("src/main/resources/r2.drl", drl2);
final KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll(DrlProject.class);
final KieContainer kieContainer = ks.newKieContainer(ks.getRepository().getDefaultReleaseId());
KieSession ksession = kieContainer.newKieSession();
ksession.insert("test");
ksession.insert(1);
assertEquals(2, ksession.fireAllRules());
kfs.delete("src/main/resources/r1.drl");
final IncrementalResults results = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/r1.drl", "src/main/resources/r2.drl").build();
assertEquals(1, results.getAddedMessages().size());
assertEquals(0, results.getRemovedMessages().size());
kieContainer.updateToVersion(ks.getRepository().getDefaultReleaseId());
ksession = kieContainer.newKieSession();
ksession.insert("test");
ksession.insert(1);
assertEquals(2, ksession.fireAllRules());
}
use of org.kie.internal.builder.IncrementalResults in project drools by kiegroup.
the class IncrementalCompilationTest method testIncrementalCompilationAddErrorThenRemoveError.
@Test
public void testIncrementalCompilationAddErrorThenRemoveError() {
// Valid
final String drl1 = "package org.drools.compiler\n" + "import " + Message.class.getCanonicalName() + ";\n" + "rule R1 when\n" + " $m : Message()\n" + "then\n" + "end\n";
// Field is unknown ("nonExistentField" not "message")
final String drl2_1 = "package org.drools.compiler\n" + "import " + Message.class.getCanonicalName() + ";\n" + "rule R2_1 when\n" + " $m : Message( nonExistentField == \"Hello World\" )\n" + "then\n" + "end\n";
// Valid
final String drl2_2 = "package org.drools.compiler\n" + "import " + Message.class.getCanonicalName() + ";\n" + "rule R2_2 when\n" + " $m : Message( message == \"Hello World\" )\n" + "then\n" + "end\n";
final KieServices ks = KieServices.Factory.get();
final KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", drl1);
final KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll(DrlProject.class);
assertEquals(0, kieBuilder.getResults().getMessages(org.kie.api.builder.Message.Level.ERROR).size());
// Add file with error - expect 1 "added" error message
kfs.write("src/main/resources/r2.drl", drl2_1);
final IncrementalResults addResults = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/r2.drl").build();
assertEquals(1, addResults.getAddedMessages().size());
assertEquals(0, addResults.getRemovedMessages().size());
// Update flawed file with correct version - expect 0 "added" error messages and removal of 1 previous error
kfs.write("src/main/resources/r2.drl", drl2_2);
final IncrementalResults removeResults = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/r2.drl").build();
assertEquals(0, removeResults.getAddedMessages().size());
assertEquals(1, removeResults.getRemovedMessages().size());
}
use of org.kie.internal.builder.IncrementalResults in project drools by kiegroup.
the class IncrementalCompilationTest method testIncrementalCompilationWithIncludes.
@Test
public void testIncrementalCompilationWithIncludes() {
// DROOLS-462
final String drl1 = "global java.util.List list\n" + "rule R1 when\n" + " $s : String() " + "then\n" + " list.add( \"a\" + $s );" + "end\n";
final String drl2 = "global java.util.List list\n" + "rule R1 when\n" + " $s : String() " + "then\n" + " list.add( \"b\" + $s );" + "end\n";
final ReleaseId releaseId = KieServices.Factory.get().newReleaseId("org.test", "test", "1.0.0");
final KieServices ks = KieServices.Factory.get();
final KieModuleModel kproj = ks.newKieModuleModel();
final KieBaseModel kieBaseModel1 = kproj.newKieBaseModel("KBase1").addPackage("org.pkg1");
kieBaseModel1.newKieSessionModel("KSession1");
final KieBaseModel kieBaseModel2 = kproj.newKieBaseModel("KBase2").addPackage("org.pkg2").addInclude("KBase1");
kieBaseModel2.newKieSessionModel("KSession2");
final KieFileSystem kfs = ks.newKieFileSystem().generateAndWritePomXML(releaseId).write("src/main/resources/KBase1/org/pkg1/r1.drl", drl1).writeKModuleXML(kproj.toXML());
final KieBuilder kieBuilder = ks.newKieBuilder(kfs);
kieBuilder.buildAll(DrlProject.class);
assertEquals(0, kieBuilder.getResults().getMessages().size());
final KieContainer kc = ks.newKieContainer(releaseId);
final KieSession ksession = kc.newKieSession("KSession2");
final List<String> list = new ArrayList<>();
ksession.setGlobal("list", list);
ksession.insert("Foo");
ksession.fireAllRules();
assertEquals(1, list.size());
assertEquals("aFoo", list.get(0));
list.clear();
kfs.delete("src/main/resources/KBase1/org/pkg1/r1.drl");
kfs.write("src/main/resources/KBase1/org/pkg1/r2.drl", drl2);
final IncrementalResults results = ((InternalKieBuilder) kieBuilder).incrementalBuild();
assertEquals(0, results.getAddedMessages().size());
final Results updateResults = kc.updateToVersion(releaseId);
assertEquals(0, updateResults.getMessages().size());
ksession.insert("Bar");
ksession.fireAllRules();
assertEquals(2, list.size());
assertTrue(list.containsAll(asList("bBar", "bFoo")));
}
Aggregations