Search in sources :

Example 1 with IncrementalResults

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

Example 2 with IncrementalResults

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

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

the class KieBuilderSetImplTest method testBuild.

@Test
public void testBuild() throws Exception {
    final KieServices ks = KieServices.Factory.get();
    final KieFileSystem kfs = ks.newKieFileSystem();
    kfs.write("src/main/resources/rule%201.drl", ruleContent());
    final KieBuilderSetImpl kieBuilderSet = new KieBuilderSetImpl(kieBuilder(ks, kfs));
    kieBuilderSet.setFiles(new String[] { "src/main/resources/rule%201.drl" });
    final IncrementalResults build = kieBuilderSet.build();
    assertEquals(0, build.getAddedMessages().size());
    assertEquals(0, build.getRemovedMessages().size());
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) KieServices(org.kie.api.KieServices) IncrementalResults(org.kie.internal.builder.IncrementalResults) Test(org.junit.Test)

Example 4 with IncrementalResults

use of org.kie.internal.builder.IncrementalResults 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(2, kSession.getObjects(new ClassObjectFilter(ModelMarker.class)).size());
    assertEquals(11, 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.kie.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) Test(org.junit.Test) DroolsAbstractPMMLTest(org.kie.pmml.pmml_4_2.DroolsAbstractPMMLTest)

Example 5 with IncrementalResults

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

the class GuidedDTableParsingIntegrationTest method testGuidedDTableWithNoDSLIncrementalCompilation.

