Search in sources :

Example 26 with DMNResult

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

the class DMNRuntimeTest method testDROOLS2147_message.

@Test
public void testDROOLS2147_message() {
    // DROOLS-2147 truncate message length
    DMNRuntime runtime = DMNRuntimeUtil.createRuntime("Ex_4_3simplified.dmn", this.getClass());
    DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_5c5a9c72-627e-4666-ae85-31356fed3658", "Ex_4_3simplified");
    assertThat(dmnModel, notNullValue());
    assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
    DMNContext context = DMNFactory.newContext();
    StringBuilder sb = new StringBuilder("abcdefghijklmnopqrstuvwxyz");
    for (int i = 0; i < 100; i++) {
        sb.append("abcdefghijklmnopqrstuvwxyz");
    }
    context.set("number", sb.toString());
    DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    System.out.println(dmnResult);
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(true));
    assertThat(dmnResult.getMessages().stream().filter(m -> m.getMessageType() == DMNMessageType.ERROR_EVAL_NODE).anyMatch(m -> m.getMessage().contains("... [string clipped after 50 chars, total length is")), is(true));
}
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) 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 27 with DMNResult

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

the class DMNRuntimeTest method testDROOLS2200.

@Test
public void testDROOLS2200() {
    // DROOLS-2200
    DMNRuntime runtime = DMNRuntimeUtil.createRuntime("will_be_null_if_negative.dmn", this.getClass());
    DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_c5889555-7ae5-4a67-a872-3a9492caf6e7", "will be null if negative");
    assertThat(dmnModel, notNullValue());
    assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
    DMNContext context = DMNFactory.newContext();
    context.set("a number", -1);
    DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
    DMNContext resultContext = dmnResult.getContext();
    assertThat(((Map) resultContext.get("will be null if negative")).get("s1"), nullValue());
    assertThat(((Map) resultContext.get("will be null if negative")).get("s2"), is("negative"));
}
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 28 with DMNResult

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

the class DMNRuntimeTest method testListContainmentDT.

@Test
public void testListContainmentDT() {
    // DROOLS-2416
    DMNRuntime runtime = DMNRuntimeUtil.createRuntime("list_containment_DT.dmn", this.getClass());
    DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_6ab2bd6d-adaa-45c4-a141-a84382a201eb", "list containment DT");
    assertThat(dmnModel, notNullValue());
    assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
    DMNContext context = DMNFactory.newContext();
    context.set("Passenger", prototype(entry("name", "Osama bin Laden")));
    DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    System.out.println(dmnResult);
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
    DMNContext result = dmnResult.getContext();
    assertThat(result.get("Boarding Status"), is("Denied"));
}
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 29 with DMNResult

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

the class DMNRuntimeTest method testNotificationsApproved2.

@Test
public void testNotificationsApproved2() {
    DMNRuntime runtime = DMNRuntimeUtil.createRuntime("NotificationsTest2.dmn", this.getClass());
    DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn", "building-structure-rules");
    assertThat(dmnModel, notNullValue());
    DMNContext context = DMNFactory.newContext();
    context.set("existingActivityApplicability", true);
    context.set("Distance", new BigDecimal(9999));
    context.set("willIncreaseTraffic", true);
    DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    DMNContext result = dmnResult.getContext();
    assertThat(result.get("Notification Status"), is("Notification to Province Approved"));
    assertThat(result.get("Permit Status"), is("Building Activity Province Permit Required"));
}
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) BigDecimal(java.math.BigDecimal) Test(org.junit.Test)

Example 30 with DMNResult

use of org.kie.dmn.api.core.DMNResult 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)

Aggregations

DMNResult (org.kie.dmn.api.core.DMNResult)139 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)135 DMNContext (org.kie.dmn.api.core.DMNContext)134 DMNModel (org.kie.dmn.api.core.DMNModel)130 Test (org.junit.Test)127 HashMap (java.util.HashMap)24 BigDecimal (java.math.BigDecimal)23 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)23 KieServices (org.kie.api.KieServices)22 KieContainer (org.kie.api.runtime.KieContainer)22 ArrayList (java.util.ArrayList)19 List (java.util.List)17 Map (java.util.Map)17 DMNDecisionResult (org.kie.dmn.api.core.DMNDecisionResult)16 DMNMessage (org.kie.dmn.api.core.DMNMessage)13 CoreMatchers.is (org.hamcrest.CoreMatchers.is)10 CoreMatchers.notNullValue (org.hamcrest.CoreMatchers.notNullValue)10 AfterEvaluateDecisionTableEvent (org.kie.dmn.api.core.event.AfterEvaluateDecisionTableEvent)10 DMNRuntimeEventListener (org.kie.dmn.api.core.event.DMNRuntimeEventListener)10 DecisionNodeImpl (org.kie.dmn.core.ast.DecisionNodeImpl)10