Search in sources :

Example 66 with DMNModel

use of org.kie.dmn.api.core.DMNModel in project drools by kiegroup.

the class DMNRuntimeTest method testOutOfOrderItemsNPE.

@Test
public void testOutOfOrderItemsNPE() {
    DMNRuntime runtime = DMNRuntimeUtil.createRuntime("out-of-order-items.dmn", this.getClass());
    DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn", "out-of-order");
    assertThat(dmnModel, notNullValue());
    assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.getMessages().stream().anyMatch(m -> m.getMessageType().equals(DMNMessageType.FAILED_VALIDATOR)), is(false));
}
Also used : BeforeEvaluateDecisionTableEvent(org.kie.dmn.api.core.event.BeforeEvaluateDecisionTableEvent) CoreMatchers.is(org.hamcrest.CoreMatchers.is) Arrays(java.util.Arrays) DMNMessage(org.kie.dmn.api.core.DMNMessage) DMNResult(org.kie.dmn.api.core.DMNResult) ZonedDateTime(java.time.ZonedDateTime) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) CoreMatchers.instanceOf(org.hamcrest.CoreMatchers.instanceOf) Assert.assertThat(org.junit.Assert.assertThat) BigDecimal(java.math.BigDecimal) DMNModel(org.kie.dmn.api.core.DMNModel) Duration(java.time.Duration) Map(java.util.Map) LocalTime(java.time.LocalTime) ZoneOffset(java.time.ZoneOffset) OffsetTime(java.time.OffsetTime) BeforeEvaluateDecisionEvent(org.kie.dmn.api.core.event.BeforeEvaluateDecisionEvent) DMNRuntimeEventListener(org.kie.dmn.api.core.event.DMNRuntimeEventListener) DMNFactory(org.kie.dmn.core.api.DMNFactory) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) Collection(java.util.Collection) BuiltInType(org.kie.dmn.feel.lang.types.BuiltInType) DMNModelImpl(org.kie.dmn.core.impl.DMNModelImpl) UUID(java.util.UUID) ItemDefinition(org.kie.dmn.model.v1_1.ItemDefinition) Collectors(java.util.stream.Collectors) DMNRuntimeUtil(org.kie.dmn.core.util.DMNRuntimeUtil) Matchers.any(org.mockito.Matchers.any) List(java.util.List) Matchers.contains(org.hamcrest.Matchers.contains) VerificationModeFactory.times(org.mockito.internal.verification.VerificationModeFactory.times) Assert.assertFalse(org.junit.Assert.assertFalse) LocalDate(java.time.LocalDate) DMNContext(org.kie.dmn.api.core.DMNContext) FEELStringMarshaller(org.kie.dmn.feel.marshaller.FEELStringMarshaller) KieHelper(org.kie.dmn.core.util.KieHelper) DMNDecisionResult(org.kie.dmn.api.core.DMNDecisionResult) AfterEvaluateDecisionEvent(org.kie.dmn.api.core.event.AfterEvaluateDecisionEvent) EvalHelper(org.kie.dmn.feel.util.EvalHelper) Mockito.mock(org.mockito.Mockito.mock) AfterEvaluateDecisionTableEvent(org.kie.dmn.api.core.event.AfterEvaluateDecisionTableEvent) DynamicTypeUtils.prototype(org.kie.dmn.core.util.DynamicTypeUtils.prototype) DMNMessageType(org.kie.dmn.api.core.DMNMessageType) CoreMatchers.not(org.hamcrest.CoreMatchers.not) DynamicTypeUtils.entry(org.kie.dmn.core.util.DynamicTypeUtils.entry) HashMap(java.util.HashMap) ArrayList(java.util.ArrayList) ArgumentCaptor(org.mockito.ArgumentCaptor) KieServices(org.kie.api.KieServices) Matchers.hasSize(org.hamcrest.Matchers.hasSize) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) CoreMatchers.nullValue(org.hamcrest.CoreMatchers.nullValue) Period(java.time.Period) Matchers.hasEntry(org.hamcrest.Matchers.hasEntry) KieContainer(org.kie.api.runtime.KieContainer) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) Mockito.verify(org.mockito.Mockito.verify) Ignore(org.junit.Ignore) Assert.assertEquals(org.junit.Assert.assertEquals) DecisionNodeImpl(org.kie.dmn.core.ast.DecisionNodeImpl) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) Test(org.junit.Test)

