use of org.kie.internal.builder.IncrementalResults in project drools by kiegroup.
the class IncrementalCompilationTest method testIncrementalCompilationWithRemovedError.
@Test
public void testIncrementalCompilationWithRemovedError() {
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( nonExistentField == \"Hello World\" )\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( message == \"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);
assertEquals(1, kieBuilder.getResults().getMessages(org.kie.api.builder.Message.Level.ERROR).size());
kfs.write("src/main/resources/r2.drl", drl2_2);
final IncrementalResults results = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/r2.drl").build();
assertEquals(0, results.getAddedMessages().size());
assertEquals(1, results.getRemovedMessages().size());
final KieContainer kieContainer = ks.newKieContainer(ks.getRepository().getDefaultReleaseId());
final KieSession ksession = kieContainer.newKieSession();
ksession.insert(new Message("Hello World"));
assertEquals(2, ksession.fireAllRules());
}
use of org.kie.internal.builder.IncrementalResults in project drools by kiegroup.
the class IncrementalCompilationTest method testIncrementalCompilationWithMissingKSession.
@Test
public void testIncrementalCompilationWithMissingKSession() {
// https://bugzilla.redhat.com/show_bug.cgi?id=1066059
final String pom = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + "<project xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\" xmlns=\"http://maven.apache.org/POM/4.0.0\"\n" + " xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" + " <modelVersion>4.0.0</modelVersion>\n" + " <groupId>org.kie</groupId>\n" + " <artifactId>test</artifactId>\n" + " <version>1.0</version>\n" + " <packaging>jar</packaging>\n" + " <name>test</name>\n" + "</project>";
final String kmodule = "<kmodule xmlns=\"http://www.drools.org/xsd/kmodule\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">\n" + "<kbase name=\"kbase\" includes=\"nonExistent\"/>\n" + "</kmodule>";
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("pom.xml", pom).write("src/main/resources/META-INF/kmodule.xml", kmodule).write("src/main/resources/r2.drl", drl2_1);
final KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll(DrlProject.class);
kfs.write("src/main/resources/r2.drl", drl2_2);
final IncrementalResults results = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/r2.drl").build();
// since there's a missing include tha kiebase is not built at all
assertEquals(0, results.getAddedMessages().size());
assertEquals(0, results.getRemovedMessages().size());
}
use of org.kie.internal.builder.IncrementalResults in project drools by kiegroup.
the class IncrementalCompilationTest method testIncrementalCompilationAddErrorBuildAllMessages.
@Test
public void testIncrementalCompilationAddErrorBuildAllMessages() {
// Valid
final String drl1 = "package org.drools.compiler\n" + "import " + Message.class.getCanonicalName() + ";\n" + "rule R1 when\n" + " $m : Message()\n" + "then\n" + "end\n";
// Field is unknown ("nonExistentField" not "message")
final String drl2_1 = "package org.drools.compiler\n" + "import " + Message.class.getCanonicalName() + ";\n" + "rule R2_1 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);
final KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll(DrlProject.class);
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);
final IncrementalResults addResults = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/r2.drl").build();
assertEquals(1, addResults.getAddedMessages().size());
assertEquals(0, addResults.getRemovedMessages().size());
// Check errors on a full build
assertEquals(1, ks.newKieBuilder(kfs).buildAll().getResults().getMessages().size());
}
use of org.kie.internal.builder.IncrementalResults in project drools by kiegroup.
the class IncrementalCompilationTest method testIncrementalCompilationWithDuplicatedRule.
@Test
public void testIncrementalCompilationWithDuplicatedRule() {
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 = "package org.drools.compiler\n" + "import " + Message.class.getCanonicalName() + ";\n" + "rule R2 when\n" + " $m : Message( message == \"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);
final KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll(DrlProject.class);
assertEquals(0, kieBuilder.getResults().getMessages(org.kie.api.builder.Message.Level.ERROR).size());
kfs.write("src/main/resources/r2_1.drl", drl2);
final IncrementalResults addResults = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/r2_1.drl").build();
assertEquals(0, addResults.getAddedMessages().size());
assertEquals(0, addResults.getRemovedMessages().size());
kfs.write("src/main/resources/r2_2.drl", drl2);
final IncrementalResults removeResults = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/r2_2.drl").build();
assertEquals(1, removeResults.getAddedMessages().size());
assertEquals(0, removeResults.getRemovedMessages().size());
}
use of org.kie.internal.builder.IncrementalResults in project drools by kiegroup.
the class IncrementalCompilationTest method testIncrementalCompilationWithInvalidDRL.
@Test
public void testIncrementalCompilationWithInvalidDRL() {
final String drl1 = "Smurf";
final String drl2_1 = "package org.drools.compiler\n" + "rule R2\n" + "when\n" + " $m : NonExistentClass()\n" + "then\n" + "end\n";
final String drl2_2 = "package org.drools.compiler\n" + "import " + Message.class.getCanonicalName() + ";\n" + "rule R2\n" + "when\n" + " $m : Message()\n" + "then\n" + "end\n";
final KieServices ks = KieServices.Factory.get();
final KieFileSystem kfs = ks.newKieFileSystem();
// First file contains errors
kfs.write("src/main/resources/r1.drl", drl1);
final KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll(DrlProject.class);
final Results results1 = kieBuilder.getResults();
assertEquals(2, results1.getMessages().size());
// Second file also contains errors.. expect some added messages
kfs.write("src/main/resources/r2.drl", drl2_1);
final IncrementalResults results2 = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/r2.drl").build();
assertEquals(1, results2.getAddedMessages().size());
assertEquals(0, results2.getRemovedMessages().size());
// Correct second file... expect original errors relating to the file to be removed
kfs.write("src/main/resources/r2.drl", drl2_2);
final IncrementalResults results3 = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/r2.drl").build();
assertEquals(0, results3.getAddedMessages().size());
assertEquals(1, results3.getRemovedMessages().size());
// Remove first file... expect related errors to be removed
kfs.delete("src/main/resources/r1.drl");
final IncrementalResults results4 = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/r1.drl").build();
assertEquals(0, results4.getAddedMessages().size());
assertEquals(2, results4.getRemovedMessages().size());
}
Aggregations