use of org.kie.dmn.api.core.DMNContext 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.DMNContext in project drools by kiegroup.
the class DMNUpdateTest method testReplace.
@Test
public void testReplace() {
final KieServices ks = KieServices.Factory.get();
final KieContainer kieContainer = KieHelper.getKieContainer(ks.newReleaseId("org.kie", "dmn-test", "1.0.0"), ks.getResources().newClassPathResource("0001-input-data-string.dmn", this.getClass()));
DMNRuntime runtime = kieContainer.newKieSession().getKieRuntime(DMNRuntime.class);
Assert.assertNotNull(runtime);
assertThat(runtime.getModels(), hasSize(1));
DMNContext dmnContext = runtime.newContext();
dmnContext.set("Full Name", "John Doe");
DMNResult evaluateAll = runtime.evaluateAll(runtime.getModels().get(0), dmnContext);
assertThat(evaluateAll.getDecisionResultByName("Greeting Message").getResult(), is("Hello John Doe"));
ReleaseId v101 = ks.newReleaseId("org.kie", "dmn-test", "1.0.1");
Resource newClassPathResource = ks.getResources().newClassPathResource("0001-input-data-string-itIT.dmn", this.getClass());
newClassPathResource.setTargetPath("0001-input-data-string.dmn");
KieHelper.createAndDeployJar(ks, v101, newClassPathResource);
Results updateResults = kieContainer.updateToVersion(v101);
assertThat(updateResults.hasMessages(Level.ERROR), is(false));
runtime = kieContainer.newKieSession().getKieRuntime(DMNRuntime.class);
Assert.assertNotNull(runtime);
assertThat(runtime.getModels(), hasSize(1));
DMNContext dmnContext2 = runtime.newContext();
dmnContext2.set("Full Name", "John Doe");
DMNResult evaluateAll2 = runtime.evaluateAll(runtime.getModels().get(0), dmnContext2);
assertThat(evaluateAll2.getDecisionResultByName("Greeting Message").getResult(), is("Salve John Doe"));
}
use of org.kie.dmn.api.core.DMNContext 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()));
}
use of org.kie.dmn.api.core.DMNContext in project drools by kiegroup.
the class FlightRebookingTest method testUninterpreted.
@Test
public void testUninterpreted() {
DMNRuntime runtime = DMNRuntimeUtil.createRuntime("0019-flight-rebooking-uninterpreted.dmn", this.getClass());
DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/dmn/definitions/_188d6caf-a355-49b5-a692-bd6ce713da08", "0019-flight-rebooking");
runtime.addListener(DMNRuntimeUtil.createListener());
assertThat(dmnModel, notNullValue());
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);
assertThat(dmnResult.getDecisionResultByName("Rebooked Passengers").getEvaluationStatus(), is(DMNDecisionResult.DecisionEvaluationStatus.SKIPPED));
}
use of org.kie.dmn.api.core.DMNContext in project drools by kiegroup.
the class VacationDaysTest method executeTest.
private void executeTest(int age, int yearsService, int expectedVacationDays) {
DMNRuntime runtime = DMNRuntimeUtil.createRuntime("0020-vacation-days.dmn", this.getClass());
DMNModel dmnModel = runtime.getModel("https://www.drools.org/kie-dmn", "0020-vacation-days");
assertThat(dmnModel, notNullValue());
DMNContext context = DMNFactory.newContext();
context.set("Age", age);
context.set("Years of Service", yearsService);
DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
DMNContext result = dmnResult.getContext();
assertThat(result.get("Total Vacation Days"), is(BigDecimal.valueOf(expectedVacationDays)));
}
Aggregations