Search in sources :

Example 6 with DMNModel

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

the class DMNRuntimeTest method testEx_4_3simplified.

@Test
public void testEx_4_3simplified() {
    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();
    context.set("number", 123.123456d);
    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("Formatted Monthly Payment"), is("€123.12"));
}
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 7 with DMNModel

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

the class DMNRuntimeTest method testInvalidFunction.

@Test
public void testInvalidFunction() {
    final DMNRuntime runtime = DMNRuntimeUtil.createRuntimeWithAdditionalResources("InvalidFunction.dmn", this.getClass());
    final DMNModel model = runtime.getModel("http://www.trisotech.com/definitions/_84453b71-5d23-479f-9481-5196d92bacae", "0003-iteration-augmented");
    assertThat(model, notNullValue());
    final DMNContext context = DMNFactory.newContext();
    context.set("Loans", new HashMap<>());
    final DMNResult result = runtime.evaluateAll(model, context);
    final List<DMNDecisionResult> decisionResults = result.getDecisionResults();
    FEELStringMarshaller.INSTANCE.marshall(Arrays.asList(decisionResults.get(0).getResult(), decisionResults.get(1).getResult()));
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) DMNContext(org.kie.dmn.api.core.DMNContext) DMNDecisionResult(org.kie.dmn.api.core.DMNDecisionResult) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) Test(org.junit.Test)

Example 8 with DMNModel

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

the class DMNRuntimeTest method testYearsAndMonthsDuration.

@Test
public void testYearsAndMonthsDuration() {
    DMNRuntime runtime = DMNRuntimeUtil.createRuntime("yearMonthDuration.dmn", this.getClass());
    DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/dmn/definitions/_6eda1490-21ca-441e-8a26-ab3ca800e43c", "Drawing 1");
    assertThat(dmnModel, notNullValue());
    assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
    BuiltInType feelType = (BuiltInType) BuiltInType.determineTypeFromName("yearMonthDuration");
    Period period = (Period) feelType.fromString("P2Y1M");
    DMNContext context = runtime.newContext();
    context.set("iDuration", period);
    DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
    DMNContext result = dmnResult.getContext();
    assertThat(result.get("How long"), is("Longer than a year"));
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) DMNContext(org.kie.dmn.api.core.DMNContext) Period(java.time.Period) BuiltInType(org.kie.dmn.feel.lang.types.BuiltInType) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNModel(org.kie.dmn.api.core.DMNModel) Test(org.junit.Test)

Example 9 with DMNModel

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

the class DMNRuntimeTest method testVerifyExtendedKieFEELFunction_now.

@Test
public void testVerifyExtendedKieFEELFunction_now() {
    // DROOLS-2322
    DMNRuntime runtime = DMNRuntimeUtil.createRuntime("just_now.dmn", this.getClass());
    DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_56fd6445-ff6a-4c28-8206-71fce7f80436", "just now");
    assertThat(dmnModel, notNullValue());
    assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
    DMNContext emptyContext = DMNFactory.newContext();
    DMNResult dmnResult = runtime.evaluateAll(dmnModel, emptyContext);
    assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
    assertThat(dmnResult.getDecisionResultByName("a decision just now").getResult(), notNullValue());
}
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 10 with DMNModel

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

the class DMNRuntimeTest method testFunctionDefAndInvocation.

@Test
public void testFunctionDefAndInvocation() {
    DMNRuntime runtime = DMNRuntimeUtil.createRuntime("FunctionDefinition.dmn", this.getClass());
    DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/dmn/definitions/_0de36357-fec0-4b4e-b7f1-382d381e06e9", "Dessin 1");
    assertThat(dmnModel, notNullValue());
    assertThat(dmnModel.getMessages().toString(), dmnModel.hasErrors(), is(false));
    DMNContext context = DMNFactory.newContext();
    context.set("a", 10);
    context.set("b", 5);
    DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    assertThat(dmnResult.hasErrors(), is(false));
    assertThat((Map<String, Object>) dmnResult.getContext().get("Math"), hasEntry("Sum", BigDecimal.valueOf(15)));
}
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

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