Search in sources :

Example 1 with DMNResultImplFactory

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));
}
Also used : DMNResultImpl(org.kie.dmn.core.impl.DMNResultImpl) DMNResult(org.kie.dmn.api.core.DMNResult) DMNRuntimeImpl(org.kie.dmn.core.impl.DMNRuntimeImpl) DMNModelInstrumentedBase(org.kie.dmn.model.api.DMNModelInstrumentedBase) ArrayList(java.util.ArrayList) DMNContext(org.kie.dmn.api.core.DMNContext) Severity(org.kie.dmn.api.core.DMNMessage.Severity) DMNRuntime(org.kie.dmn.api.core.DMNRuntime) DMNMessageType(org.kie.dmn.api.core.DMNMessageType) DMNResultImplFactory(org.kie.dmn.core.impl.DMNResultImplFactory) DMNMessage(org.kie.dmn.api.core.DMNMessage) FEELEvent(org.kie.dmn.api.feel.runtime.events.FEELEvent) DMNModel(org.kie.dmn.api.core.DMNModel) Test(org.junit.Test)

Aggregations

ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 DMNContext (org.kie.dmn.api.core.DMNContext)1 DMNMessage (org.kie.dmn.api.core.DMNMessage)1 Severity (org.kie.dmn.api.core.DMNMessage.Severity)1 DMNMessageType (org.kie.dmn.api.core.DMNMessageType)1 DMNModel (org.kie.dmn.api.core.DMNModel)1 DMNResult (org.kie.dmn.api.core.DMNResult)1 DMNRuntime (org.kie.dmn.api.core.DMNRuntime)1 FEELEvent (org.kie.dmn.api.feel.runtime.events.FEELEvent)1 DMNResultImpl (org.kie.dmn.core.impl.DMNResultImpl)1 DMNResultImplFactory (org.kie.dmn.core.impl.DMNResultImplFactory)1 DMNRuntimeImpl (org.kie.dmn.core.impl.DMNRuntimeImpl)1 DMNModelInstrumentedBase (org.kie.dmn.model.api.DMNModelInstrumentedBase)1