Search in sources :

Example 71 with DMNContext

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

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

Example 73 with DMNContext

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

the class DMNRuntimeTest method testTrisotechNamespace.

@Test
public void testTrisotechNamespace() {
    DMNRuntime runtime = DMNRuntimeUtil.createRuntime("trisotech_namespace.dmn", this.getClass());
    DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/dmn/definitions/_b8feec86-dadf-4051-9feb-8e6093bbb530", "Solution 3");
    assertThat(dmnModel, notNullValue());
    assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
    DMNContext context = DMNFactory.newContext();
    context.set("IsDoubleHulled", true);
    context.set("Residual Cargo Size", BigDecimal.valueOf(0.1));
    context.set("Ship Size", new BigDecimal(50));
    DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
    DMNContext result = dmnResult.getContext();
    assertThat(result.get("Ship can enter a Dutch port"), is(true));
}
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 74 with DMNContext

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

the class DMNRuntimeTest method testLoanComparison.

@Test
public void testLoanComparison() {
    DMNRuntime runtime = DMNRuntimeUtil.createRuntime("loanComparison.dmn", this.getClass());
    DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_3a1fd8f4-ea04-4453-aa30-ff14140e3441", "loanComparison");
    assertThat(dmnModel, notNullValue());
    assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
    DMNContext context = DMNFactory.newContext();
    context.set("RequestedAmt", 500000);
    DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
}
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 75 with DMNContext

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

the class DMNRuntimeTest method testLoan_Recommendation2.

@Test
public void testLoan_Recommendation2() {
    DMNRuntime runtime = DMNRuntimeUtil.createRuntime("Loan_Recommendation2.dmn", this.getClass());
    DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_35c7339b-b868-43da-8f06-eb481708c73c", "Loan Recommendation2");
    assertThat(dmnModel, notNullValue());
    assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
    Map<String, Object> loan = new HashMap<>();
    loan.put("Amount", 100000);
    loan.put("Rate", 2.39);
    loan.put("Term", 60);
    Map<String, Object> borrower = new HashMap<>();
    borrower.put("Age", 39);
    borrower.put("EmploymentStatus", "Employed");
    borrower.put("YearsAtCurrentEmployer", 10);
    borrower.put("TotalAnnualIncome", 150000);
    borrower.put("NonSalaryIncome", 0);
    borrower.put("MonthlyDebtPmtAmt", 2000);
    borrower.put("LiquidAssetsAmt", 50000);
    DMNContext context = runtime.newContext();
    context.set("Credit Score", null);
    context.set("Appraised Value", 200000);
    context.set("Loan", loan);
    context.set("Borrower", borrower);
    DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
    DMNContext result = dmnResult.getContext();
    assertThat(result.get("Loan Recommendation"), is("Decline"));
}
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

DMNContext (org.kie.dmn.api.core.DMNContext)142 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)130 DMNModel (org.kie.dmn.api.core.DMNModel)129 Test (org.junit.Test)127 DMNResult (org.kie.dmn.api.core.DMNResult)123 HashMap (java.util.HashMap)24 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)24 BigDecimal (java.math.BigDecimal)23 ArrayList (java.util.ArrayList)20 List (java.util.List)20 Map (java.util.Map)20 KieServices (org.kie.api.KieServices)19 KieContainer (org.kie.api.runtime.KieContainer)19 DMNMessage (org.kie.dmn.api.core.DMNMessage)13 DMNRuntimeEventListener (org.kie.dmn.api.core.event.DMNRuntimeEventListener)11 CoreMatchers.is (org.hamcrest.CoreMatchers.is)10 CoreMatchers.notNullValue (org.hamcrest.CoreMatchers.notNullValue)10 AfterEvaluateDecisionTableEvent (org.kie.dmn.api.core.event.AfterEvaluateDecisionTableEvent)10 Collection (java.util.Collection)8 UUID (java.util.UUID)8