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);
}
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);
}
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));
}
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"));
}
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));
}
Aggregations