use of org.kie.api.KieServices in project drools by kiegroup.
the class IncrementalCompilationTest method testIncrementalCompilationAddErrorThenRemoveIt.
@Test
public void testIncrementalCompilationAddErrorThenRemoveIt() throws Exception {
// Fact Type is unknown ("NonExistentClass" not "Message")
String drl1 = "package org.drools.compiler\n" + "rule R1 when\n" + " $m : NonExistentClass()\n" + "then\n" + "end\n";
// Field is unknown ("nonExistentField" not "message")
String drl2_1 = "package org.drools.compiler\n" + "rule R2_1 when\n" + " $m : Message( nonExistentField == \"Hello World\" )\n" + "then\n" + "end\n";
// Valid
String drl2_2 = "package org.drools.compiler\n" + "rule R2_2 when\n" + " $m : Message( message == \"Hello World\" )\n" + "then\n" + "end\n";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", drl1);
// Initial file contains errors
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
assertEquals(1, 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);
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 relating to updated file
kfs.write("src/main/resources/r2.drl", drl2_2);
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.api.KieServices in project drools by kiegroup.
the class IncrementalCompilationTest method testSegmentMergeOnRuleRemovalWithNotExistingSegment.
@Test
public void testSegmentMergeOnRuleRemovalWithNotExistingSegment() throws Exception {
// DROOLS-950
String drl1 = "rule R1 when\n" + " $i : Integer()\n" + " $s : String( length == $i )\n" + "then\n" + "end\n" + "rule R2 when\n" + " $i : Integer()\n" + " $l : Long( this > $i )\n" + "then\n" + "end\n";
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.1");
KieModule km = createAndDeployJar(ks, releaseId1, drl1);
KieContainer kc = ks.newKieContainer(km.getReleaseId());
KieSession ksession = kc.newKieSession();
kc.updateToVersion(releaseId1);
ksession.insert("Test");
ksession.insert(4L);
ksession.fireAllRules();
ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.2");
km = createAndDeployJar(ks, releaseId2);
kc.updateToVersion(releaseId2);
}
use of org.kie.api.KieServices in project drools by kiegroup.
the class IncrementalCompilationTest method testIncrementalCompilationChangeingParentRule.
@Test
public void testIncrementalCompilationChangeingParentRule() throws Exception {
// DROOLS-1031
String drl1_1 = "rule R1 when\n" + " $s : String( this == \"s1\" )\n" + "then\n" + "end\n";
String drl1_2 = "rule R1 when\n" + " $s : String( this == \"s2\" )\n" + "then\n" + "end\n";
String drl2 = "rule R2 extends R1 when\n" + " $i : Integer()\n" + "then\n" + "end\n";
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-extends", "1.1.1");
KieModule km = createAndDeployJar(ks, releaseId1, drl1_1 + drl2);
KieContainer kc = ks.newKieContainer(km.getReleaseId());
KieSession ksession = kc.newKieSession();
ksession.insert(1);
ksession.insert("s2");
assertEquals(0, ksession.fireAllRules());
ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-extends", "1.1.2");
km = createAndDeployJar(ks, releaseId2, drl1_2 + drl2);
kc.updateToVersion(releaseId2);
assertEquals(2, ksession.fireAllRules());
}
use of org.kie.api.KieServices in project drools by kiegroup.
the class IncrementalCompilationTest method testGlobalRemovedAndAdded.
@Test
public void testGlobalRemovedAndAdded() throws Exception {
// RHDM-311
String drlAWithGlobal = "package org.x.a\nglobal Boolean globalBool\n";
String drlANoGlobal = "package org.x.a\n";
String drlBWithGlobal = "package org.x.b\nglobal Boolean globalBool\n";
String drlBNoGlobal = "package org.x.b\n";
KieServices ks = KieServices.Factory.get();
ReleaseId releaseId1 = ks.newReleaseId("org.kie", "test-upgrade", "1.0.0");
KieModule km = createAndDeployJar(ks, releaseId1, drlAWithGlobal, drlBNoGlobal);
KieContainer kc = ks.newKieContainer(releaseId1);
KieSession ksession = kc.newKieSession();
ksession.setGlobal("globalBool", Boolean.FALSE);
ReleaseId releaseId2 = ks.newReleaseId("org.kie", "test-upgrade", "1.1.0");
createAndDeployJar(ks, releaseId2, drlANoGlobal, drlBWithGlobal);
kc.updateToVersion(releaseId2);
ksession.setGlobal("globalBool", Boolean.TRUE);
}
use of org.kie.api.KieServices in project drools by kiegroup.
the class IncrementalCompilationTest method testIncrementalCompilationAddErrorThenEmptyWithoutError.
@Test
public void testIncrementalCompilationAddErrorThenEmptyWithoutError() throws Exception {
// BZ-1009369
// Invalid. Type "Smurf" is unknown
String drl1 = "Smurf";
// Valid
String drl2 = "package org.drools.compiler\n" + "rule R2_2 when\n" + " $m : Message( message == \"Hello World\" )\n" + "then\n" + "end\n";
KieServices ks = KieServices.Factory.get();
// Add file with error - expect 2 build messages
KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", drl1);
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
assertEquals(2, kieBuilder.getResults().getMessages(org.kie.api.builder.Message.Level.ERROR).size());
// Add empty file - expect no "added" messages and no "removed" messages
kfs.write("src/main/resources/r2.drl", "");
IncrementalResults addResults1 = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/r2.drl").build();
assertEquals(0, addResults1.getAddedMessages().size());
assertEquals(0, addResults1.getRemovedMessages().size());
// Update file with no errors - expect no "added" messages and no "removed" messages
kfs.write("src/main/resources/r2.drl", drl2);
IncrementalResults addResults2 = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/r2.drl").build();
assertEquals(0, addResults2.getAddedMessages().size());
assertEquals(0, addResults2.getRemovedMessages().size());
}
Aggregations