Search in sources :

Example 1 with DMNResult

use of org.kie.dmn.api.core.DMNResult in project drools by kiegroup.

the class DMNAssemblerTest method testStrictMode.

@Test
public void testStrictMode() {
    System.setProperty("org.kie.dmn.strictConformance", "true");
    DMNRuntime runtime = DMNRuntimeUtil.createRuntime("strictMode.dmn", this.getClass());
    DMNModel model = runtime.getModel("http://www.trisotech.com/dmn/definitions/_ecf4ea54-2abc-4e2f-a101-4fe14e356a46", "strictMode");
    DMNContext ctx = runtime.newContext();
    ctx.set("timestring", "2016-12-20T14:30:22z");
    DMNResult result = runtime.evaluateAll(model, ctx);
    assertNull(result.getDecisionResultByName("time").getResult());
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) DMNContext(org.kie.dmn.api.core.DMNContext) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) Test(org.junit.Test)

Example 2 with DMNResult

use of org.kie.dmn.api.core.DMNResult in project drools by kiegroup.

the class DMNAssemblerTest method testStrictModeProp.

@Test
public void testStrictModeProp() {
    final KieServices services = KieServices.Factory.get();
    final KieFileSystem fileSystem = services.newKieFileSystem();
    KieModuleModel moduleModel = services.newKieModuleModel();
    moduleModel.setConfigurationProperty("org.kie.dmn.strictConformance", "true");
    fileSystem.writeKModuleXML(moduleModel.toXML());
    fileSystem.write(services.getResources().newClassPathResource("strictMode.dmn", this.getClass()));
    services.newKieBuilder(fileSystem).buildAll();
    final KieContainer container = services.newKieContainer(services.getRepository().getDefaultReleaseId());
    DMNRuntime runtime = container.newKieSession().getKieRuntime(DMNRuntime.class);
    DMNModel model = runtime.getModel("http://www.trisotech.com/dmn/definitions/_ecf4ea54-2abc-4e2f-a101-4fe14e356a46", "strictMode");
    DMNContext ctx = runtime.newContext();
    ctx.set("timestring", "2016-12-20T14:30:22z");
    DMNResult result = runtime.evaluateAll(model, ctx);
    assertNull(result.getDecisionResultByName("time").getResult());
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) KieFileSystem(org.kie.api.builder.KieFileSystem) KieModuleModel(org.kie.api.builder.model.KieModuleModel) DMNContext(org.kie.dmn.api.core.DMNContext) KieServices(org.kie.api.KieServices) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 3 with DMNResult

use of org.kie.dmn.api.core.DMNResult in project drools by kiegroup.

the class DMNCompilerTest method testImport.

@Test
public void testImport() {
    System.out.println(null instanceof Definitions);
    DMNRuntime runtime = DMNRuntimeUtil.createRuntimeWithAdditionalResources("Importing_Model.dmn", this.getClass(), "Imported_Model.dmn");
    DMNModel importedModel = runtime.getModel("http://www.trisotech.com/dmn/definitions/_f27bb64b-6fc7-4e1f-9848-11ba35e0df36", "Imported Model");
    assertThat(importedModel, notNullValue());
    for (DMNMessage message : importedModel.getMessages()) {
        LOG.debug("{}", message);
    }
    DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/dmn/definitions/_f79aa7a4-f9a3-410a-ac95-bea496edab52", "Importing Model");
    assertThat(dmnModel, notNullValue());
    for (DMNMessage message : dmnModel.getMessages()) {
        LOG.debug("{}", message);
    }
    DMNContext context = runtime.newContext();
    context.set("A Person", mapOf(entry("name", "John"), entry("age", 47)));
    DMNResult evaluateAll = runtime.evaluateAll(dmnModel, context);
    for (DMNMessage message : evaluateAll.getMessages()) {
        LOG.debug("{}", message);
    }
    LOG.debug("{}", evaluateAll);
    assertThat(evaluateAll.getDecisionResultByName("Greeting").getResult(), is("Hello John!"));
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) DMNMessage(org.kie.dmn.api.core.DMNMessage) Definitions(org.kie.dmn.model.v1_1.Definitions) DMNContext(org.kie.dmn.api.core.DMNContext) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) Test(org.junit.Test)

Example 4 with DMNResult

use of org.kie.dmn.api.core.DMNResult in project drools by kiegroup.

the class DMNDecisionTableHitPolicyTest method testSimpleDecisionTableHitPolicyUniqueNullWarn.

