Search in sources :

Example 51 with DMNResult

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

the class DMNRuntimeTest method testDROOLS2200.

@Test
public void testDROOLS2200() {
    // DROOLS-2200
    DMNRuntime runtime = DMNRuntimeUtil.createRuntime("will_be_null_if_negative.dmn", this.getClass());
    DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_c5889555-7ae5-4a67-a872-3a9492caf6e7", "will be null if negative");
    assertThat(dmnModel, notNullValue());
    assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
    DMNContext context = DMNFactory.newContext();
    context.set("a number", -1);
    DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
    DMNContext resultContext = dmnResult.getContext();
    assertThat(((Map) resultContext.get("will be null if negative")).get("s1"), nullValue());
    assertThat(((Map) resultContext.get("will be null if negative")).get("s2"), is("negative"));
}
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 52 with DMNResult

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

the class DMNRuntimeTest method testListContainmentDT.

@Test
public void testListContainmentDT() {
    // DROOLS-2416
    DMNRuntime runtime = DMNRuntimeUtil.createRuntime("list_containment_DT.dmn", this.getClass());
    DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_6ab2bd6d-adaa-45c4-a141-a84382a201eb", "list containment DT");
    assertThat(dmnModel, notNullValue());
    assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
    DMNContext context = DMNFactory.newContext();
    context.set("Passenger", prototype(entry("name", "Osama bin Laden")));
    DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    System.out.println(dmnResult);
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
    DMNContext result = dmnResult.getContext();
    assertThat(result.get("Boarding Status"), is("Denied"));
}
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 53 with DMNResult

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

the class DMNRuntimeTest method testNotificationsApproved2.

@Test
public void testNotificationsApproved2() {
    DMNRuntime runtime = DMNRuntimeUtil.createRuntime("NotificationsTest2.dmn", this.getClass());
    DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn", "building-structure-rules");
    assertThat(dmnModel, notNullValue());
    DMNContext context = DMNFactory.newContext();
    context.set("existingActivityApplicability", true);
    context.set("Distance", new BigDecimal(9999));
    context.set("willIncreaseTraffic", true);
    DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    DMNContext result = dmnResult.getContext();
    assertThat(result.get("Notification Status"), is("Notification to Province Approved"));
    assertThat(result.get("Permit Status"), is("Building Activity Province Permit Required"));
}
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) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 54 with DMNResult

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

the class DMNRuntimeTest method testBoxedContext.

@Test
public void testBoxedContext() {
    DMNRuntime runtime = DMNRuntimeUtil.createRuntime("BoxedContext.dmn", this.getClass());
    DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/dmn/definitions/_0de36357-fec0-4b4e-b7f1-382d381e06e9", "Dessin 1");
    assertThat(dmnModel, notNullValue());
    assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
    DMNContext context = DMNFactory.newContext();
    context.set("a", 10);
    context.set("b", 5);
    DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
    assertThat((Map<String, Object>) dmnResult.getContext().get("Math"), hasEntry("Sum", BigDecimal.valueOf(15)));
    assertThat((Map<String, Object>) dmnResult.getContext().get("Math"), hasEntry("Product", BigDecimal.valueOf(50)));
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) DMNContext(org.kie.dmn.api.core.DMNContext) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) Test(org.junit.Test)

Example 55 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)

Aggregations

DMNResult (org.kie.dmn.api.core.DMNResult)127 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)125 DMNContext (org.kie.dmn.api.core.DMNContext)122 DMNModel (org.kie.dmn.api.core.DMNModel)120 Test (org.junit.Test)119 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)23 BigDecimal (java.math.BigDecimal)22 HashMap (java.util.HashMap)22 KieServices (org.kie.api.KieServices)19 KieContainer (org.kie.api.runtime.KieContainer)19 ArrayList (java.util.ArrayList)16 List (java.util.List)15 Map (java.util.Map)15 DMNMessage (org.kie.dmn.api.core.DMNMessage)12 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 DMNModelImpl (org.kie.dmn.core.impl.DMNModelImpl)10