use of org.kie.dmn.api.core.DMNModel in project drools by kiegroup.
the class DMNRuntimeTest method test_countCSATradeRatings.
@Test
public void test_countCSATradeRatings() {
// DROOLS-1563
DMNRuntime runtime = DMNRuntimeUtil.createRuntime("countCSATradeRatings.dmn", this.getClass());
DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_1a7d184c-2e38-4462-ae28-15591ef6d534", "countCSATradeRatings");
assertThat(dmnModel, notNullValue());
assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
DMNContext ctx = runtime.newContext();
List<Map<?, ?>> ratings = new ArrayList<>();
ratings.add(prototype(entry("Agency", "FITCH"), entry("Value", "val1")));
ratings.add(prototype(entry("Agency", "MOODY"), entry("Value", "val2")));
ctx.set("CSA Trade Ratings", ratings);
DMNResult dmnResult = runtime.evaluateAll(dmnModel, ctx);
assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
DMNContext result = dmnResult.getContext();
assertThat(result.get("Trade Ratings"), is(new BigDecimal(2)));
DMNContext ctx2 = runtime.newContext();
ctx2.set("CSA Trade Ratings", null);
DMNResult dmnResult2 = runtime.evaluateAll(dmnModel, ctx2);
assertThat(DMNRuntimeUtil.formatMessages(dmnResult2.getMessages()), dmnResult2.hasErrors(), is(false));
DMNContext result2 = dmnResult2.getContext();
assertThat(result2.get("Trade Ratings"), nullValue());
DMNResult dmnResult3 = runtime.evaluateAll(dmnModel, runtime.newContext());
assertThat(DMNRuntimeUtil.formatMessages(dmnResult3.getMessages()), dmnResult3.hasErrors(), is(true));
assertThat(dmnResult3.getMessages().stream().anyMatch(m -> m.getMessageType().equals(DMNMessageType.REQ_NOT_FOUND)), is(true));
}
use of org.kie.dmn.api.core.DMNModel in project drools by kiegroup.
the class DMNRuntimeTest method testInvalidVariableNames.
@Test
public void testInvalidVariableNames() {
DMNRuntime runtime = DMNRuntimeUtil.createRuntime("invalid-variable-names.dmn", this.getClass());
DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn", "0001-input-data-string");
assertThat(dmnModel, notNullValue());
assertThat(dmnModel.hasErrors(), is(true));
}
use of org.kie.dmn.api.core.DMNModel in project drools by kiegroup.
the class DMNRuntimeTypeCheckTest method assertPerformTypeCheck.
private void assertPerformTypeCheck(DMNRuntime runtime) {
DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_6d8af9a2-dcf4-4b9e-8d90-6ccddc8c1bbd", "forTypeCheckTest");
assertThat(dmnModel, notNullValue());
assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
DMNContext context = DMNFactory.newContext();
context.set("a number", "ciao");
DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
assertThat("Should throw several errors, not only for 1 specific Decision: " + DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.getMessages(DMNMessage.Severity.ERROR).stream().allMatch(m -> m.getSourceId().equals(dmnModel.getDecisionByName("hundred minus number").getId())), is(false));
DMNDecisionResult textPlusNumberDR = dmnResult.getDecisionResultByName("text plus number");
// dependency failed type check
assertThat(textPlusNumberDR.getEvaluationStatus(), is(DecisionEvaluationStatus.SKIPPED));
DMNDecisionResult hundredMinusNumber = dmnResult.getDecisionResultByName("hundred minus number");
// dependency failed type check
assertThat(textPlusNumberDR.getEvaluationStatus(), is(DecisionEvaluationStatus.SKIPPED));
}
use of org.kie.dmn.api.core.DMNModel in project drools by kiegroup.
the class DMNRuntimeTypeCheckTest method assertNoTypeCheck.
private void assertNoTypeCheck(DMNRuntime runtime) {
DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_6d8af9a2-dcf4-4b9e-8d90-6ccddc8c1bbd", "forTypeCheckTest");
assertThat(dmnModel, notNullValue());
assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
DMNContext context = DMNFactory.newContext();
context.set("a number", "ciao");
DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.getMessages(DMNMessage.Severity.ERROR).stream().allMatch(m -> m.getSourceId().equals(dmnModel.getDecisionByName("hundred minus number").getId())), is(true));
DMNDecisionResult textPlusNumberDR = dmnResult.getDecisionResultByName("text plus number");
assertThat(textPlusNumberDR.getEvaluationStatus(), is(DecisionEvaluationStatus.SUCCEEDED));
assertThat(textPlusNumberDR.getResult(), is("The input number is: ciao"));
DMNDecisionResult hundredMinusNumber = dmnResult.getDecisionResultByName("hundred minus number");
assertThat(hundredMinusNumber.getEvaluationStatus(), is(DecisionEvaluationStatus.FAILED));
}
use of org.kie.dmn.api.core.DMNModel in project drools by kiegroup.
the class FlightRebookingTest method testSolution1.
@Test
public void testSolution1() {
DMNRuntime runtime = DMNRuntimeUtil.createRuntime("0019-flight-rebooking.dmn", this.getClass());
DMNModel dmnModel = runtime.getModel("https://www.drools.org/kie-dmn", "0019-flight-rebooking");
assertThat(dmnModel, notNullValue());
// need proper type support to enable this
assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
DMNContext context = DMNFactory.newContext();
List passengerList = loadPassengerList();
List flightList = loadFlightList();
context.set("Passenger List", passengerList);
context.set("Flight List", flightList);
DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
DMNContext result = dmnResult.getContext();
assertThat(result.get("Rebooked Passengers"), is(loadExpectedResult()));
}
Aggregations