Search in sources :

Example 26 with DMNRuntime

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

the class DMNRuntimeTypeCheckTest method testAskTypeCheckWithGlobalEnvVariable.

@Test
public void testAskTypeCheckWithGlobalEnvVariable() {
    System.setProperty(RuntimeTypeCheckOption.PROPERTY_NAME, "true");
    // 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);
    assertPerformTypeCheck(runtime);
    System.clearProperty(RuntimeTypeCheckOption.PROPERTY_NAME);
}
Also used : DMNRuntime(org.kie.dmn.api.core.DMNRuntime) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 27 with DMNRuntime

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

the class DMNRuntimeTypeCheckTest method testDefaultNoTypeCheckButOverrideRuntime.

@Test
public void testDefaultNoTypeCheckButOverrideRuntime() {
    // 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);
    ((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) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 28 with DMNRuntime

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

the class DMNRuntimeTypeCheckTest method assertNoTypeCheck.

private void assertNoTypeCheck(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(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.getMessages(DMNMessage.Severity.ERROR).stream().allMatch(m -> m.getSourceId().equals(dmnModel.getDecisionByName("hundred minus number").getId())), is(true));
    DMNDecisionResult textPlusNumberDR = dmnResult.getDecisionResultByName("text plus number");
    assertThat(textPlusNumberDR.getEvaluationStatus(), is(DecisionEvaluationStatus.SUCCEEDED));
    assertThat(textPlusNumberDR.getResult(), is("The input number is: ciao"));
    DMNDecisionResult hundredMinusNumber = dmnResult.getDecisionResultByName("hundred minus number");
    assertThat(hundredMinusNumber.getEvaluationStatus(), is(DecisionEvaluationStatus.FAILED));
}
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 29 with DMNRuntime

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

the class DMNUpdateTest method testReplace.

@Test
public void testReplace() {
    final KieServices ks = KieServices.Factory.get();
    final KieContainer kieContainer = KieHelper.getKieContainer(ks.newReleaseId("org.kie", "dmn-test", "1.0.0"), ks.getResources().newClassPathResource("0001-input-data-string.dmn", this.getClass()));
    DMNRuntime runtime = kieContainer.newKieSession().getKieRuntime(DMNRuntime.class);
    Assert.assertNotNull(runtime);
    assertThat(runtime.getModels(), hasSize(1));
    DMNContext dmnContext = runtime.newContext();
    dmnContext.set("Full Name", "John Doe");
    DMNResult evaluateAll = runtime.evaluateAll(runtime.getModels().get(0), dmnContext);
    assertThat(evaluateAll.getDecisionResultByName("Greeting Message").getResult(), is("Hello John Doe"));
    ReleaseId v101 = ks.newReleaseId("org.kie", "dmn-test", "1.0.1");
    Resource newClassPathResource = ks.getResources().newClassPathResource("0001-input-data-string-itIT.dmn", this.getClass());
    newClassPathResource.setTargetPath("0001-input-data-string.dmn");
    KieHelper.createAndDeployJar(ks, v101, newClassPathResource);
    Results updateResults = kieContainer.updateToVersion(v101);
    assertThat(updateResults.hasMessages(Level.ERROR), is(false));
    runtime = kieContainer.newKieSession().getKieRuntime(DMNRuntime.class);
    Assert.assertNotNull(runtime);
    assertThat(runtime.getModels(), hasSize(1));
    DMNContext dmnContext2 = runtime.newContext();
    dmnContext2.set("Full Name", "John Doe");
    DMNResult evaluateAll2 = runtime.evaluateAll(runtime.getModels().get(0), dmnContext2);
    assertThat(evaluateAll2.getDecisionResultByName("Greeting Message").getResult(), is("Salve John Doe"));
}
Also used : DMNResult(org.kie.dmn.api.core.DMNResult) Results(org.kie.api.builder.Results) DMNContext(org.kie.dmn.api.core.DMNContext) Resource(org.kie.api.io.Resource) KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) KieContainer(org.kie.api.runtime.KieContainer) Test(org.junit.Test)

Example 30 with DMNRuntime

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

the class DMNUpdateTest method testFromClonedKiePackage.

@Test
public void testFromClonedKiePackage() {
    final KieServices ks = KieServices.Factory.get();
    ReleaseId v100 = ks.newReleaseId("org.kie", "dmn-test", "1.0.0");
    KieHelper.createAndDeployJar(ks, v100, ks.getResources().newClassPathResource("0001-input-data-string.dmn", this.getClass()));
    KieContainer kieContainer = ks.newKieContainer(v100);
    DMNRuntime runtime = kieContainer.newKieSession().getKieRuntime(DMNRuntime.class);
    Assert.assertNotNull(runtime);
    assertThat(runtime.getModels(), hasSize(1));
    kieContainer.dispose();
    kieContainer = ks.newKieContainer(v100);
    runtime = kieContainer.newKieSession().getKieRuntime(DMNRuntime.class);
    Assert.assertNotNull(runtime);
    assertThat(runtime.getModels(), hasSize(1));
}
Also used : KieServices(org.kie.api.KieServices) ReleaseId(org.kie.api.builder.ReleaseId) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) KieContainer(org.kie.api.runtime.KieContainer) 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