Example 67 with DMNModel

use of org.kie.dmn.api.core.DMNModel in project drools by kiegroup.

the class DMNRuntimeTest method testBoxedContext.

@Test
public void testBoxedContext() {
    DMNRuntime runtime = DMNRuntimeUtil.createRuntime("BoxedContext.dmn", this.getClass());
    DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/dmn/definitions/_0de36357-fec0-4b4e-b7f1-382d381e06e9", "Dessin 1");
    assertThat(dmnModel, notNullValue());
    assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
    DMNContext context = DMNFactory.newContext();
    context.set("a", 10);
    context.set("b", 5);
    DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
    assertThat((Map<String, Object>) dmnResult.getContext().get("Math"), hasEntry("Sum", BigDecimal.valueOf(15)));
    assertThat((Map<String, Object>) dmnResult.getContext().get("Math"), hasEntry("Product", BigDecimal.valueOf(50)));
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) DMNContext(org.kie.dmn.api.core.DMNContext) CoreMatchers.containsString(org.hamcrest.CoreMatchers.containsString) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) Test(org.junit.Test)

Example 68 with DMNModel

use of org.kie.dmn.api.core.DMNModel in project drools by kiegroup.

the class DMNRuntimeTest method testDrools2125.

@Test
public void testDrools2125() {
    // DROOLS-2125
    DMNRuntime runtime = DMNRuntimeUtil.createRuntime("drools2125.dmn", this.getClass());
    DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_9f976b29-4cdd-42e9-8737-0ccbc2ad9498", "drools2125");
    assertThat(dmnModel, notNullValue());
    assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
    DMNContext context = DMNFactory.newContext();
    context.set("person", "Bob");
    context.set("list of persons", Arrays.asList("Bob", "John"));
    DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
    DMNContext result = dmnResult.getContext();
    assertThat(result.get("person is Bob"), is("yes"));
    assertThat(result.get("persons complies with UT list"), is("yes"));
    assertThat(result.get("person on the list of persons"), is("yes"));
    assertThat(result.get("persons complies with hardcoded list"), is("yes"));
    assertThat(result.get("person is person"), is("yes"));
}
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) Test(org.junit.Test)

Example 69 with DMNModel

use of org.kie.dmn.api.core.DMNModel in project drools by kiegroup.

the class DMNRuntimeTest method testInvokeFunctionWrongDecisionName.

@Test
public void testInvokeFunctionWrongDecisionName() {
    DMNRuntime runtime = DMNRuntimeUtil.createRuntimeWithAdditionalResources("Caller.dmn", this.getClass(), "Calling.dmn");
    DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_b0a696d6-3d57-4e97-b5d4-b44a63909d67", "Caller");
    assertThat(dmnModel, notNullValue());
    DMNContext wrongContext = DMNFactory.newContext();
    wrongContext.set("My Name", "John Doe");
    wrongContext.set("My Number", 3);
    wrongContext.set("Call ns", "http://www.trisotech.com/definitions/_88156d21-3acc-43b6-8b81-385caf0bb6ca");
    wrongContext.set("Call name", "Calling");
    wrongContext.set("Invoke decision", "<unexistent decision>");
    DMNResult dmnResult = runtime.evaluateAll(dmnModel, wrongContext);
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(true));
    // total of: 2. x1 error in calling external decision, and x1 error in making final decision as it depends on the former.
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.getMessages().size(), is(2));
}
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) Test(org.junit.Test)

Example 70 with DMNModel

use of org.kie.dmn.api.core.DMNModel in project drools by kiegroup.

the class DMNRuntimeTest method testNull.

@Test
public void testNull() {
    DMNRuntime runtime = DMNRuntimeUtil.createRuntime("null_values.dmn", this.getClass());
    DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn", "Null values model");
    assertThat(dmnModel, notNullValue());
    assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
    DMNContext context = runtime.newContext();
    context.set("Null Input", null);
    DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
    DMNContext result = dmnResult.getContext();
    assertThat(result.get("Null value"), is("Input is null"));
    context = runtime.newContext();
    context.set("Null Input", "foo");
    dmnResult = runtime.evaluateAll(dmnModel, context);
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
    result = dmnResult.getContext();
    assertThat(result.get("Null value"), is("Input is not null"));
}
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) Test(org.junit.Test)

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