Search in sources :

Example 36 with Results

use of org.kie.api.builder.Results in project drools by kiegroup.

the class AdapterTest method testCustomInputAdapter.

@Test
public void testCustomInputAdapter() {
    String source = PMML4Helper.pmmlDefaultPackageName().replace(".", "/") + "/" + "mock_cold_adapter.xml";
    KieServices ks = KieServices.Factory.get();
    KieFileSystem kfs = ks.newKieFileSystem();
    kfs.write(ResourceFactory.newClassPathResource(source).setResourceType(ResourceType.PMML));
    Results res = ks.newKieBuilder(kfs).buildAll().getResults();
    if (res.hasMessages(Message.Level.ERROR)) {
        System.out.println(res.getMessages(Message.Level.ERROR));
    }
    assertEquals(0, res.getMessages(Message.Level.ERROR).size());
    KieBase kieBase = ks.newKieContainer(ks.getRepository().getDefaultReleaseId()).getKieBase();
    FactType ft = kieBase.getFactType("test", "MyAdapter");
    assertTrue(ft != null);
    assertTrue(ft.getFactClass().isInterface());
    FactType fto = kieBase.getFactType("test", "MyOutAdapter");
    assertTrue(fto != null);
    assertTrue(fto.getFactClass().isInterface());
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Results(org.kie.api.builder.Results) KieBase(org.kie.api.KieBase) KieServices(org.kie.api.KieServices) FactType(org.kie.api.definition.type.FactType) Test(org.junit.Test) DroolsAbstractPMMLTest(org.kie.pmml.pmml_4_2.DroolsAbstractPMMLTest)

Example 37 with Results

use of org.kie.api.builder.Results in project drools by kiegroup.

the class GuidedDTableParsingIntegrationTest method testGuidedDTableWithDSLSuccessfullyCompiled.

@Test
public void testGuidedDTableWithDSLSuccessfullyCompiled() {
    String personDrl = "package org.drools.test\n" + "declare Person\n" + "  adult : boolean\n" + "end";
    String personDsl = "[when]When the person is adult = person:org.drools.test.Person(adult==\"true\")";
    String guidedDTable = "<decision-table52>\n" + "  <tableName>test</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" + "    <org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn>\n" + "      <hideColumn>false</hideColumn>\n" + "      <width>-1</width>\n" + "      <header>test</header>\n" + "      <constraintValueType>1</constraintValueType>\n" + "      <parameters/>\n" + "      <definition>\n" + "        <org.drools.workbench.models.datamodel.rule.DSLSentence>\n" + "          <drl>person:org.drools.test.Person(adult==\"true\")</drl>\n" + "          <definition>When the person is adult</definition>\n" + "          <values>\n" + "            <org.drools.workbench.models.datamodel.rule.DSLVariableValue>\n" + "              <value>false</value>\n" + "            </org.drools.workbench.models.datamodel.rule.DSLVariableValue>\n" + "          </values>\n" + "        </org.drools.workbench.models.datamodel.rule.DSLSentence>\n" + "      </definition>\n" + "      <childColumns>\n" + "        <org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn>\n" + "          <hideColumn>false</hideColumn>\n" + "          <width>-1</width>\n" + "          <header>test</header>\n" + "          <constraintValueType>1</constraintValueType>\n" + "          <fieldType>Boolean</fieldType>\n" + "          <parameters/>\n" + "          <varName></varName>\n" + "        </org.drools.workbench.models.guided.dtable.shared.model.BRLConditionVariableColumn>\n" + "      </childColumns>\n" + "    </org.drools.workbench.models.guided.dtable.shared.model.BRLConditionColumn>\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" + "  <packageName>org.drools.test</packageName>\n" + "  <tableFormat>EXTENDED_ENTRY</tableFormat>\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" + "        <valueBoolean>false</valueBoolean>\n" + "        <valueString></valueString>\n" + "        <dataType>BOOLEAN</dataType>\n" + "        <isOtherwise>false</isOtherwise>\n" + "      </value>\n" + "    </list>\n" + "    <list>\n" + "      <value>\n" + "        <valueNumeric class=\"int\">2</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" + "        <valueBoolean>true</valueBoolean>\n" + "        <valueString></valueString>\n" + "        <dataType>BOOLEAN</dataType>\n" + "        <isOtherwise>false</isOtherwise>\n" + "      </value>\n" + "    </list>\n" + "  </data>\n" + "</decision-table52>";
    KieHelper kieHelper = new KieHelper();
    kieHelper.addContent(personDrl, ResourceType.DRL);
    kieHelper.addContent(personDsl, ResourceType.DSL);
    kieHelper.addContent(guidedDTable, ResourceType.GDST);
    Results buildResults = kieHelper.verify();
    assertEquals("No build failures", Collections.emptyList(), buildResults.getMessages(Message.Level.ERROR));
    // make sure the dtable was actually processed and knowledge packages created
    KieBase kieBase = kieHelper.build();
    Assert.assertNotNull("Rule generated from guided dtable not found!", kieBase.getRule("org.drools.test", "Row 1 test"));
}
Also used : Results(org.kie.api.builder.Results) IncrementalResults(org.kie.internal.builder.IncrementalResults) KieBase(org.kie.api.KieBase) KieHelper(org.kie.internal.utils.KieHelper) Test(org.junit.Test)

Example 38 with Results

use of org.kie.api.builder.Results 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)

