Search in sources :

Example 11 with IncrementalResults

use of org.kie.internal.builder.IncrementalResults 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 12 with IncrementalResults

use of org.kie.internal.builder.IncrementalResults 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.drl.parser.MessageImpl) Assert.assertNotNull(org.junit.Assert.assertNotNull) 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.assertEquals(org.junit.Assert.assertEquals) 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.drl.parser.MessageImpl) IncrementalResults(org.kie.internal.builder.IncrementalResults) Test(org.junit.Test)

Example 13 with IncrementalResults

use of org.kie.internal.builder.IncrementalResults 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 14 with IncrementalResults

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

the class IncrementalCompilationTest method testIncrementalCompilationDuplicateXLSResources.

@Test
public void testIncrementalCompilationDuplicateXLSResources() throws Exception {
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem();
    InputStream in1 = null;
    InputStream in2 = null;
    try {
        // Add XLS decision table
        in1 = this.getClass().getResourceAsStream("incrementalBuild.dtable.xls");
        kfs.write("src/main/resources/incrementalBuild1.dtable.xls", KieServices.Factory.get().getResources().newInputStreamResource(in1));
        // Expect no errors
        KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
        assertEquals(0, kieBuilder.getResults().getMessages(org.kie.api.builder.Message.Level.ERROR).size());
        // Add the same XLS decision table again as a different resource
        in2 = this.getClass().getResourceAsStream("incrementalBuild.dtable.xls");
        kfs.write("src/main/resources/incrementalBuild2.dtable.xls", KieServices.Factory.get().getResources().newInputStreamResource(in2));
        IncrementalResults addResults = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/incrementalBuild2.dtable.xls").build();
        // Expect duplicate rule errors
        assertEquals(1, addResults.getAddedMessages().size());
        assertEquals(0, addResults.getRemovedMessages().size());
        // Check errors on a full build
        List<Message> messages = ks.newKieBuilder(kfs).buildAll().getResults().getMessages();
        assertFalse(messages.isEmpty());
    } finally {
        if (in1 != null) {
            in1.close();
        }
        if (in2 != null) {
            in2.close();
        }
    }
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Message(org.kie.api.builder.Message) InputStream(java.io.InputStream) 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 15 with IncrementalResults

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

the class IncrementalCompilationTest method testIncrementalCompilationWithAddedError.

@Test
public void testIncrementalCompilationWithAddedError() {
    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( 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("src/main/resources/r1.drl", drl1).write("src/main/resources/r2.drl", drl2_1);
    final KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll(DrlProject.class);
    final KieContainer kieContainer = ks.newKieContainer(ks.getRepository().getDefaultReleaseId());
    KieSession ksession = kieContainer.newKieSession();
    ksession.insert(new Message("Hello World"));
    assertEquals(1, ksession.fireAllRules());
    kfs.write("src/main/resources/r2.drl", drl2_2);
    final IncrementalResults results = ((InternalKieBuilder) kieBuilder).createFileSet("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(new Message("Hello World"));
    assertEquals(1, ksession.fireAllRules());
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Message(org.drools.testcoverage.common.model.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)

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