use of org.kie.internal.builder.IncrementalResults in project drools by kiegroup.
the class IncrementalCompilationNonExecModelTest method testCreateFileSetWithDeclaredModel.
@Test
public void testCreateFileSetWithDeclaredModel() throws InstantiationException, IllegalAccessException {
final String drl1 = "package myPkg\n" + "declare StringWrapper\n" + " s : String\n" + "end\n";
// Requires 3 AlphaNodes to enable hash index
final String drl2_1 = DRL2_COMMON_SRC + "rule R2_C\n" + "when\n" + " $s : StringWrapper( s == \"Hi Universe\" )\n" + "then\n" + "end\n";
final String drl2_2 = DRL2_COMMON_SRC + "rule R2_C when\n" + " $s : StringWrapper( s == \"Hello World\" )\n" + "then\n" + " System.out.println(\"HIT\");\n" + "end\n";
final KieServices ks = KieServices.Factory.get();
final KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/myPkg/r1.drl", drl1).write("src/main/resources/myPkg/r2.drl", drl2_1);
ReleaseId releaseId1 = ks.newReleaseId("org.default", "artifact", "1.1.0");
kfs.generateAndWritePomXML(releaseId1);
KieBuilder kieBuilder = KieUtil.getKieBuilderFromKieFileSystem(kieBaseTestConfiguration, kfs, true);
final KieContainer kieContainer = ks.newKieContainer(releaseId1);
runRules(kieContainer, 1);
// ---------------------
kfs.delete("src/main/resources/myPkg/r2.drl");
kfs.write("src/main/resources/myPkg/r2.drl", drl2_2);
ReleaseId releaseId2 = ks.newReleaseId("org.default", "artifact", "1.2.0");
kfs.generateAndWritePomXML(releaseId2);
// buildAll instead of createFileSet doesn't have the issue
// if (kieBaseTestConfiguration.isExecutableModel()) {
// kieBuilder = ks.newKieBuilder(kfs).buildAll(ExecutableModelProject.class);
// } else {
// kieBuilder = ks.newKieBuilder(kfs).buildAll(DrlProject.class);
// }
final IncrementalResults results = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/myPkg/r2.drl").build();
assertEquals(0, results.getAddedMessages().size());
assertEquals(0, results.getRemovedMessages().size());
kieContainer.updateToVersion(releaseId2);
runRules(kieContainer, 2);
}
use of org.kie.internal.builder.IncrementalResults in project drools by kiegroup.
the class MessageImplTest method testMessageWithIncrementalBuild.
@Test
public void testMessageWithIncrementalBuild() throws Exception {
// Some suitably duff DSL to generate errors
String dsl1 = "bananna\n";
// Some suitably valid DRL
String drl1 = "import org.drools.mvel.compiler.Person;\n" + "rule R1\n" + "when\n" + "There is a Person\n" + "then\n" + "end\n";
// Some suitably valid DRL
String drl2 = "rule R2\n" + "when\n" + "then\n" + "end\n";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/dsl.dsl", dsl1).write("src/main/resources/drl.dslr", drl1);
final KieBuilder kieBuilder = KieUtil.getKieBuilderFromKieFileSystem(kieBaseTestConfiguration, kfs, false);
Results fullBuildResults = kieBuilder.getResults();
assertEquals(3, fullBuildResults.getMessages().size());
kfs.write("src/main/resources/r2.drl", drl2);
IncrementalResults incrementalBuildResults = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/r2.drl").build();
assertEquals(0, incrementalBuildResults.getAddedMessages().size());
assertEquals(0, incrementalBuildResults.getRemovedMessages().size());
}
use of org.kie.internal.builder.IncrementalResults in project drools by kiegroup.
the class KieModuleIncrementalCompilationTest method testIncrementalCompilationFirstBuildHasErrors.
@Test
public void testIncrementalCompilationFirstBuildHasErrors() throws Exception {
KieServices ks = KieServices.Factory.get();
// Malformed POM - No Version information
ReleaseId releaseId = ks.newReleaseId("org.kie", "incremental-test-with-invalid pom", "");
KieFileSystem kfs = createKieFileSystemWithKProject(ks);
kfs.writePomXML(getPom(releaseId));
// Valid
String drl1 = "rule R1 when\n" + " $s : String()\n" + "then\n" + "end\n";
// Invalid
String drl2 = "rule R2 when\n" + " $s : Strin( )\n" + "then\n" + "end\n";
// Write Rule 1 - No DRL errors, but POM is in error
kfs.write("src/main/resources/KBase1/r1.drl", drl1);
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/KBase1/r2.drl", drl2);
IncrementalResults addResults = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/KBase1/r2.drl").build();
assertEquals(1, addResults.getAddedMessages().size());
assertEquals(0, addResults.getRemovedMessages().size());
}
use of org.kie.internal.builder.IncrementalResults in project drools by kiegroup.
the class KieModuleIncrementalCompilationTest method checkIncrementalCompilationWithFunctionThenRule.
@Test
public void checkIncrementalCompilationWithFunctionThenRule() 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/function.drl", function);
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/rule.drl", rule);
IncrementalResults addResults = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/org/kie/scanner/rule.drl").build();
assertEquals(0, addResults.getAddedMessages().size());
assertEquals(0, addResults.getRemovedMessages().size());
}
Aggregations