@Test
public void testSimpleDecisionTableHitPolicyUniqueNullWarn() {
    final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("0004-simpletable-U-noinputvalues.dmn", this.getClass());
    final DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn", "0004-simpletable-U-noinputvalues");
    assertThat(dmnModel, notNullValue());
    final DMNContext context = getSimpleTableContext(BigDecimal.valueOf(18), "ASD", false);
    final DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    final DMNContext result = dmnResult.getContext();
    assertThat(result.get("Approval Status"), nullValue());
    assertTrue(dmnResult.getMessages().size() > 0);
    assertTrue(dmnResult.getMessages().stream().anyMatch(dm -> dm.getSeverity().equals(DMNMessage.Severity.WARN) && dm.getFeelEvent() instanceof HitPolicyViolationEvent && dm.getFeelEvent().getSeverity().equals(FEELEvent.Severity.WARN)));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) Matchers.hasEntry(org.hamcrest.Matchers.hasEntry) HitPolicyViolationEvent(org.kie.dmn.feel.runtime.events.HitPolicyViolationEvent) DMNFactory(org.kie.dmn.core.api.DMNFactory) DMNMessage(org.kie.dmn.api.core.DMNMessage) DMNResult(org.kie.dmn.api.core.DMNResult) Test(org.junit.Test) DMNRuntimeUtil(org.kie.dmn.core.util.DMNRuntimeUtil) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) BigDecimal(java.math.BigDecimal) List(java.util.List) DMNModel(org.kie.dmn.api.core.DMNModel) Matchers.contains(org.hamcrest.Matchers.contains) FEELEvent(org.kie.dmn.api.feel.runtime.events.FEELEvent) Map(java.util.Map) DMNContext(org.kie.dmn.api.core.DMNContext) Matchers.hasSize(org.hamcrest.Matchers.hasSize) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) Assert(org.junit.Assert) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) Matchers.isEmptyOrNullString(org.hamcrest.Matchers.isEmptyOrNullString) DMNResult(org.kie.dmn.api.core.DMNResult) DMNContext(org.kie.dmn.api.core.DMNContext) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) HitPolicyViolationEvent(org.kie.dmn.feel.runtime.events.HitPolicyViolationEvent) Test(org.junit.Test)

Example 5 with DMNResult

use of org.kie.dmn.api.core.DMNResult in project drools by kiegroup.

the class DMNDecisionTableHitPolicyTest method testDecisionTableHitPolicyUnique.

@Test
public void testDecisionTableHitPolicyUnique() {
    final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("BranchDistribution.dmn", this.getClass());
    final DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/dmn/definitions/_cdf29af2-959b-4004-8271-82a9f5a62147", "Dessin 1");
    assertThat(dmnModel, notNullValue());
    final DMNContext context = DMNFactory.newContext();
    context.set("Branches dispersion", "Province");
    context.set("Number of Branches", BigDecimal.valueOf(10));
    final DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    assertThat(dmnResult.hasErrors(), is(false));
    final DMNContext result = dmnResult.getContext();
    assertThat(result.get("Branches distribution"), is("Medium"));
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) DMNContext(org.kie.dmn.api.core.DMNContext) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) Test(org.junit.Test)

Aggregations

DMNResult (org.kie.dmn.api.core.DMNResult)139 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)135 DMNContext (org.kie.dmn.api.core.DMNContext)134 DMNModel (org.kie.dmn.api.core.DMNModel)130 Test (org.junit.Test)127 HashMap (java.util.HashMap)24 BigDecimal (java.math.BigDecimal)23 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)23 KieServices (org.kie.api.KieServices)22 KieContainer (org.kie.api.runtime.KieContainer)22 ArrayList (java.util.ArrayList)19 List (java.util.List)17 Map (java.util.Map)17 DMNDecisionResult (org.kie.dmn.api.core.DMNDecisionResult)16 DMNMessage (org.kie.dmn.api.core.DMNMessage)13 CoreMatchers.is (org.hamcrest.CoreMatchers.is)10 CoreMatchers.notNullValue (org.hamcrest.CoreMatchers.notNullValue)10 AfterEvaluateDecisionTableEvent (org.kie.dmn.api.core.event.AfterEvaluateDecisionTableEvent)10 DMNRuntimeEventListener (org.kie.dmn.api.core.event.DMNRuntimeEventListener)10 DecisionNodeImpl (org.kie.dmn.core.ast.DecisionNodeImpl)10