Search in sources :

Example 16 with InternalKieBuilder

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

the class GuidedScoreCardIntegrationJavaClassesAddedToKieFileSystemTest 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/java/org/drools/workbench/models/guided/scorecard/backend/test2/Applicant.java", Helper.getApplicant());
    kfs.write("src/main/java/org/drools/workbench/models/guided/scorecard/backend/test2/ApplicantAttribute.java", Helper.getApplicantAttribute());
    kfs.write("src/main/resources/org/drools/workbench/models/guided/scorecard/backend/test2/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)

Example 17 with InternalKieBuilder

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

the class KieBuilderTest method checkKModule.

private void checkKModule(final String kmodule, final int expectedErrors) {
    final KieServices ks = KieServices.Factory.get();
    final ReleaseId releaseId = ks.newReleaseId("org.kie", "test-kie-builder", "1.0.0");
    final KieFileSystem kfs = ks.newKieFileSystem().generateAndWritePomXML(releaseId).writeKModuleXML(kmodule);
    final KieBuilder kieBuilder = ks.newKieBuilder(kfs);
    kieBuilder.buildAll();
    final Results results = kieBuilder.getResults();
    assertEquals(expectedErrors, results.getMessages(org.kie.api.builder.Message.Level.ERROR).size());
    assertNotNull(((InternalKieBuilder) kieBuilder).getKieModuleIgnoringErrors());
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Results(org.kie.api.builder.Results) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) InternalKieBuilder(org.kie.internal.builder.InternalKieBuilder) KieBuilder(org.kie.api.builder.KieBuilder)

Example 18 with InternalKieBuilder

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

the class MessageImplTests method testMessageWithIncrementalBuild.

@Test
public void testMessageWithIncrementalBuild() throws Exception {
    // Some suitably duff DSL to generate errors
    String dsl1 = "bananna\n";
    // Some suitably valid DRL
    String drl1 = "import org.drools.compiler.Person;\n" + "rule R1\n" + "when\n" + "There is a Person\n" + "then\n" + "end\n";
    // Some suitably valid DRL
    String drl2 = "rule R2\n" + "when\n" + "then\n" + "end\n";
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/dsl.dsl", dsl1).write("src/main/resources/drl.dslr", drl1);
    KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
    Results fullBuildResults = kieBuilder.getResults();
    assertEquals(3, fullBuildResults.getMessages().size());
    kfs.write("src/main/resources/r2.drl", drl2);
    IncrementalResults incrementalBuildResults = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/r2.drl").build();
    assertEquals(0, incrementalBuildResults.getAddedMessages().size());
    assertEquals(0, incrementalBuildResults.getRemovedMessages().size());
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Results(org.kie.api.builder.Results) IncrementalResults(org.kie.internal.builder.IncrementalResults) 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 19 with InternalKieBuilder

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

the class MultipleModelTest method testIncrementalBuilding.

@Test
public void testIncrementalBuilding() throws Exception {
    ReleaseId releaseId1 = KieServices.Factory.get().newReleaseId("org.test", "test", "1.0.0-SNAPSHOT");
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem();
    KieBuilder kb = ks.newKieBuilder(kfs);
    kfs.generateAndWritePomXML(releaseId1);
    kfs.write(ResourceFactory.newClassPathResource(source1).setResourceType(ResourceType.PMML));
    kb.buildAll();
    KieContainer kc = ks.newKieContainer(releaseId1);
    KieSession kSession = kc.newKieSession();
    setKbase(kSession.getKieBase());
    kSession.fireAllRules();
    kfs.write(ResourceFactory.newClassPathResource(source2).setResourceType(ResourceType.PMML));
    IncrementalResults results = ((InternalKieBuilder) kb).incrementalBuild();
    kc.updateToVersion(releaseId1);
    kSession.fireAllRules();
    assertEquals(1, kSession.getObjects(new ClassObjectFilter(ModelMarker.class)).size());
    assertEquals(9, kSession.getObjects(new ClassObjectFilter(kSession.getKieBase().getFactType(packageName, "Synapse").getFactClass())).size());
    kSession.dispose();
    checkGeneratedRules();
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) ClassObjectFilter(org.kie.api.runtime.ClassObjectFilter) InternalKieBuilder(org.kie.internal.builder.InternalKieBuilder) ModelMarker(org.drools.pmml.pmml_4_2.ModelMarker) KieServices(org.kie.api.KieServices) KieSession(org.kie.api.runtime.KieSession) ReleaseId(org.kie.api.builder.ReleaseId) KieBuilder(org.kie.api.builder.KieBuilder) InternalKieBuilder(org.kie.internal.builder.InternalKieBuilder) IncrementalResults(org.kie.internal.builder.IncrementalResults) KieContainer(org.kie.api.runtime.KieContainer) DroolsAbstractPMMLTest(org.drools.pmml.pmml_4_2.DroolsAbstractPMMLTest) Test(org.junit.Test)

Example 20 with InternalKieBuilder

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

the class IncrementalCompilationTest method testIncrementalCompilationAddErrorThenRemoveError.

@Test
public void testIncrementalCompilationAddErrorThenRemoveError() throws Exception {
    // Valid
    String drl1 = "package org.drools.compiler\n" + "rule R1 when\n" + "   $m : Message()\n" + "then\n" + "end\n";
    // Field is unknown ("nonExistentField" not "message")
    String drl2_1 = "package org.drools.compiler\n" + "rule R2_1 when\n" + "   $m : Message( nonExistentField == \"Hello World\" )\n" + "then\n" + "end\n";
    // Valid
    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);
    KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
    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);
    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);
    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)

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