Search in sources :

Example 86 with DMNRuntime

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

the class DMNRuntimeTest method testList.

@Test
public void testList() {
    DMNRuntime runtime = DMNRuntimeUtil.createRuntime("list-expression.dmn", getClass());
    // runtime.addListener( DMNRuntimeUtil.createListener() );
    DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn", "list-expression");
    assertThat(dmnModel, notNullValue());
    assertThat(dmnModel.getMessages().toString(), dmnModel.hasErrors(), is(false));
    DMNContext context = DMNFactory.newContext();
    DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    assertThat(dmnResult.hasErrors(), is(false));
    assertThat(dmnResult.getContext().get("Name list"), is(Arrays.asList("John", "Mary")));
}
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 87 with DMNRuntime

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

the class DMNRuntimeTest method testDinner.

@Test
public void testDinner() {
    DMNRuntime runtime = DMNRuntimeUtil.createRuntime("Dinner.dmn", this.getClass());
    DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_0c45df24-0d57-4acc-b296-b4cba8b71a36", "Dinner");
    assertThat(dmnModel, notNullValue());
    assertThat(dmnModel.hasErrors(), is(false));
    DMNContext context = DMNFactory.newContext();
    context.set("Guests with children", true);
    context.set("Season", "Fall");
    context.set("Number of guests", 4);
    context.set("Temp", 25);
    context.set("Rain Probability", 30);
    DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    assertThat(dmnResult.hasErrors(), is(false));
    assertThat(dmnResult.getContext().get("Where to eat"), is("Outside"));
    assertThat(dmnResult.getContext().get("Dish"), is("Spareribs"));
    assertThat(dmnResult.getContext().get("Drinks"), is(Arrays.asList("Apero", "Ale", "Juice Boxes")));
}
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 88 with DMNRuntime

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

the class DMNRuntimeTest method testErrorMessages.

@Test
public void testErrorMessages() {
    DMNRuntime runtime = DMNRuntimeUtil.createRuntime("car_damage_responsibility2.dmn", this.getClass());
    runtime.addListener(DMNRuntimeUtil.createListener());
    DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/dmn/definitions/_dcc63ab0-3a53-4628-8bee-3ae1f1ad683b", "Car Damage Responsibility");
    assertThat(dmnModel, notNullValue());
    assertThat(dmnModel.hasErrors(), is(true));
}
Also used : DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) Test(org.junit.Test)

Example 89 with DMNRuntime

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

the class DMNRuntimeTest method testBKMNode.

@Test
public void testBKMNode() {
    DMNRuntime runtime = DMNRuntimeUtil.createRuntime("0009-invocation-arithmetic.dmn", getClass());
    // runtime.addListener( DMNRuntimeUtil.createListener() );
    DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_cb28c255-91cd-4c01-ac7b-1a9cb1ecdb11", "literal invocation1");
    assertThat(dmnModel, notNullValue());
    assertThat(dmnModel.getMessages().toString(), dmnModel.hasErrors(), is(false));
    Map<String, Object> loan = new HashMap<>();
    loan.put("amount", BigDecimal.valueOf(600000));
    loan.put("rate", new BigDecimal("0.0375"));
    loan.put("term", BigDecimal.valueOf(360));
    DMNContext context = DMNFactory.newContext();
    context.set("fee", 100);
    context.set("Loan", loan);
    DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    assertThat(dmnResult.hasErrors(), is(false));
    assertThat(((BigDecimal) dmnResult.getContext().get("MonthlyPayment")).setScale(8, BigDecimal.ROUND_DOWN), is(new BigDecimal("2878.69354943277").setScale(8, BigDecimal.ROUND_DOWN)));
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) HashMap(java.util.HashMap) 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) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 90 with DMNRuntime

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

the class DMNRuntimeTest method testResolutionOfVariableWithLeadingOrTrailingSpaces.

@Test
public void testResolutionOfVariableWithLeadingOrTrailingSpaces() {
    // DROOLS-1504
    DMNRuntime runtime = DMNRuntimeUtil.createRuntime("variableLeadingTrailingSpaces.dmn", this.getClass());
    DMNModel dmnModel = runtime.getModel("https://www.drools.org/kie-dmn/definitions", "definitions");
    assertThat(dmnModel, notNullValue());
    assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
    DMNContext context = runtime.newContext();
    Map<String, String> person = new HashMap<>();
    person.put("Name", "John");
    person.put("Surname", "Doe");
    context.set("Input Person", person);
    DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
    DMNContext result = dmnResult.getContext();
    assertThat(result.get("Further Decision"), is("The person was greeted with: 'Ciao John Doe'"));
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) HashMap(java.util.HashMap) 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)

Aggregations

DMNRuntime (org.kie.dmn.api.core.DMNRuntime)178 Test (org.junit.Test)164 DMNModel (org.kie.dmn.api.core.DMNModel)152 DMNContext (org.kie.dmn.api.core.DMNContext)132 DMNResult (org.kie.dmn.api.core.DMNResult)128 KieContainer (org.kie.api.runtime.KieContainer)34 KieServices (org.kie.api.KieServices)30 BigDecimal (java.math.BigDecimal)26 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)26 HashMap (java.util.HashMap)25 List (java.util.List)22 ArrayList (java.util.ArrayList)21 Map (java.util.Map)21 DMNMessage (org.kie.dmn.api.core.DMNMessage)16 CoreMatchers.is (org.hamcrest.CoreMatchers.is)13 CoreMatchers.notNullValue (org.hamcrest.CoreMatchers.notNullValue)13 Results (org.kie.api.builder.Results)13 AfterEvaluateDecisionTableEvent (org.kie.dmn.api.core.event.AfterEvaluateDecisionTableEvent)13 DMNRuntimeEventListener (org.kie.dmn.api.core.event.DMNRuntimeEventListener)13 DecisionNodeImpl (org.kie.dmn.core.ast.DecisionNodeImpl)13