use of org.kie.internal.builder.InternalKieBuilder 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.InternalKieBuilder in project drools by kiegroup.
the class KieModuleIncrementalCompilationTest method checkIncrementalCompilationWithRuleThenFunction.
@Test
public void checkIncrementalCompilationWithRuleThenFunction() throws Exception {
String rule = "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);
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
assertEquals(1, 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(1, addResults1.getRemovedMessages().size());
}
use of org.kie.internal.builder.InternalKieBuilder 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.InternalKieBuilder 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.InternalKieBuilder in project drools by kiegroup.
the class GuidedScoreCardIntegrationJavaClassesOnClassPathTest method testIncrementalCompilation.
@Test
public void testIncrementalCompilation() throws Exception {
String xml1_1 = Helper.createEmptyGuidedScoreCardXML();
String xml1_2 = Helper.createGuidedScoreCardXML();
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
kfs.write("pom.xml", Helper.getPom());
kfs.write("src/main/resources/META-INF/kmodule.xml", Helper.getKModule());
kfs.write("src/main/resources/sc1.scgd", xml1_1);
// Add empty Score Card
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
final List<Message> messages = kieBuilder.getResults().getMessages();
Helper.dumpMessages(messages);
assertEquals(0, messages.size());
// Update with complete Score Card
kfs.write("src/main/resources/sc1.scgd", xml1_2);
IncrementalResults results = ((InternalKieBuilder) kieBuilder).incrementalBuild();
final List<Message> addedMessages = results.getAddedMessages();
final List<Message> removedMessages = results.getRemovedMessages();
Helper.dumpMessages(addedMessages);
assertEquals(0, addedMessages.size());
Helper.dumpMessages(removedMessages);
assertEquals(0, removedMessages.size());
}
Aggregations