use of org.kie.internal.builder.InternalKieBuilder in project drools by kiegroup.
the class IncrementalCompilationTest method testIncrementalCompilationWithExtendsRule.
@Test
public void testIncrementalCompilationWithExtendsRule() throws Exception {
// DROOLS-1405
String drl1 = "rule \"test1\" when then end\n";
String drl2 = "rule \"test2\" extends \"test1\" when then end\n" + "rule \"test3\" extends \"test1\" when then 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());
kfs.write("src/main/resources/r2.drl", drl2);
IncrementalResults addResults = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/r2.drl").build();
assertEquals(0, addResults.getAddedMessages().size());
}
use of org.kie.internal.builder.InternalKieBuilder in project drools by kiegroup.
the class IncrementalCompilationTest method testIncrementalCompilationWithRemovedError.
@Test
public void testIncrementalCompilationWithRemovedError() throws Exception {
String drl1 = "package org.drools.compiler\n" + "rule R1 when\n" + " $m : Message()\n" + "then\n" + "end\n";
String drl2_1 = "package org.drools.compiler\n" + "rule R2_1 when\n" + " $m : Message( nonExistentField == \"Hello World\" )\n" + "then\n" + "end\n";
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).write("src/main/resources/r2.drl", drl2_1);
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
assertEquals(1, kieBuilder.getResults().getMessages(org.kie.api.builder.Message.Level.ERROR).size());
kfs.write("src/main/resources/r2.drl", drl2_2);
IncrementalResults results = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/r2.drl").build();
assertEquals(0, results.getAddedMessages().size());
assertEquals(1, results.getRemovedMessages().size());
KieContainer kieContainer = ks.newKieContainer(ks.getRepository().getDefaultReleaseId());
KieSession ksession = kieContainer.newKieSession();
ksession.insert(new Message("Hello World"));
assertEquals(2, ksession.fireAllRules());
}
use of org.kie.internal.builder.InternalKieBuilder in project drools by kiegroup.
the class IncrementalCompilationTest method testIncrementalCompilationWithInvalidDRL.
@Test
public void testIncrementalCompilationWithInvalidDRL() throws Exception {
String drl1 = "Smurf";
String drl2_1 = "package org.drools.compiler\n" + "rule R2\n" + "when\n" + " $m : NonExistentClass()\n" + "then\n" + "end\n";
String drl2_2 = "package org.drools.compiler\n" + "rule R2\n" + "when\n" + " $m : Message()\n" + "then\n" + "end\n";
KieServices ks = KieServices.Factory.get();
KieFileSystem kfs = ks.newKieFileSystem();
// First file contains errors
kfs.write("src/main/resources/r1.drl", drl1);
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
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);
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);
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");
IncrementalResults results4 = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/r1.drl").build();
assertEquals(0, results4.getAddedMessages().size());
assertEquals(2, results4.getRemovedMessages().size());
}
use of org.kie.internal.builder.InternalKieBuilder in project drools by kiegroup.
the class IncrementalCompilationTest method testIncrementalCompilationWithMissingKSession.
@Test
public void testIncrementalCompilationWithMissingKSession() throws Exception {
// https://bugzilla.redhat.com/show_bug.cgi?id=1066059
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>";
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>";
String drl2_1 = "package org.drools.compiler\n" + "rule R2_1 when\n" + " $m : Message( message == \"Hi Universe\" )\n" + "then\n" + "end\n";
String drl2_2 = "package org.drools.compiler\n" + "rule R2_2 when\n" + " $m : Message( nonExistentField == \"Hello World\" )\n" + "then\n" + "end\n";
KieServices ks = KieServices.Factory.get();
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);
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
kfs.write("src/main/resources/r2.drl", drl2_2);
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.InternalKieBuilder in project drools by kiegroup.
the class IncrementalCompilationTest method testIncrementalCompilationWithDuplicatedRule.
@Test
public void testIncrementalCompilationWithDuplicatedRule() throws Exception {
String drl1 = "package org.drools.compiler\n" + "rule R1 when\n" + " $m : Message()\n" + "then\n" + "end\n";
String drl2 = "package org.drools.compiler\n" + "rule R2 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());
kfs.write("src/main/resources/r2_1.drl", drl2);
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);
IncrementalResults removeResults = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/r2_2.drl").build();
assertEquals(1, removeResults.getAddedMessages().size());
assertEquals(0, removeResults.getRemovedMessages().size());
}
Aggregations