use of org.kie.dmn.api.core.DMNRuntime in project drools by kiegroup.
the class DMNRuntimeTest method testSingletonlist_function_call.
@Test
public void testSingletonlist_function_call() {
DMNRuntime runtime = DMNRuntimeUtil.createRuntime("singletonlist_fuction_call.dmn", this.getClass());
DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_0768879b-5ee1-410f-92f0-7732573b069d", "expression function subst [a] with a");
assertThat(dmnModel, notNullValue());
assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
DMNContext ctx = runtime.newContext();
ctx.set("InputLineItem", prototype(entry("Line", "0015"), entry("Description", "additional Battery")));
DMNResult dmnResult = runtime.evaluateAll(dmnModel, ctx);
assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
DMNContext result = dmnResult.getContext();
assertThat(result.get("The Battery"), is(prototype(entry("Line", "0010"), entry("Description", "Battery"))));
assertThat((List<?>) result.get("Remove Battery"), contains(prototype(entry("Line", "0020"), entry("Description", "Case")), prototype(entry("Line", "0030"), entry("Description", "Power Supply"))));
assertThat((List<?>) result.get("Remove Battery"), not(contains(prototype(entry("Line", "0010"), entry("Description", "Battery")))));
assertThat((List<?>) result.get("Insert before Line 0020"), contains(prototype(entry("Line", "0010"), entry("Description", "Battery")), prototype(entry("Line", "0015"), entry("Description", "additional Battery")), prototype(entry("Line", "0020"), entry("Description", "Case")), prototype(entry("Line", "0030"), entry("Description", "Power Supply"))));
}
use of org.kie.dmn.api.core.DMNRuntime in project drools by kiegroup.
the class DMNRuntimeTest method testFiltering.
@Test
public void testFiltering() {
DMNRuntime runtime = DMNRuntimeUtil.createRuntime("Person_filtering_by_age.dmn", getClass());
runtime.addListener(DMNRuntimeUtil.createListener());
DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_e215ed7a-701b-4c53-b8df-4b4d23d5fe32", "Person filtering by age");
assertThat(dmnModel, notNullValue());
assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
DMNContext context = DMNFactory.newContext();
context.set("Min Age", 50);
DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), ((List) dmnResult.getContext().get("Filtering")).size(), is(2));
}
use of org.kie.dmn.api.core.DMNRuntime in project drools by kiegroup.
the class DMNRuntimeTest method testPriority_table.
@Test
public void testPriority_table() {
DMNRuntime runtime = DMNRuntimeUtil.createRuntime("priority_table.dmn", this.getClass());
DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_ff54a44d-b8f5-48fc-b2b7-43db767e8a1c", "not quite all or nothing P");
assertThat(dmnModel, notNullValue());
assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
DMNContext context = runtime.newContext();
context.set("isAffordable", false);
context.set("RiskCategory", "Medium");
DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
DMNContext result = dmnResult.getContext();
assertThat(result.get("Approval Status"), is("Declined"));
}
use of org.kie.dmn.api.core.DMNRuntime in project drools by kiegroup.
the class DMNRuntimeTest method testEx_6_1.
@Test
public void testEx_6_1() {
DMNRuntime runtime = DMNRuntimeUtil.createRuntime("Ex_6_1.dmn", this.getClass());
DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_5f1269c8-1e6f-4748-9eca-26aa1b1278ef", "Ex 6-1");
assertThat(dmnModel, notNullValue());
assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
DMNContext ctx = runtime.newContext();
Map<String, Object> t1 = new HashMap<>();
t1.put("city", "Los Angeles");
t1.put("name", "Los Angeles");
t1.put("wins", 0);
t1.put("losses", 1);
t1.put("bonus points", 40);
Map<String, Object> t2 = new HashMap<>();
t2.put("city", "San Francisco");
t2.put("name", "San Francisco");
t2.put("wins", 1);
t2.put("losses", 0);
t2.put("bonus points", 7);
ctx.set("NBA Pacific", Arrays.asList(new Map[] { t1, t2 }));
DMNResult dmnResult = runtime.evaluateAll(dmnModel, ctx);
assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
DMNContext result = dmnResult.getContext();
assertThat(result.get("Number of distinct cities"), is(new BigDecimal(2)));
assertThat(result.get("Second place losses"), is(new BigDecimal(0)));
assertThat(result.get("Max wins"), is(new BigDecimal(1)));
assertThat(result.get("Mean wins"), is(new BigDecimal(0.5)));
assertThat((List<?>) result.get("Positions of Los Angeles teams"), contains(new BigDecimal(1)));
assertThat(result.get("Number of teams"), is(new BigDecimal(2)));
assertThat(result.get("Sum of bonus points"), is(new BigDecimal(47)));
}
use of org.kie.dmn.api.core.DMNRuntime in project drools by kiegroup.
the class DMNRuntimeTest method testCycleDetectionDeadlyDiamond.
@Test
public void testCycleDetectionDeadlyDiamond() {
DecisionNodeImpl a = new DecisionNodeImpl();
DecisionNodeImpl b = new DecisionNodeImpl();
DecisionNodeImpl c = new DecisionNodeImpl();
DecisionNodeImpl d = new DecisionNodeImpl();
a.addDependency("b", b);
a.addDependency("c", c);
b.addDependency("d", d);
c.addDependency("d", d);
DMNModelImpl model = new DMNModelImpl();
model.addDecision(a);
model.addDecision(b);
model.addDecision(c);
model.addDecision(d);
DMNRuntime runtime = DMNRuntimeUtil.createRuntime(this.getClass());
DMNResult result = runtime.evaluateAll(model, DMNFactory.newContext());
assertFalse(result.hasErrors());
}
Aggregations