use of org.kie.internal.builder.InternalKieBuilder in project drools by kiegroup.
the class GuidedScoreCardIntegrationJavaClassesAddedToKieFileSystemTest 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/java/org/drools/workbench/models/guided/scorecard/backend/test2/Applicant.java", Helper.getApplicant());
kfs.write("src/main/java/org/drools/workbench/models/guided/scorecard/backend/test2/ApplicantAttribute.java", Helper.getApplicantAttribute());
kfs.write("src/main/resources/org/drools/workbench/models/guided/scorecard/backend/test2/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());
}
use of org.kie.internal.builder.InternalKieBuilder in project drools by kiegroup.
the class KieBuilderTest method checkKModule.
private void checkKModule(final String kmodule, final int expectedErrors) {
final KieServices ks = KieServices.Factory.get();
final ReleaseId releaseId = ks.newReleaseId("org.kie", "test-kie-builder", "1.0.0");
final KieFileSystem kfs = ks.newKieFileSystem().generateAndWritePomXML(releaseId).writeKModuleXML(kmodule);
final KieBuilder kieBuilder = ks.newKieBuilder(kfs);
kieBuilder.buildAll();
final Results results = kieBuilder.getResults();
assertEquals(expectedErrors, results.getMessages(org.kie.api.builder.Message.Level.ERROR).size());
assertNotNull(((InternalKieBuilder) kieBuilder).getKieModuleIgnoringErrors());
}
use of org.kie.internal.builder.InternalKieBuilder in project drools by kiegroup.
the class MessageImplTests 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.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);
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
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.InternalKieBuilder in project drools by kiegroup.
the class MultipleModelTest method testIncrementalBuilding.
@Test
public void testIncrementalBuilding() throws Exception {
ReleaseId releaseId1 = KieServices.Factory.get().newReleaseId("org.test", "test", "1.0.0-SNAPSHOT");
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
KieBuilder kb = ks.newKieBuilder(kfs);
kfs.generateAndWritePomXML(releaseId1);
kfs.write(ResourceFactory.newClassPathResource(source1).setResourceType(ResourceType.PMML));
kb.buildAll();
KieContainer kc = ks.newKieContainer(releaseId1);
KieSession kSession = kc.newKieSession();
setKbase(kSession.getKieBase());
kSession.fireAllRules();
kfs.write(ResourceFactory.newClassPathResource(source2).setResourceType(ResourceType.PMML));
IncrementalResults results = ((InternalKieBuilder) kb).incrementalBuild();
kc.updateToVersion(releaseId1);
kSession.fireAllRules();
assertEquals(1, kSession.getObjects(new ClassObjectFilter(ModelMarker.class)).size());
assertEquals(9, kSession.getObjects(new ClassObjectFilter(kSession.getKieBase().getFactType(packageName, "Synapse").getFactClass())).size());
kSession.dispose();
checkGeneratedRules();
}
use of org.kie.internal.builder.InternalKieBuilder in project drools by kiegroup.
the class IncrementalCompilationTest method testIncrementalCompilationAddErrorThenRemoveError.
@Test
public void testIncrementalCompilationAddErrorThenRemoveError() throws Exception {
// Valid
String drl1 = "package org.drools.compiler\n" + "rule R1 when\n" + " $m : Message()\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);
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
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);
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);
IncrementalResults removeResults = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/r2.drl").build();
assertEquals(0, removeResults.getAddedMessages().size());
assertEquals(1, removeResults.getRemovedMessages().size());
}
Aggregations