Example 39 with Results

use of org.kie.api.builder.Results in project drools by kiegroup.

the class GuidedDTableParsingIntegrationTest method testGuidedDTableWithNoDSLSuccessfullyCompiled.

@Test
public void testGuidedDTableWithNoDSLSuccessfullyCompiled() {
    String personDrl = "package org.drools.test\n" + "declare Person\n" + "  adult : boolean\n" + "end";
    String guidedDTable = "<decision-table52>\n" + "  <tableName>test1</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.Person</factType>\n" + "      <boundName>person</boundName>\n" + "      <isNegated>false</isNegated>\n" + "      <conditions>\n" + "        <condition-column52>\n" + "          <typedDefaultValue>\n" + "            <valueBoolean>false</valueBoolean>\n" + "            <valueString></valueString>\n" + "            <dataType>BOOLEAN</dataType>\n" + "            <isOtherwise>false</isOtherwise>\n" + "          </typedDefaultValue>\n" + "          <hideColumn>false</hideColumn>\n" + "          <width>-1</width>\n" + "          <header>Header</header>\n" + "          <constraintValueType>1</constraintValueType>\n" + "          <factField>adult</factField>\n" + "          <fieldType>Boolean</fieldType>\n" + "          <operator>==</operator>\n" + "          <parameters/>\n" + "        </condition-column52>\n" + "      </conditions>\n" + "      <window>\n" + "        <parameters/>\n" + "      </window>\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>org.drools.test</packageName>\n" + "  <tableFormat>EXTENDED_ENTRY</tableFormat>\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" + "        <valueBoolean>true</valueBoolean>\n" + "        <valueString></valueString>\n" + "        <dataType>BOOLEAN</dataType>\n" + "        <isOtherwise>false</isOtherwise>\n" + "      </value>\n" + "    </list>\n" + "  </data>\n" + "</decision-table52>";
    KieHelper kieHelper = new KieHelper();
    kieHelper.addContent(personDrl, ResourceType.DRL);
    kieHelper.addContent(guidedDTable, ResourceType.GDST);
    Results buildResults = kieHelper.verify();
    assertEquals("No build failures", Collections.emptyList(), buildResults.getMessages(Message.Level.ERROR));
    // make sure the dtable was actually processed and knowledge packages created
    KieBase kieBase = kieHelper.build();
    Assert.assertNotNull("Rule generated from guided dtable not found!", kieBase.getRule("org.drools.test", "Row 1 test1"));
}
Also used : Results(org.kie.api.builder.Results) IncrementalResults(org.kie.internal.builder.IncrementalResults) KieBase(org.kie.api.KieBase) KieHelper(org.kie.internal.utils.KieHelper) Test(org.junit.Test)

Example 40 with Results

use of org.kie.api.builder.Results in project drools by kiegroup.

the class DMNAssemblerTest method testDuplicateModel.

@Test
public void testDuplicateModel() {
    final KieServices ks = KieServices.Factory.get();
    final KieFileSystem kfs = ks.newKieFileSystem();
    kfs.write(ks.getResources().newClassPathResource("0001-input-data-string.dmn", this.getClass()));
    kfs.write(ks.getResources().newClassPathResource("duplicate.0001-input-data-string.dmn", this.getClass()));
    Results results = ks.newKieBuilder(kfs).buildAll().getResults();
    LOG.info("buildAll() completed.");
    results.getMessages(Level.ERROR).forEach(e -> LOG.error("{}", e));
    assertTrue(results.getMessages(Level.ERROR).size() > 0);
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Results(org.kie.api.builder.Results) KieServices(org.kie.api.KieServices) Test(org.junit.Test)

Aggregations

Results (org.kie.api.builder.Results)92 Test (org.junit.Test)81 KieServices (org.kie.api.KieServices)72 KieFileSystem (org.kie.api.builder.KieFileSystem)60 KieContainer (org.kie.api.runtime.KieContainer)36 KieBuilder (org.kie.api.builder.KieBuilder)32 KieSession (org.kie.api.runtime.KieSession)25 IncrementalResults (org.kie.internal.builder.IncrementalResults)20 ReleaseId (org.kie.api.builder.ReleaseId)19 QueryResults (org.kie.api.runtime.rule.QueryResults)17 StatelessKieSession (org.kie.api.runtime.StatelessKieSession)15 KieBase (org.kie.api.KieBase)14 InternalKieBuilder (org.kie.internal.builder.InternalKieBuilder)13 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)11 KieHelper (org.kie.internal.utils.KieHelper)11 KieModuleModel (org.kie.api.builder.model.KieModuleModel)10 FactType (org.kie.api.definition.type.FactType)10 ArrayList (java.util.ArrayList)9 FlatQueryResults (org.drools.core.runtime.rule.impl.FlatQueryResults)9 InternalKieModule (org.drools.compiler.kie.builder.impl.InternalKieModule)7