@Test
public void testGuidedDTableWithNoDSLIncrementalCompilation() {
    // DROOLS-1544
    String typeDrl = "package org.drools.test\n" + "declare LoanApplication\n" + "  amount : int\n" + "end";
    String brokenDrlGenerated = "<decision-table52>\n" + "  <tableName>Pricing loans</tableName>\n" + "  <rowNumberCol>\n" + "    <hideColumn>false</hideColumn>\n" + "    <width>-1</width>\n" + "  </rowNumberCol>\n" + "  <descriptionCol>\n" + "    <hideColumn>false</hideColumn>\n" + "    <width>-1</width>\n" + "  </descriptionCol>\n" + "  <metadataCols/>\n" + "  <attributeCols/>\n" + "  <conditionPatterns>\n" + "    <Pattern52>\n" + "      <factType>org.drools.test.LoanApplication</factType>\n" + "      <boundName>application</boundName>\n" + "      <isNegated>false</isNegated>\n" + "      <conditions>\n" + "        <condition-column52>\n" + "          <typedDefaultValue>\n" + "            <valueString></valueString>\n" + "            <dataType>STRING</dataType>\n" + "            <isOtherwise>false</isOtherwise>\n" + "          </typedDefaultValue>\n" + "          <hideColumn>false</hideColumn>\n" + "          <width>-1</width>\n" + "          <header>aa</header>\n" + "          <constraintValueType>1</constraintValueType>\n" + "          <factField>amount</factField>\n" + "          <fieldType>Integer</fieldType>\n" + "          <operator>==</operator>\n" + "          <valueList>a,b</valueList>\n" + "          <parameters/>\n" + "        </condition-column52>\n" + "      </conditions>\n" + "      <window>\n" + "        <parameters/>\n" + "      </window>\n" + "      <entryPointName></entryPointName>\n" + "    </Pattern52>\n" + "  </conditionPatterns>\n" + "  <actionCols/>\n" + "  <auditLog>\n" + "    <filter class=\"org.drools.guvnor.client.modeldriven.dt52.auditlog.DecisionTableAuditLogFilter\">\n" + "      <acceptedTypes>\n" + "        <entry>\n" + "          <string>INSERT_ROW</string>\n" + "          <boolean>false</boolean>\n" + "        </entry>\n" + "        <entry>\n" + "          <string>INSERT_COLUMN</string>\n" + "          <boolean>false</boolean>\n" + "        </entry>\n" + "        <entry>\n" + "          <string>DELETE_ROW</string>\n" + "          <boolean>false</boolean>\n" + "        </entry>\n" + "        <entry>\n" + "          <string>DELETE_COLUMN</string>\n" + "          <boolean>false</boolean>\n" + "        </entry>\n" + "        <entry>\n" + "          <string>UPDATE_COLUMN</string>\n" + "          <boolean>false</boolean>\n" + "        </entry>\n" + "      </acceptedTypes>\n" + "    </filter>\n" + "    <entries/>\n" + "  </auditLog>\n" + "  <imports>\n" + "    <imports/>\n" + "  </imports>\n" + "  <packageName>mortgages.mortgages</packageName>\n" + "  <tableFormat>EXTENDED_ENTRY</tableFormat>\n" + "  <hitPolicy>NONE</hitPolicy>\n" + "  <data>\n" + "    <list>\n" + "      <value>\n" + "        <valueNumeric class=\"int\">1</valueNumeric>\n" + "        <valueString></valueString>\n" + "        <dataType>NUMERIC_INTEGER</dataType>\n" + "        <isOtherwise>false</isOtherwise>\n" + "      </value>\n" + "      <value>\n" + "        <valueString></valueString>\n" + "        <dataType>STRING</dataType>\n" + "        <isOtherwise>false</isOtherwise>\n" + "      </value>\n" + "      <value>\n" + "        <valueString>a</valueString>\n" + "        <dataType>STRING</dataType>\n" + "        <isOtherwise>false</isOtherwise>\n" + "      </value>\n" + "    </list>\n" + "  </data>\n" + "</decision-table52>";
    String correctDrlGenerated = "<decision-table52>\n" + "  <tableName>Pricing loans</tableName>\n" + "  <rowNumberCol>\n" + "    <hideColumn>false</hideColumn>\n" + "    <width>-1</width>\n" + "  </rowNumberCol>\n" + "  <descriptionCol>\n" + "    <hideColumn>false</hideColumn>\n" + "    <width>-1</width>\n" + "  </descriptionCol>\n" + "  <metadataCols/>\n" + "  <attributeCols/>\n" + "  <conditionPatterns>\n" + "    <Pattern52>\n" + "      <factType>org.drools.test.LoanApplication</factType>\n" + "      <boundName>application</boundName>\n" + "      <isNegated>false</isNegated>\n" + "      <conditions>\n" + "        <condition-column52>\n" + "          <typedDefaultValue>\n" + "            <valueString></valueString>\n" + "            <dataType>STRING</dataType>\n" + "            <isOtherwise>false</isOtherwise>\n" + "          </typedDefaultValue>\n" + "          <hideColumn>false</hideColumn>\n" + "          <width>-1</width>\n" + "          <header>aa</header>\n" + "          <constraintValueType>1</constraintValueType>\n" + "          <factField>amount</factField>\n" + "          <fieldType>Integer</fieldType>\n" + "          <operator>==</operator>\n" + "          <valueList>a,b</valueList>\n" + "          <parameters/>\n" + "        </condition-column52>\n" + "      </conditions>\n" + "      <window>\n" + "        <parameters/>\n" + "      </window>\n" + "      <entryPointName></entryPointName>\n" + "    </Pattern52>\n" + "  </conditionPatterns>\n" + "  <actionCols/>\n" + "  <auditLog>\n" + "    <filter class=\"org.drools.guvnor.client.modeldriven.dt52.auditlog.DecisionTableAuditLogFilter\">\n" + "      <acceptedTypes>\n" + "        <entry>\n" + "          <string>INSERT_ROW</string>\n" + "          <boolean>false</boolean>\n" + "        </entry>\n" + "        <entry>\n" + "          <string>INSERT_COLUMN</string>\n" + "          <boolean>false</boolean>\n" + "        </entry>\n" + "        <entry>\n" + "          <string>DELETE_ROW</string>\n" + "          <boolean>false</boolean>\n" + "        </entry>\n" + "        <entry>\n" + "          <string>DELETE_COLUMN</string>\n" + "          <boolean>false</boolean>\n" + "        </entry>\n" + "        <entry>\n" + "          <string>UPDATE_COLUMN</string>\n" + "          <boolean>false</boolean>\n" + "        </entry>\n" + "      </acceptedTypes>\n" + "    </filter>\n" + "    <entries/>\n" + "  </auditLog>\n" + "  <imports>\n" + "    <imports/>\n" + "  </imports>\n" + "  <packageName>mortgages.mortgages</packageName>\n" + "  <tableFormat>EXTENDED_ENTRY</tableFormat>\n" + "  <hitPolicy>NONE</hitPolicy>\n" + "  <data>\n" + "    <list>\n" + "      <value>\n" + "        <valueNumeric class=\"int\">1</valueNumeric>\n" + "        <valueString></valueString>\n" + "        <dataType>NUMERIC_INTEGER</dataType>\n" + "        <isOtherwise>false</isOtherwise>\n" + "      </value>\n" + "      <value>\n" + "        <valueString></valueString>\n" + "        <dataType>STRING</dataType>\n" + "        <isOtherwise>false</isOtherwise>\n" + "      </value>\n" + "      <value>\n" + "        <valueNumeric class=\"int\">1000</valueNumeric>\n" + "        <dataType>NUMERIC_INTEGER</dataType>\n" + "        <isOtherwise>false</isOtherwise>\n" + "      </value>\n" + "    </list>\n" + "  </data>\n" + "</decision-table52>";
    // Build the module with a broken DRL file
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem().write("src/main/resources/org/drools/test/personDrl.drl", typeDrl).write("src/main/resources/dt1.gdst", brokenDrlGenerated);
    KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
    Results buildResults = kieBuilder.getResults();
    int errorsNr = buildResults.getMessages(Message.Level.ERROR).size();
    Assert.assertTrue("Expected build failure", errorsNr > 0);
    // Fix the DRL file
    kfs.write("src/main/resources/dt1.gdst", correctDrlGenerated);
    IncrementalResults results = ((InternalKieBuilder) kieBuilder).createFileSet("src/main/resources/dt1.gdst").build();
    assertEquals(0, results.getAddedMessages().size());
    assertEquals(errorsNr, results.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) KieBuilder(org.kie.api.builder.KieBuilder) InternalKieBuilder(org.kie.internal.builder.InternalKieBuilder) IncrementalResults(org.kie.internal.builder.IncrementalResults) 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