Search in sources :

Example 21 with DMNRuntime

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

the class DMNRuntimeTypeCheckTest method testAskTypeCheckInKModuleButOverrideRuntime.

@Test
public void testAskTypeCheckInKModuleButOverrideRuntime() {
    DMNRuntime runtime = getRuntimeWithTypeCheckOption("true", ks.getResources().newClassPathResource("forTypeCheckTest.dmn", this.getClass()));
    ((DMNRuntimeImpl) runtime).setOption(new RuntimeTypeCheckOption(false));
    assertPerformTypeCheck(runtime);
}
Also used : DMNRuntimeImpl(org.kie.dmn.core.impl.DMNRuntimeImpl) RuntimeTypeCheckOption(org.kie.dmn.core.compiler.RuntimeTypeCheckOption) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) Test(org.junit.Test)

Example 22 with DMNRuntime

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

the class DMNRuntimeTypeCheckTest method assertPerformTypeCheck.

private void assertPerformTypeCheck(DMNRuntime runtime) {
    DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_6d8af9a2-dcf4-4b9e-8d90-6ccddc8c1bbd", "forTypeCheckTest");
    assertThat(dmnModel, notNullValue());
    assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
    DMNContext context = DMNFactory.newContext();
    context.set("a number", "ciao");
    DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
    assertThat("Should throw several errors, not only for 1 specific Decision: " + DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.getMessages(DMNMessage.Severity.ERROR).stream().allMatch(m -> m.getSourceId().equals(dmnModel.getDecisionByName("hundred minus number").getId())), is(false));
    DMNDecisionResult textPlusNumberDR = dmnResult.getDecisionResultByName("text plus number");
    // dependency failed type check
    assertThat(textPlusNumberDR.getEvaluationStatus(), is(DecisionEvaluationStatus.SKIPPED));
    DMNDecisionResult hundredMinusNumber = dmnResult.getDecisionResultByName("hundred minus number");
    // dependency failed type check
    assertThat(textPlusNumberDR.getEvaluationStatus(), is(DecisionEvaluationStatus.SKIPPED));
}
Also used : CoreMatchers.is(org.hamcrest.CoreMatchers.is) KieFileSystem(org.kie.api.builder.KieFileSystem) DMNFactory(org.kie.dmn.core.api.DMNFactory) KieBuilder(org.kie.api.builder.KieBuilder) DMNMessage(org.kie.dmn.api.core.DMNMessage) DMNResult(org.kie.dmn.api.core.DMNResult) Results(org.kie.api.builder.Results) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test) UUID(java.util.UUID) DMNRuntimeImpl(org.kie.dmn.core.impl.DMNRuntimeImpl) DMNRuntimeUtil(org.kie.dmn.core.util.DMNRuntimeUtil) CoreMatchers.notNullValue(org.hamcrest.CoreMatchers.notNullValue) RuntimeTypeCheckOption(org.kie.dmn.core.compiler.RuntimeTypeCheckOption) Assert.assertThat(org.junit.Assert.assertThat) Resource(org.kie.api.io.Resource) DMNModel(org.kie.dmn.api.core.DMNModel) KieModuleModel(org.kie.api.builder.model.KieModuleModel) DecisionEvaluationStatus(org.kie.dmn.api.core.DMNDecisionResult.DecisionEvaluationStatus) KieServices(org.kie.api.KieServices) DMNContext(org.kie.dmn.api.core.DMNContext) KieHelper(org.kie.dmn.core.util.KieHelper) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNDecisionResult(org.kie.dmn.api.core.DMNDecisionResult) DMNResult(org.kie.dmn.api.core.DMNResult) DMNContext(org.kie.dmn.api.core.DMNContext) DMNDecisionResult(org.kie.dmn.api.core.DMNDecisionResult) DMNModel(org.kie.dmn.api.core.DMNModel)

Example 23 with DMNRuntime

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

the class DMNRuntimeTypeCheckTest method testExplicitDisableTypeCheckInKModule.

@Test
public void testExplicitDisableTypeCheckInKModule() {
    DMNRuntime runtime = getRuntimeWithTypeCheckOption("false", ks.getResources().newClassPathResource("forTypeCheckTest.dmn", this.getClass()));
    assertNoTypeCheck(runtime);
}
Also used : DMNRuntime(org.kie.dmn.api.core.DMNRuntime) Test(org.junit.Test)

Example 24 with DMNRuntime

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

the class DMNRuntimeTypeCheckTest method testDefaultNoTypeCheck.

@Test
public void testDefaultNoTypeCheck() {
    // do NOT use the DMNRuntimeUtil as that enables typeSafe check override for runtime.
    final KieContainer kieContainer = KieHelper.getKieContainer(ks.newReleaseId("org.kie", "dmn-test-" + UUID.randomUUID(), "1.0"), ks.getResources().newClassPathResource("forTypeCheckTest.dmn", this.getClass()));
    DMNRuntime runtime = kieContainer.newKieSession().getKieRuntime(DMNRuntime.class);
    assertNoTypeCheck(runtime);
}
Also used : DMNRuntime(org.kie.dmn.api.core.DMNRuntime) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 25 with DMNRuntime

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

the class DMNRuntimeTypeCheckTest method testExplicitDisableTypeCheckInKModuleButOverrideRuntime.

@Test
public void testExplicitDisableTypeCheckInKModuleButOverrideRuntime() {
    DMNRuntime runtime = getRuntimeWithTypeCheckOption("false", ks.getResources().newClassPathResource("forTypeCheckTest.dmn", this.getClass()));
    ((DMNRuntimeImpl) runtime).setOption(new RuntimeTypeCheckOption(true));
    assertPerformTypeCheck(runtime);
}
Also used : DMNRuntimeImpl(org.kie.dmn.core.impl.DMNRuntimeImpl) RuntimeTypeCheckOption(org.kie.dmn.core.compiler.RuntimeTypeCheckOption) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) Test(org.junit.Test)

Aggregations

DMNRuntime (org.kie.dmn.api.core.DMNRuntime)178 Test (org.junit.Test)164 DMNModel (org.kie.dmn.api.core.DMNModel)152 DMNContext (org.kie.dmn.api.core.DMNContext)132 DMNResult (org.kie.dmn.api.core.DMNResult)128 KieContainer (org.kie.api.runtime.KieContainer)34 KieServices (org.kie.api.KieServices)30 BigDecimal (java.math.BigDecimal)26 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)26 HashMap (java.util.HashMap)25 List (java.util.List)22 ArrayList (java.util.ArrayList)21 Map (java.util.Map)21 DMNMessage (org.kie.dmn.api.core.DMNMessage)16 CoreMatchers.is (org.hamcrest.CoreMatchers.is)13 CoreMatchers.notNullValue (org.hamcrest.CoreMatchers.notNullValue)13 Results (org.kie.api.builder.Results)13 AfterEvaluateDecisionTableEvent (org.kie.dmn.api.core.event.AfterEvaluateDecisionTableEvent)13 DMNRuntimeEventListener (org.kie.dmn.api.core.event.DMNRuntimeEventListener)13 DecisionNodeImpl (org.kie.dmn.core.ast.DecisionNodeImpl)13