use of org.kie.dmn.api.core.DMNContext in project drools by kiegroup.
the class DMNDecisionTableRuntimeTest method testSimpleDecisionTableMultipleOutputWrongOutputType.
@Test
public void testSimpleDecisionTableMultipleOutputWrongOutputType() {
final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("0004-simpletable-P-multiple-outputs-wrong-output.dmn", this.getClass());
final DMNModel dmnModel = runtime.getModel("https://github.com/kiegroup/kie-dmn", "0004-simpletable-P-multiple-outputs-wrong-output");
assertThat(dmnModel, notNullValue());
final DMNContext context = DMNFactory.newContext();
context.set("Age", BigDecimal.valueOf(18));
context.set("RiskCategory", "Medium");
context.set("isAffordable", true);
final DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
assertThat(dmnResult.hasErrors(), is(true));
assertThat(dmnResult.getMessages().stream().filter(message -> message.getFeelEvent().getSourceException() instanceof NullPointerException).count(), is(0L));
}
use of org.kie.dmn.api.core.DMNContext in project drools by kiegroup.
the class DMNDecisionTableRuntimeTest method testNullRelation.
@Test
public void testNullRelation() {
DMNRuntime runtime = DMNRuntimeUtil.createRuntime("nullrelation.dmn", getClass());
DMNModel model = runtime.getModel("http://www.trisotech.com/definitions/_946a2145-89ae-4197-88b4-40e6f88c8101", "Null in relations");
assertThat(model, notNullValue());
assertThat(DMNRuntimeUtil.formatMessages(model.getMessages()), model.hasErrors(), is(false));
DMNContext context = DMNFactory.newContext();
context.set("Value", "a3");
DMNResult result = runtime.evaluateByName(model, context, "Mapping");
assertThat(DMNRuntimeUtil.formatMessages(result.getMessages()), result.hasErrors(), is(false));
}
use of org.kie.dmn.api.core.DMNContext in project drools by kiegroup.
the class DMNDecisionTableRuntimeTest method testDTInContext.
@Test
public void testDTInContext() {
DMNRuntime runtime = DMNRuntimeUtil.createRuntime("DT_in_context.dmn", this.getClass());
DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/dmn/definitions/_4acdcb25-b298-435e-abd5-efd00ed686a5", "Drawing 1");
assertThat(dmnModel, notNullValue());
DMNContext context = DMNFactory.newContext();
DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
assertThat(dmnResult.getDecisionResults().size(), is(1));
assertThat(dmnResult.getDecisionResultByName("D1").getResult(), is(instanceOf(Map.class)));
DMNContext result = dmnResult.getContext();
assertThat(((Map) result.get("D1")).get("Text color"), is("red"));
}
use of org.kie.dmn.api.core.DMNContext in project drools by kiegroup.
the class DMNDecisionTableRuntimeTest method testDecisionTableOutputDMNTypeCollectionWithLOV_NOtypecheck.
@Test
public void testDecisionTableOutputDMNTypeCollectionWithLOV_NOtypecheck() {
// DROOLS-2359
// do NOT use the DMNRuntimeUtil as that enables typeSafe check override for runtime.
KieServices ks = KieServices.Factory.get();
final KieContainer kieContainer = KieHelper.getKieContainer(ks.newReleaseId("org.kie", "dmn-test-" + UUID.randomUUID(), "1.0"), ks.getResources().newClassPathResource("DecisionTableOutputDMNTypeCollectionWithLOV.dmn", this.getClass()));
DMNRuntime runtime = kieContainer.newKieSession().getKieRuntime(DMNRuntime.class);
DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/dmn/definitions/_ae5d2033-c6d0-411f-a394-da33a70e5638", "List of Words in DT");
assertThat(dmnModel, notNullValue());
assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
DMNContext context = DMNFactory.newContext();
context.set("selector", "asd");
DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
DMNContext result = dmnResult.getContext();
assertThat(result.get("a decision"), is(Arrays.asList("abc", "a")));
}
use of org.kie.dmn.api.core.DMNContext in project drools by kiegroup.
the class DMNDecisionTableRuntimeTest method testDTUsingEqualsUnaryTestWithVariable1.
@Test
public void testDTUsingEqualsUnaryTestWithVariable1() {
DMNRuntime runtime = DMNRuntimeUtil.createRuntime("DT_using_variables.dmn", this.getClass());
DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_ed1ec15b-40aa-424d-b1d0-4936df80b135", "DT Using variables");
assertThat(dmnModel, notNullValue());
assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
Map<String, Object> complex = new HashMap<>();
complex.put("aBoolean", true);
complex.put("aNumber", 10);
complex.put("aString", "bar");
DMNContext context = DMNFactory.newContext();
context.set("Complex", complex);
context.set("Another boolean", true);
context.set("Another String", "bar");
context.set("Another number", 10);
DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
DMNContext result = dmnResult.getContext();
assertThat(result.get("Compare Boolean"), is("Same boolean"));
assertThat(result.get("Compare Number"), is("Equals"));
assertThat(result.get("Compare String"), is("Same String"));
}
Aggregations