use of org.kie.dmn.api.core.DMNModel 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.DMNModel 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)));
}
use of org.kie.dmn.api.core.DMNModel in project drools by kiegroup.
the class DMNExtensionRegisterTest method testUsingKModuleProperty_WrongClasses.
@Test
public void testUsingKModuleProperty_WrongClasses() {
final KieServices ks = KieServices.Factory.get();
final KieFileSystem kfs = ks.newKieFileSystem();
KieModuleModel kmm = ks.newKieModuleModel();
kmm.setConfigurationProperty("org.kie.dmn.profiles.FirstNameLastNameProfile", "foo");
kfs.writeKModuleXML(kmm.toXML());
kfs.write(ks.getResources().newClassPathResource("0001-input-data-string-with-extensions.dmn", this.getClass()));
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
Results results = kieBuilder.getResults();
LOG.info("buildAll() completed.");
results.getMessages(Level.WARNING).forEach(e -> LOG.warn("{}", e));
assertTrue(results.getMessages(Level.WARNING).size() > 0);
final KieContainer kieContainer = ks.newKieContainer(ks.getRepository().getDefaultReleaseId());
DMNRuntime runtime = kieContainer.newKieSession().getKieRuntime(DMNRuntime.class);
DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn", "0001-input-data-string");
assertThat(dmnModel, notNullValue());
assertThat(formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
assertEquals(3, dmnModel.getDefinitions().getDrgElement().size());
InputData inputData1 = (InputData) dmnModel.getDefinitions().getDrgElement().get(1);
assertEquals("First Name", inputData1.getName());
DMNElement.ExtensionElements id1elements = inputData1.getExtensionElements();
assertTrue(id1elements != null);
assertEquals(0, id1elements.getAny().size());
InputData inputData2 = (InputData) dmnModel.getDefinitions().getDrgElement().get(2);
assertEquals("Last Name", inputData2.getName());
DMNElement.ExtensionElements id2elements = inputData2.getExtensionElements();
assertTrue(id2elements != null);
assertEquals(0, id2elements.getAny().size());
}
use of org.kie.dmn.api.core.DMNModel in project drools by kiegroup.
the class DMNExtensionRegisterTest method testUsingKModuleProperty.
@Test
public void testUsingKModuleProperty() {
final KieServices ks = KieServices.Factory.get();
final KieFileSystem kfs = ks.newKieFileSystem();
KieModuleModel kmm = ks.newKieModuleModel();
kmm.setConfigurationProperty("org.kie.dmn.profiles.FirstNameLastNameProfile", FirstNameLastNameProfile.class.getCanonicalName());
kfs.writeKModuleXML(kmm.toXML());
kfs.write(ks.getResources().newClassPathResource("0001-input-data-string-with-extensions.dmn", this.getClass()));
KieBuilder kieBuilder = ks.newKieBuilder(kfs).buildAll();
Results results = kieBuilder.getResults();
LOG.info("buildAll() completed.");
results.getMessages(Level.WARNING).forEach(e -> LOG.warn("{}", e));
assertTrue(results.getMessages(Level.WARNING).size() == 0);
final KieContainer kieContainer = ks.newKieContainer(ks.getRepository().getDefaultReleaseId());
DMNRuntime runtime = kieContainer.newKieSession().getKieRuntime(DMNRuntime.class);
DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn", "0001-input-data-string");
assertThat(dmnModel, notNullValue());
assertThat(formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
assertEquals(3, dmnModel.getDefinitions().getDrgElement().size());
InputData inputData1 = (InputData) dmnModel.getDefinitions().getDrgElement().get(1);
assertEquals("First Name", inputData1.getName());
DMNElement.ExtensionElements id1elements = inputData1.getExtensionElements();
assertTrue(id1elements != null);
assertEquals(1, id1elements.getAny().size());
FirstNameDescription firstNameDescription = (FirstNameDescription) id1elements.getAny().get(0);
assertTrue(firstNameDescription.getContent().equals("First name in latin characters"));
InputData inputData2 = (InputData) dmnModel.getDefinitions().getDrgElement().get(2);
assertEquals("Last Name", inputData2.getName());
DMNElement.ExtensionElements id2elements = inputData2.getExtensionElements();
assertTrue(id2elements != null);
assertEquals(1, id2elements.getAny().size());
LastNameDescription lastNameDescription = (LastNameDescription) id2elements.getAny().get(0);
assertTrue(lastNameDescription.getContent().equals("Last name in latin characters"));
}
use of org.kie.dmn.api.core.DMNModel in project drools by kiegroup.
the class SignavioTest method assertStartsWithAnA.
private void assertStartsWithAnA(final DMNRuntime runtime, final String testString, final boolean startsWithAnA) {
DMNContext context = runtime.newContext();
context.set("surname", testString);
DMNModel model0 = runtime.getModels().get(0);
DMNResult evaluateAll = runtime.evaluateAll(model0, context);
evaluateAll.getMessages().forEach(System.out::println);
assertFalse(evaluateAll.getMessages().toString(), evaluateAll.hasErrors());
assertEquals(startsWithAnA, evaluateAll.getContext().get("startsWithAnA"));
}
Aggregations