Search in sources :

Example 11 with InternalKieBuilder

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

the class KieModuleIncrementalCompilationTest method testCheckMetaDataAfterIncrementalDelete.

@Test
public void testCheckMetaDataAfterIncrementalDelete() throws Exception {
    String drl1 = "package org.kie.scanner\n" + "rule R1 when\n" + "   String()\n" + "then\n" + "end\n";
    String drl2 = "package org.kie.scanner\n" + "rule R2_2 when\n" + "   String( )\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);
    KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
    assertEquals(2, getRuleNames(kieBuilder).get("org.kie.scanner").size());
    kfs.delete("src/main/resources/r2.drl");
    IncrementalResults addResults = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/r2.drl").build();
    assertEquals(1, getRuleNames(kieBuilder).get("org.kie.scanner").size());
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) KieServices(org.kie.api.KieServices) KieBuilder(org.kie.api.builder.KieBuilder) InternalKieBuilder(org.kie.internal.builder.InternalKieBuilder) IncrementalResults(org.kie.internal.builder.IncrementalResults) Test(org.junit.Test)

Example 12 with InternalKieBuilder

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

the class KieModuleIncrementalCompilationTest method checkIncrementalCompilationWithRuleThenFunction.

@Test
public void checkIncrementalCompilationWithRuleThenFunction() throws Exception {
    String rule = "package org.kie.scanner\n" + "rule R1 when\n" + "   String()\n" + "then\n" + "   System.out.println(MyFunction());\n" + "end\n";
    String function = "package org.kie.scanner\n" + "function int MyFunction() {\n" + "   return 1;\n" + "}\n";
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem();
    kfs.write("src/main/resources/org/kie/scanner/rule.drl", rule);
    KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
    assertEquals(1, kieBuilder.getResults().getMessages(org.kie.api.builder.Message.Level.ERROR).size());
    kfs.write("src/main/resources/org/kie/scanner/function.drl", function);
    IncrementalResults addResults1 = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/org/kie/scanner/function.drl").build();
    assertEquals(0, addResults1.getAddedMessages().size());
    assertEquals(1, addResults1.getRemovedMessages().size());
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) KieServices(org.kie.api.KieServices) KieBuilder(org.kie.api.builder.KieBuilder) InternalKieBuilder(org.kie.internal.builder.InternalKieBuilder) IncrementalResults(org.kie.internal.builder.IncrementalResults) Test(org.junit.Test)

Example 13 with InternalKieBuilder

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

the class KieModuleIncrementalCompilationTest method checkIncrementalCompilationWithMultipleKieBases.

@Test
public void checkIncrementalCompilationWithMultipleKieBases() throws Exception {
    String rule = "package org.kie.scanner\n" + "rule R1 when\n" + "then\n" + "end\n";
    String invalidRule = "package org.kie.scanner\n" + "rule R2 when\n" + // missing import
    "   Cheese()\n" + "then\n" + "end\n";
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = createKieFileSystemWithTwoKBases(ks);
    kfs.write("src/main/resources/org/kie/scanner/rule.drl", rule);
    KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
    assertEquals(0, kieBuilder.getResults().getMessages().size());
    kfs.write("src/main/resources/org/kie/scanner/invalidRule.drl", invalidRule);
    IncrementalResults addResults = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/org/kie/scanner/invalidRule.drl").build();
    assertEquals(2, addResults.getAddedMessages().size());
    addResults.getAddedMessages().stream().map(m -> (MessageImpl) m).forEach(m -> assertNotNull(m.getKieBaseName()));
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) KieBuilder(org.kie.api.builder.KieBuilder) EventProcessingOption(org.kie.api.conf.EventProcessingOption) MessageImpl(org.drools.compiler.kie.builder.impl.MessageImpl) Collection(java.util.Collection) EqualityBehaviorOption(org.kie.api.conf.EqualityBehaviorOption) HashMap(java.util.HashMap) Test(org.junit.Test) IncrementalResults(org.kie.internal.builder.IncrementalResults) ReleaseId(org.kie.api.builder.ReleaseId) InternalKieBuilder(org.kie.internal.builder.InternalKieBuilder) KieModuleModel(org.kie.api.builder.model.KieModuleModel) KieServices(org.kie.api.KieServices) Assert(org.junit.Assert) KieFileSystem(org.kie.api.builder.KieFileSystem) KieServices(org.kie.api.KieServices) KieBuilder(org.kie.api.builder.KieBuilder) InternalKieBuilder(org.kie.internal.builder.InternalKieBuilder) MessageImpl(org.drools.compiler.kie.builder.impl.MessageImpl) IncrementalResults(org.kie.internal.builder.IncrementalResults) Test(org.junit.Test)

Example 14 with InternalKieBuilder

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

the class KieModuleIncrementalCompilationTest method checkIncrementalCompilationWithRuleFunctionRule.

@Test
public void checkIncrementalCompilationWithRuleFunctionRule() throws Exception {
    String rule_1 = "package org.kie.scanner\n" + "rule R1 when\n" + "   String()\n" + "then\n" + "end\n";
    String rule_2 = "package org.kie.scanner\n" + "rule R1 when\n" + "   String()\n" + "then\n" + "   System.out.println(MyFunction());\n" + "end\n";
    String function = "package org.kie.scanner\n" + "function int MyFunction() {\n" + "   return 1;\n" + "}\n";
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem();
    kfs.write("src/main/resources/org/kie/scanner/rule.drl", rule_1);
    KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
    assertEquals(0, kieBuilder.getResults().getMessages(org.kie.api.builder.Message.Level.ERROR).size());
    kfs.write("src/main/resources/org/kie/scanner/function.drl", function);
    IncrementalResults addResults1 = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/org/kie/scanner/function.drl").build();
    assertEquals(0, addResults1.getAddedMessages().size());
    assertEquals(0, addResults1.getRemovedMessages().size());
    kfs.write("src/main/resources/org/kie/scanner/rule.drl", rule_2);
    IncrementalResults addResults2 = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/org/kie/scanner/rule.drl").build();
    assertEquals(0, addResults2.getAddedMessages().size());
    assertEquals(0, addResults2.getRemovedMessages().size());
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) KieServices(org.kie.api.KieServices) KieBuilder(org.kie.api.builder.KieBuilder) InternalKieBuilder(org.kie.internal.builder.InternalKieBuilder) IncrementalResults(org.kie.internal.builder.IncrementalResults) Test(org.junit.Test)

Example 15 with InternalKieBuilder

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

the class GuidedScoreCardIntegrationJavaClassesOnClassPathTest 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/resources/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());
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Message(org.kie.api.builder.Message) InternalKieBuilder(org.kie.internal.builder.InternalKieBuilder) 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