Search in sources :

Example 36 with IncrementalResults

use of org.kie.internal.builder.IncrementalResults in project drools by kiegroup.

the class IncrementalCompilationTest method testIncrementalCompilationWithExtendsRule.

@Test
public void testIncrementalCompilationWithExtendsRule() {
    // DROOLS-1405
    final String drl1 = "rule \"test1\" when then end\n";
    final String drl2 = "rule \"test2\" extends \"test1\" when then end\n" + "rule \"test3\" extends \"test1\" when then 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.drl", drl2);
    final 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 37 with IncrementalResults

use of org.kie.internal.builder.IncrementalResults in project drools by kiegroup.

the class IncrementalCompilationTest method testIncrementalCompilationFromEmptyProject.

@Test
public void testIncrementalCompilationFromEmptyProject() {
    // DROOLS-5547
    final String drl1 = "rule \"test1\" when then end\n";
    final String drl2 = "rule \"test2\" extends \"test1\" when then end\n" + "rule \"test3\" extends \"test1\" when then end\n";
    final KieServices ks = KieServices.Factory.get();
    final KieFileSystem kfs = ks.newKieFileSystem();
    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/r1.drl", drl1);
    final IncrementalResults addResults1 = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/r1.drl").build();
    assertEquals(0, addResults1.getAddedMessages().size());
    kfs.write("src/main/resources/r2.drl", drl2);
    final IncrementalResults addResults2 = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/r2.drl").build();
    assertEquals(0, addResults2.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 38 with IncrementalResults

use of org.kie.internal.builder.IncrementalResults in project drools by kiegroup.

the class IncrementalCompilationTest method testIncrementalCompilationRemovingParentRule.

@Test
public void testIncrementalCompilationRemovingParentRule() {
    // DROOLS-1031
    final String drl1 = "package org.drools.compiler\n" + "rule R1 when\n" + "   $s : String()\n" + "then\n" + "end\n";
    final String drl2 = "package org.drools.compiler\n" + "rule R2 extends R1 when\n" + "   $i : Integer()\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);
    final KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll(DrlProject.class);
    final KieContainer kieContainer = ks.newKieContainer(ks.getRepository().getDefaultReleaseId());
    KieSession ksession = kieContainer.newKieSession();
    ksession.insert("test");
    ksession.insert(1);
    assertEquals(2, ksession.fireAllRules());
    kfs.delete("src/main/resources/r1.drl");
    final IncrementalResults results = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/r1.drl", "src/main/resources/r2.drl").build();
    assertEquals(1, results.getAddedMessages().size());
    assertEquals(0, results.getRemovedMessages().size());
    kieContainer.updateToVersion(ks.getRepository().getDefaultReleaseId());
    ksession = kieContainer.newKieSession();
    ksession.insert("test");
    ksession.insert(1);
    assertEquals(2, ksession.fireAllRules());
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) 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 39 with IncrementalResults

use of org.kie.internal.builder.IncrementalResults in project drools by kiegroup.

the class IncrementalCompilationTest method testIncrementalCompilationAddErrorThenRemoveError.

@Test
public void testIncrementalCompilationAddErrorThenRemoveError() {
    // 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";
    // Valid
    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);
    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());
    // 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);
    final IncrementalResults removeResults = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/r2.drl").build();
    assertEquals(0, removeResults.getAddedMessages().size());
    assertEquals(1, 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)

Example 40 with IncrementalResults

use of org.kie.internal.builder.IncrementalResults in project drools by kiegroup.

the class IncrementalCompilationTest method testIncrementalCompilationWithIncludes.

@Test
public void testIncrementalCompilationWithIncludes() {
    // DROOLS-462
    final String drl1 = "global java.util.List list\n" + "rule R1 when\n" + " $s : String() " + "then\n" + " list.add( \"a\" + $s );" + "end\n";
    final String drl2 = "global java.util.List list\n" + "rule R1 when\n" + " $s : String() " + "then\n" + " list.add( \"b\" + $s );" + "end\n";
    final ReleaseId releaseId = KieServices.Factory.get().newReleaseId("org.test", "test", "1.0.0");
    final KieServices ks = KieServices.Factory.get();
    final KieModuleModel kproj = ks.newKieModuleModel();
    final KieBaseModel kieBaseModel1 = kproj.newKieBaseModel("KBase1").addPackage("org.pkg1");
    kieBaseModel1.newKieSessionModel("KSession1");
    final KieBaseModel kieBaseModel2 = kproj.newKieBaseModel("KBase2").addPackage("org.pkg2").addInclude("KBase1");
    kieBaseModel2.newKieSessionModel("KSession2");
    final KieFileSystem kfs = ks.newKieFileSystem().generateAndWritePomXML(releaseId).write("src/main/resources/KBase1/org/pkg1/r1.drl", drl1).writeKModuleXML(kproj.toXML());
    final KieBuilder kieBuilder = ks.newKieBuilder(kfs);
    kieBuilder.buildAll(DrlProject.class);
    assertEquals(0, kieBuilder.getResults().getMessages().size());
    final KieContainer kc = ks.newKieContainer(releaseId);
    final KieSession ksession = kc.newKieSession("KSession2");
    final List<String> list = new ArrayList<>();
    ksession.setGlobal("list", list);
    ksession.insert("Foo");
    ksession.fireAllRules();
    assertEquals(1, list.size());
    assertEquals("aFoo", list.get(0));
    list.clear();
    kfs.delete("src/main/resources/KBase1/org/pkg1/r1.drl");
    kfs.write("src/main/resources/KBase1/org/pkg1/r2.drl", drl2);
    final IncrementalResults results = ((InternalKieBuilder) kieBuilder).incrementalBuild();
    assertEquals(0, results.getAddedMessages().size());
    final Results updateResults = kc.updateToVersion(releaseId);
    assertEquals(0, updateResults.getMessages().size());
    ksession.insert("Bar");
    ksession.fireAllRules();
    assertEquals(2, list.size());
    assertTrue(list.containsAll(asList("bBar", "bFoo")));
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) ArrayList(java.util.ArrayList) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) IncrementalResults(org.kie.internal.builder.IncrementalResults) KieBaseModel(org.kie.api.builder.model.KieBaseModel) InternalKieBuilder(org.kie.internal.builder.InternalKieBuilder) IncrementalResults(org.kie.internal.builder.IncrementalResults) Results(org.kie.api.builder.Results) KieModuleModel(org.kie.api.builder.model.KieModuleModel) StatelessKieSession(org.kie.api.runtime.StatelessKieSession) KieSession(org.kie.api.runtime.KieSession) InternalKieBuilder(org.kie.internal.builder.InternalKieBuilder) KieBuilder(org.kie.api.builder.KieBuilder) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Aggregations

IncrementalResults (org.kie.internal.builder.IncrementalResults)44 Test (org.junit.Test)42 KieServices (org.kie.api.KieServices)42 KieFileSystem (org.kie.api.builder.KieFileSystem)42 KieBuilder (org.kie.api.builder.KieBuilder)39 InternalKieBuilder (org.kie.internal.builder.InternalKieBuilder)39 KieContainer (org.kie.api.runtime.KieContainer)14 ReleaseId (org.kie.api.builder.ReleaseId)13 KieSession (org.kie.api.runtime.KieSession)10 Results (org.kie.api.builder.Results)8 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)8 Message (org.kie.api.builder.Message)5 ArrayList (java.util.ArrayList)4 StringReader (java.io.StringReader)3 Message (org.drools.testcoverage.common.model.Message)3 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)3 KieBuilderSetImpl (org.drools.compiler.kie.builder.impl.KieBuilderSetImpl)2 KieModuleModel (org.kie.api.builder.model.KieModuleModel)2 ClassObjectFilter (org.kie.api.runtime.ClassObjectFilter)2 InputStream (java.io.InputStream)1