use of org.kie.dmn.api.core.DMNModel 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));
}
use of org.kie.dmn.api.core.DMNModel 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));
}
use of org.kie.dmn.api.core.DMNModel 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"));
}
use of org.kie.dmn.api.core.DMNModel in project drools by kiegroup.
the class DMNRuntimeTest method testCompositeItemDefinition.
@Test
public void testCompositeItemDefinition() {
DMNRuntime runtime = DMNRuntimeUtil.createRuntime("0008-LX-arithmetic.dmn", this.getClass());
DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn", "0008-LX-arithmetic");
assertThat(dmnModel, notNullValue());
DMNContext context = DMNFactory.newContext();
Map loan = new HashMap();
loan.put("principal", 600000);
loan.put("rate", 0.0375);
loan.put("termMonths", 360);
context.set("loan", loan);
DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
DMNContext result = dmnResult.getContext();
assertThat(result.get("payment"), is(new BigDecimal("2778.693549432766768088520383236299")));
}
use of org.kie.dmn.api.core.DMNModel in project drools by kiegroup.
the class DMNRuntimeTest method testDateAllowedValues.
@Test
public void testDateAllowedValues() {
DMNRuntime runtime = DMNRuntimeUtil.createRuntime("date_allowed_values.dmn", this.getClass());
DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_fbf002a3-615b-4f02-98e4-c28d4676225a", "Error with constraints verification");
assertThat(dmnModel, notNullValue());
assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
DMNContext ctx = runtime.newContext();
Object duration = BuiltInType.DURATION.fromString("P20Y");
ctx.set("yearsMonth", duration);
Object dateTime = BuiltInType.DATE_TIME.fromString("2017-05-16T17:58:00.000");
ctx.set("dateTime", dateTime);
DMNResult dmnResult = runtime.evaluateAll(dmnModel, ctx);
DMNContext result = dmnResult.getContext();
assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
assertThat((Map<String, Object>) result.get("Decision Logic 1"), hasEntry("years and months", duration));
assertThat((Map<String, Object>) result.get("Decision Logic 1"), hasEntry("Date Time", dateTime));
}
Aggregations