Search in sources :

Example 26 with DMNModel

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));
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) DMNContext(org.kie.dmn.api.core.DMNContext) ArrayList(java.util.ArrayList) List(java.util.List) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) Test(org.junit.Test)

Example 27 with DMNModel

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)));
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) DMNContext(org.kie.dmn.api.core.DMNContext) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel)

Example 28 with DMNModel

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());
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) Results(org.kie.api.builder.Results) KieModuleModel(org.kie.api.builder.model.KieModuleModel) DMNElement(org.kie.dmn.model.v1_1.DMNElement) KieServices(org.kie.api.KieServices) KieBuilder(org.kie.api.builder.KieBuilder) InputData(org.kie.dmn.model.v1_1.InputData) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 29 with DMNModel

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"));
}
Also used : KieFileSystem(org.kie.api.builder.KieFileSystem) KieServices(org.kie.api.KieServices) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) Results(org.kie.api.builder.Results) KieModuleModel(org.kie.api.builder.model.KieModuleModel) DMNElement(org.kie.dmn.model.v1_1.DMNElement) KieBuilder(org.kie.api.builder.KieBuilder) InputData(org.kie.dmn.model.v1_1.InputData) DMNModel(org.kie.dmn.api.core.DMNModel) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 30 with DMNModel

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"));
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) DMNContext(org.kie.dmn.api.core.DMNContext) DMNModel(org.kie.dmn.api.core.DMNModel)

Aggregations

DMNModel (org.kie.dmn.api.core.DMNModel)163 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)152 Test (org.junit.Test)143 DMNContext (org.kie.dmn.api.core.DMNContext)131 DMNResult (org.kie.dmn.api.core.DMNResult)123 BigDecimal (java.math.BigDecimal)26 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)26 HashMap (java.util.HashMap)25 ArrayList (java.util.ArrayList)22 List (java.util.List)22 Map (java.util.Map)22 KieServices (org.kie.api.KieServices)21 KieContainer (org.kie.api.runtime.KieContainer)21 DMNMessage (org.kie.dmn.api.core.DMNMessage)16 CoreMatchers.is (org.hamcrest.CoreMatchers.is)13 CoreMatchers.notNullValue (org.hamcrest.CoreMatchers.notNullValue)13 AfterEvaluateDecisionTableEvent (org.kie.dmn.api.core.event.AfterEvaluateDecisionTableEvent)13 DMNRuntimeEventListener (org.kie.dmn.api.core.event.DMNRuntimeEventListener)13 UUID (java.util.UUID)11 CoreMatchers.nullValue (org.hamcrest.CoreMatchers.nullValue)11