use of org.kie.dmn.core.impl.DMNResultImplFactory in project drools by kiegroup.
the class DMNDecisionTableRuntimeTest method testQMarkAndNullShouldNotThrowNPEs.
@Test
public void testQMarkAndNullShouldNotThrowNPEs() {
final DMNRuntime runtime = DMNRuntimeUtil.createRuntime("questionmarkunarytest/qmarkMatches.dmn", this.getClass());
final DMNModel dmnModel = runtime.getModel("https://kiegroup.org/dmn/_D1CF8332-8443-41C8-B214-D282B82C7632", "qmarkMatches");
assertThat(dmnModel, notNullValue());
assertThat(DMNRuntimeUtil.formatMessages(dmnModel.getMessages()), dmnModel.hasErrors(), is(false));
List<NullPointerException> feelNPEs = new ArrayList<>();
DMNRuntimeImpl runtimeImpl = (DMNRuntimeImpl) runtime;
runtimeImpl.setDMNResultImplFactory(new DMNResultImplFactory() {
@Override
public DMNResultImpl newDMNResultImpl(DMNModel model) {
return new DMNResultImpl(model) {
@Override
public DMNMessage addMessage(Severity severity, String message, DMNMessageType messageType, DMNModelInstrumentedBase source, FEELEvent feelEvent) {
if (feelEvent.getSourceException() instanceof NullPointerException) {
feelNPEs.add((NullPointerException) feelEvent.getSourceException());
}
return super.addMessage(severity, message, messageType, source, feelEvent);
}
};
}
});
final DMNContext context = DMNFactory.newContext();
context.set("MyInput", null);
final DMNResult dmnResult = runtime.evaluateAll(dmnModel, context);
LOG.debug("{}", dmnResult);
assertThat(DMNRuntimeUtil.formatMessages(dmnResult.getMessages()), dmnResult.hasErrors(), is(true));
assertThat("while it's okay to have error-ed on evaluation of FEEL, there should not be any sort of NPEs when reporting the human friendly message", feelNPEs.isEmpty(), is(true));
}
Aggregations