Search in sources :

Example 36 with DMNResult

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

the class DMNRuntimeTest method testDROOLS2147.

@Test
public void testDROOLS2147() {
    // DROOLS-2147
    DMNRuntime runtime = DMNRuntimeUtil.createRuntime("DROOLS-2147.dmn", this.getClass());
    DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/dmn/definitions/_cbdacb7b-f72d-457d-b4f4-54020a06db24", "Drawing 1");
    assertThat(dmnModel, notNullValue());
    assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
    DMNContext context = DMNFactory.newContext();
    DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
    DMNContext resultContext = dmnResult.getContext();
    List people = (List) resultContext.get("People");
    List peopleGroups = (List) resultContext.get("People groups");
    assertEquals(6, people.size());
    assertEquals(3, peopleGroups.size());
    assertEquals(2, ((List) peopleGroups.get(0)).size());
    assertEquals(2, ((List) peopleGroups.get(1)).size());
    assertEquals(2, ((List) peopleGroups.get(2)).size());
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) DMNContext(org.kie.dmn.api.core.DMNContext) List(java.util.List) ArrayList(java.util.ArrayList) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) Test(org.junit.Test)

Example 37 with DMNResult

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

the class DMNRuntimeTest method testEnhancedForLoop.

@Test
public void testEnhancedForLoop() {
    // DROOLS-2307
    DMNRuntime runtime = DMNRuntimeUtil.createRuntime("drools2307.dmn", this.getClass());
    DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/dmn/definitions/_03d9481e-dcfc-4a59-9bdd-4f021cb2f0d8", "Drawing 1");
    assertThat(dmnModel, notNullValue());
    assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
    DMNContext emptyContext = DMNFactory.newContext();
    DMNResult dmnResult = runtime.evaluateAll(dmnModel, emptyContext);
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
    DMNContext result = dmnResult.getContext();
    assertThat(result.get("an hardcoded forloop"), is(Arrays.asList(new BigDecimal(2), new BigDecimal(3), new BigDecimal(4))));
}
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 38 with DMNResult

use of org.kie.dmn.api.core.DMNResult 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 39 with DMNResult

use of org.kie.dmn.api.core.DMNResult 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 40 with DMNResult

use of org.kie.dmn.api.core.DMNResult 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)

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