Search in sources :

Example 21 with InternalKieBuilder

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());
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) KieServices(org.kie.api.KieServices) InternalKieBuilder(org.kie.internal.builder.InternalKieBuilder) KieBuilder(org.kie.api.builder.KieBuilder) IncrementalResults(org.kie.internal.builder.IncrementalResults) Test(org.junit.Test)

Example 22 with InternalKieBuilder

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());
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Message(org.drools.compiler.Message) KieServices(org.kie.api.KieServices) StatelessKieSession(org.kie.api.runtime.StatelessKieSession) KieSession(org.kie.api.runtime.KieSession) InternalKieBuilder(org.kie.internal.builder.InternalKieBuilder) KieBuilder(org.kie.api.builder.KieBuilder) IncrementalResults(org.kie.internal.builder.IncrementalResults) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 23 with InternalKieBuilder

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());
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) IncrementalResults(org.kie.internal.builder.IncrementalResults) Results(org.kie.api.builder.Results) KieServices(org.kie.api.KieServices) InternalKieBuilder(org.kie.internal.builder.InternalKieBuilder) KieBuilder(org.kie.api.builder.KieBuilder) IncrementalResults(org.kie.internal.builder.IncrementalResults) Test(org.junit.Test)

Example 24 with InternalKieBuilder

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());
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) KieServices(org.kie.api.KieServices) InternalKieBuilder(org.kie.internal.builder.InternalKieBuilder) KieBuilder(org.kie.api.builder.KieBuilder) IncrementalResults(org.kie.internal.builder.IncrementalResults) Test(org.junit.Test)

Example 25 with InternalKieBuilder

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());
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) KieServices(org.kie.api.KieServices) InternalKieBuilder(org.kie.internal.builder.InternalKieBuilder) KieBuilder(org.kie.api.builder.KieBuilder) IncrementalResults(org.kie.internal.builder.IncrementalResults) Test(org.junit.Test)

Aggregations

KieBuilder (org.kie.api.builder.KieBuilder)34 KieFileSystem (org.kie.api.builder.KieFileSystem)34 InternalKieBuilder (org.kie.internal.builder.InternalKieBuilder)34 KieServices (org.kie.api.KieServices)32 Test (org.junit.Test)31 IncrementalResults (org.kie.internal.builder.IncrementalResults)31 ReleaseId (org.kie.api.builder.ReleaseId)10 KieContainer (org.kie.api.runtime.KieContainer)10 KieSession (org.kie.api.runtime.KieSession)10 Results (org.kie.api.builder.Results)9 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)8 StringReader (java.io.StringReader)4 Message (org.kie.api.builder.Message)4 ArrayList (java.util.ArrayList)2 Message (org.drools.compiler.Message)2 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)2 KieModuleModel (org.kie.api.builder.model.KieModuleModel)2 ClassObjectFilter (org.kie.api.runtime.ClassObjectFilter)2 InputStream (java.io.InputStream)1 Collection (java.util.Collection)1