use of org.kie.dmn.api.core.FEELPropertyAccessible in project drools by kiegroup.
the class DMN13specificTest method testDMNv1_3_ch11.
@Test
public void testDMNv1_3_ch11() {
testName = "testDMNv1_3_ch11";
final DMNRuntime runtime = createRuntimeWithAdditionalResources("Chapter 11 Example.dmn", this.getClass(), "Financial.dmn");
final DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_9d01a0c4-f529-4ad8-ad8e-ec5fb5d96ad4", "Chapter 11 Example");
assertThat(dmnModel, notNullValue());
assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
final DMNContext context = DMNFactory.newContext();
context.set("Applicant data", mapOf(entry("Age", new BigDecimal(51)), // typo is present in DMNv1.3
entry("MartitalStatus", "M"), entry("EmploymentStatus", "EMPLOYED"), entry("ExistingCustomer", false), entry("Monthly", mapOf(entry("Income", new BigDecimal(100_000)), entry("Repayments", new BigDecimal(2_500)), entry("Expenses", new BigDecimal(10_000))))));
context.set("Bureau data", mapOf(entry("Bankrupt", false), entry("CreditScore", new BigDecimal(600))));
context.set("Requested product", mapOf(entry("ProductType", "STANDARD LOAN"), entry("Rate", new BigDecimal(0.08)), entry("Term", new BigDecimal(36)), entry("Amount", new BigDecimal(100_000))));
context.set("Supporting documents", null);
final DMNResult dmnResult = evaluateModel(runtime, dmnModel, context);
LOG.debug("{}", dmnResult);
assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
final DMNContext result = dmnResult.getContext();
assertThat(result.get("Strategy"), is("THROUGH"));
assertThat(result.get("Routing"), is("ACCEPT"));
if (isTypeSafe()) {
FEELPropertyAccessible outputSet = ((DMNContextFPAImpl) dmnResult.getContext()).getFpa();
Map<String, Object> allProperties = outputSet.allFEELProperties();
assertThat(allProperties.get("Strategy"), is("THROUGH"));
assertThat(allProperties.get("Routing"), is("ACCEPT"));
}
}
use of org.kie.dmn.api.core.FEELPropertyAccessible in project drools by kiegroup.
the class DMN13specificTest method testDMNv1_3_simple.
@Test
public void testDMNv1_3_simple() {
final DMNRuntime runtime = createRuntime("simple.dmn", this.getClass());
final DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_9d01a0c4-f529-4ad8-ad8e-ec5fb5d96ad4", "Chapter 11 Example");
assertThat(dmnModel, notNullValue());
assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
final DMNContext context = DMNFactory.newContext();
context.set("name", "John");
final DMNResult dmnResult = evaluateModel(runtime, dmnModel, context);
LOG.debug("{}", dmnResult);
assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
final DMNContext result = dmnResult.getContext();
assertThat(result.get("salutation"), is("Hello, John"));
if (isTypeSafe()) {
FEELPropertyAccessible outputSet = ((DMNContextFPAImpl) dmnResult.getContext()).getFpa();
Map<String, Object> allProperties = outputSet.allFEELProperties();
assertThat(allProperties.get("salutation"), is("Hello, John"));
}
}
use of org.kie.dmn.api.core.FEELPropertyAccessible in project drools by kiegroup.
the class DMN13specificTest method testBKMencapsulatedlogictyperef.
@Test
public void testBKMencapsulatedlogictyperef() {
final DMNRuntime runtime = createRuntime("bkmELTyperef.dmn", this.getClass());
final DMNModel dmnModel = runtime.getModel("http://www.trisotech.com/definitions/_a49df6fc-c936-467a-9762-9aa3c9a93c06", "Drawing 1");
assertThat(dmnModel, notNullValue());
assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
final DMNContext context = DMNFactory.newContext();
final DMNResult dmnResult = evaluateModel(runtime, dmnModel, context);
LOG.debug("{}", dmnResult);
assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(false));
final DMNContext result = dmnResult.getContext();
assertThat(result.get("Decision1"), is(new BigDecimal("3")));
if (isTypeSafe()) {
FEELPropertyAccessible outputSet = ((DMNContextFPAImpl) dmnResult.getContext()).getFpa();
Map<String, Object> allProperties = outputSet.allFEELProperties();
assertThat(allProperties.get("Decision1"), is(new BigDecimal("3")));
}
}
use of org.kie.dmn.api.core.FEELPropertyAccessible in project drools by kiegroup.
the class VariantTest method evaluateByNameTypeSafe.
private DMNResult evaluateByNameTypeSafe(DMNRuntime runtime, DMNModel dmnModel, DMNContext context, String... decisionNames) {
Map<String, Object> inputMap = context.getAll();
FEELPropertyAccessible outputSet;
try {
outputSet = createOutputSetInstance(dmnModel);
outputSet.fromMap(inputMap);
DMNContext contextFpa = new DMNContextFPAImpl(outputSet);
DMNResult result = runtime.evaluateByName(dmnModel, contextFpa, decisionNames);
return convertContext(result, createOutputSetInstance(dmnModel));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
use of org.kie.dmn.api.core.FEELPropertyAccessible in project drools by kiegroup.
the class VariantTest method evaluateDecisionServiceTypeSafe.
private DMNResult evaluateDecisionServiceTypeSafe(DMNRuntime runtime, DMNModel dmnModel, DMNContext context, String decisionServiceName) {
Map<String, Object> inputMap = context.getAll();
FEELPropertyAccessible outputSet;
try {
outputSet = createOutputSetInstance(dmnModel);
outputSet.fromMap(inputMap);
DMNContext contextFpa = new DMNContextFPAImpl(outputSet);
DMNResult result = runtime.evaluateDecisionService(dmnModel, contextFpa, decisionServiceName);
return convertContext(result, createOutputSetInstance(dmnModel));
} catch (Exception e) {
throw new RuntimeException(e);
}
}
Aggregations