Search in sources :

Example 31 with DMNResult

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

the class DMNRuntimeTest method testDrools2125.

@Test
public void testDrools2125() {
    // DROOLS-2125
    DMNRuntime runtime = DMNRuntimeUtil.createRuntime("drools2125.dmn", this.getClass());
    DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_9f976b29-4cdd-42e9-8737-0ccbc2ad9498", "drools2125");
    assertThat(dmnModel, notNullValue());
    assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
    DMNContext context = DMNFactory.newContext();
    context.set("person", "Bob");
    context.set("list of persons", Arrays.asList("Bob", "John"));
    DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
    DMNContext result = dmnResult.getContext();
    assertThat(result.get("person is Bob"), is("yes"));
    assertThat(result.get("persons complies with UT list"), is("yes"));
    assertThat(result.get("person on the list of persons"), is("yes"));
    assertThat(result.get("persons complies with hardcoded list"), is("yes"));
    assertThat(result.get("person is person"), is("yes"));
}
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 32 with DMNResult

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

the class DMNRuntimeTest method testInvokeFunctionWrongDecisionName.

@Test
public void testInvokeFunctionWrongDecisionName() {
    DMNRuntime runtime = DMNRuntimeUtil.createRuntimeWithAdditionalResources("Caller.dmn", this.getClass(), "Calling.dmn");
    DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_b0a696d6-3d57-4e97-b5d4-b44a63909d67", "Caller");
    assertThat(dmnModel, notNullValue());
    DMNContext wrongContext = DMNFactory.newContext();
    wrongContext.set("My Name", "John Doe");
    wrongContext.set("My Number", 3);
    wrongContext.set("Call ns", "http://www.trisotech.com/definitions/_88156d21-3acc-43b6-8b81-385caf0bb6ca");
    wrongContext.set("Call name", "Calling");
    wrongContext.set("Invoke decision", "<unexistent decision>");
    DMNResult dmnResult = runtime.evaluateAll(dmnModel, wrongContext);
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(true));
    // total of: 2. x1 error in calling external decision, and x1 error in making final decision as it depends on the former.
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.getMessages().size(), is(2));
}
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 33 with DMNResult

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

the class DMNRuntimeTest method testNull.

@Test
public void testNull() {
    DMNRuntime runtime = DMNRuntimeUtil.createRuntime("null_values.dmn", this.getClass());
    DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn", "Null values model");
    assertThat(dmnModel, notNullValue());
    assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
    DMNContext context = runtime.newContext();
    context.set("Null Input", null);
    DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
    DMNContext result = dmnResult.getContext();
    assertThat(result.get("Null value"), is("Input is null"));
    context = runtime.newContext();
    context.set("Null Input", "foo");
    dmnResult = runtime.evaluateAll(dmnModel, context);
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
    result = dmnResult.getContext();
    assertThat(result.get("Null value"), is("Input is not null"));
}
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 34 with DMNResult

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

the class DMNRuntimeTest method testArtificialAttributes.

@Test
public void testArtificialAttributes() {
    DMNRuntime runtime = DMNRuntimeUtil.createRuntime("0001-input-data-string-artificial-attributes.dmn", this.getClass());
    DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/drools", "0001-input-data-string");
    assertThat(dmnModel, notNullValue());
    DMNContext context = DMNFactory.newContext();
    context.set("Full Name", "John Doe");
    DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    assertThat(dmnResult.getDecisionResults().size(), is(1));
    assertThat(dmnResult.getDecisionResultByName("Greeting Message").getResult(), is("Hello John Doe"));
    DMNContext result = dmnResult.getContext();
    assertThat(result.get("Greeting Message"), is("Hello John Doe"));
}
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 35 with DMNResult

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

the class DMNRuntimeTest method testEmptyDecision1.

@Test
public void testEmptyDecision1() {
    DMNRuntime runtime = DMNRuntimeUtil.createRuntime("empty_decision.dmn", this.getClass());
    DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/dmn/definitions/_ba9fc4b1-5ced-4d00-9b61-290de4bf3213", "Solution 3");
    assertThat(dmnModel, notNullValue());
    DMNContext context = DMNFactory.newContext();
    Map shipInfo = new HashMap();
    shipInfo.put("Size", BigDecimal.valueOf(70));
    shipInfo.put("Is Double Hulled", Boolean.FALSE);
    shipInfo.put("Residual Cargo Size", BigDecimal.valueOf(0.1));
    context.set("Ship Info", shipInfo);
    // Test that even if one decision is empty or missing input data,
    // the other decisions in the model are still evaluated
    DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    DMNContext result = dmnResult.getContext();
    assertThat(dmnResult.hasErrors(), is(true));
    assertThat(result.get("Ship Can Enter v2"), is(true));
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) HashMap(java.util.HashMap) DMNContext(org.kie.dmn.api.core.DMNContext) Map(java.util.Map) HashMap(java.util.HashMap) 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