use of org.kie.internal.builder.IncrementalResults in project drools by kiegroup.
the class KieModuleIncrementalCompilationTest method checkIncrementalCompilationWithRuleFunctionRule.
@Test
public void checkIncrementalCompilationWithRuleFunctionRule() throws Exception {
String rule_1 = "package org.kie.scanner\n" + "rule R1 when\n" + " String()\n" + "then\n" + "end\n";
String rule_2 = "package org.kie.scanner\n" + "rule R1 when\n" + " String()\n" + "then\n" + " System.out.println(MyFunction());\n" + "end\n";
String function = "package org.kie.scanner\n" + "function int MyFunction() {\n" + " return 1;\n" + "}\n";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
kfs.write("src/main/resources/org/kie/scanner/rule.drl", rule_1);
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
assertEquals(0, kieBuilder.getResults().getMessages(org.kie.api.builder.Message.Level.ERROR).size());
kfs.write("src/main/resources/org/kie/scanner/function.drl", function);
IncrementalResults addResults1 = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/org/kie/scanner/function.drl").build();
assertEquals(0, addResults1.getAddedMessages().size());
assertEquals(0, addResults1.getRemovedMessages().size());
kfs.write("src/main/resources/org/kie/scanner/rule.drl", rule_2);
IncrementalResults addResults2 = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/org/kie/scanner/rule.drl").build();
assertEquals(0, addResults2.getAddedMessages().size());
assertEquals(0, addResults2.getRemovedMessages().size());
}
use of org.kie.internal.builder.IncrementalResults in project drools by kiegroup.
the class KieModuleIncrementalCompilationTest method checkIncrementalCompilationWithMultipleKieBases.
@Test
public void checkIncrementalCompilationWithMultipleKieBases() throws Exception {
String rule = "package org.kie.scanner\n" + "rule R1 when\n" + "then\n" + "end\n";
String invalidRule = "package org.kie.scanner\n" + "rule R2 when\n" + // missing import
" Cheese()\n" + "then\n" + "end\n";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = createKieFileSystemWithTwoKBases(ks);
kfs.write("src/main/resources/org/kie/scanner/rule.drl", rule);
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
assertEquals(0, kieBuilder.getResults().getMessages().size());
kfs.write("src/main/resources/org/kie/scanner/invalidRule.drl", invalidRule);
IncrementalResults addResults = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/org/kie/scanner/invalidRule.drl").build();
assertEquals(2, addResults.getAddedMessages().size());
addResults.getAddedMessages().stream().map(m -> (MessageImpl) m).forEach(m -> assertNotNull(m.getKieBaseName()));
}
use of org.kie.internal.builder.IncrementalResults in project drools by kiegroup.
the class KieModuleIncrementalCompilationTest method testCheckMetaDataAfterIncrementalDelete.
@Test
public void testCheckMetaDataAfterIncrementalDelete() throws Exception {
String drl1 = "package org.kie.scanner\n" + "rule R1 when\n" + " String()\n" + "then\n" + "end\n";
String drl2 = "package org.kie.scanner\n" + "rule R2_2 when\n" + " String( )\n" + "then\n" + "end\n";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/r1.drl", drl1).write("src/main/resources/r2.drl", drl2);
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
assertEquals(2, getRuleNames(kieBuilder).get("org.kie.scanner").size());
kfs.delete("src/main/resources/r2.drl");
IncrementalResults addResults = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/r2.drl").build();
assertEquals(1, getRuleNames(kieBuilder).get("org.kie.scanner").size());
}
use of org.kie.internal.builder.IncrementalResults in project drools by kiegroup.
the class IncrementalCompilationTest method testIncrementalCompilationDuplicateXLSResources.
@Test
public void testIncrementalCompilationDuplicateXLSResources() throws Exception {
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
InputStream in1 = null;
InputStream in2 = null;
try {
// Add XLS decision table
in1 = this.getClass().getResourceAsStream("incrementalBuild.dtable.xls");
kfs.write("src/main/resources/incrementalBuild1.dtable.xls", KieServices.Factory.get().getResources().newInputStreamResource(in1));
// Expect no errors
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
assertEquals(0, kieBuilder.getResults().getMessages(org.kie.api.builder.Message.Level.ERROR).size());
// Add the same XLS decision table again as a different resource
in2 = this.getClass().getResourceAsStream("incrementalBuild.dtable.xls");
kfs.write("src/main/resources/incrementalBuild2.dtable.xls", KieServices.Factory.get().getResources().newInputStreamResource(in2));
IncrementalResults addResults = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/incrementalBuild2.dtable.xls").build();
// Expect duplicate rule errors
assertEquals(1, addResults.getAddedMessages().size());
assertEquals(0, addResults.getRemovedMessages().size());
// Check errors on a full build
List<Message> messages = ks.newKieBuilder(kfs).buildAll().getResults().getMessages();
assertFalse(messages.isEmpty());
} finally {
if (in1 != null) {
in1.close();
}
if (in2 != null) {
in2.close();
}
}
}
use of org.kie.internal.builder.IncrementalResults in project drools by kiegroup.
the class IncrementalCompilationTest method testIncrementalCompilationWithAddedError.
@Test
public void testIncrementalCompilationWithAddedError() {
final String drl1 = "package org.drools.compiler\n" + "import " + Message.class.getCanonicalName() + ";\n" + "rule R1 when\n" + " $m : Message()\n" + "then\n" + "end\n";
final String drl2_1 = "package org.drools.compiler\n" + "import " + Message.class.getCanonicalName() + ";\n" + "rule R2_1 when\n" + " $m : Message( message == \"Hi Universe\" )\n" + "then\n" + "end\n";
final String drl2_2 = "package org.drools.compiler\n" + "import " + Message.class.getCanonicalName() + ";\n" + "rule R2_2 when\n" + " $m : Message( nonExistentField == \"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).write("src/main/resources/r2.drl", drl2_1);
final KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll(DrlProject.class);
final KieContainer kieContainer = ks.newKieContainer(ks.getRepository().getDefaultReleaseId());
KieSession ksession = kieContainer.newKieSession();
ksession.insert(new Message("Hello World"));
assertEquals(1, ksession.fireAllRules());
kfs.write("src/main/resources/r2.drl", drl2_2);
final IncrementalResults results = ((InternalKieBuilder) kieBuilder).createFileSet("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(new Message("Hello World"));
assertEquals(1, ksession.fireAllRules());
}
Aggregations