Features for DmnEngineRule

Hello community,

I would like to contribute some code to the DmnEngineRule and I would like to know if there is interest of doing so. Following features:

  • declarative approach for loading dmn resources
  • declarative approach for “deploying”/“activating” specific dmn rule
  • convenience methods for “evaluateDecision” and “evaluateDecisionTable”

Example unit test:

@DmnResource(resources = "/rule.dmn")
public class RptNttMatchClassicTest {

  @Rule
  public DmnEngineRule dmnEngineRule = new DmnEngineRule();

  @Test
  @DmnDecisionKey(name = "rule-id")
  public void rptTTMatchClassicNormaliseProductsTest() {
    // given
    Map<String, Object> variables = new HashMap<String, Object>();
    ...
    // when
    DmnDecisionResult dmnDecisionResult = dmnEngineRule.evaluateDecision(variables);
    // then
    ...
  }
}

My idea is highly inspired by the BPMN unit test support!

This is a really nice idea!
I think i’ll bring this up at the DMN question corner next week. might be a good point to start a discussion.

Hi @Niall,

as soon as you/your collegues agree with this feature idea, I could contribute code for it on github.com.

Hi @rfelgent,

good idea to invest into the DMN testing.

My thoughts on this:
@DmnResource() is similar to @Deployment(resources = "myDmnFile.dmn")

I think it is worth to improve is the assertions of the DmnDecisionResult.

I usually write

    DmnDecisionTableResult decisionTableResult = decisionService().evaluateDecisionTableByKey("tweetApproval", variables);
    assertThat(decisionTableResult.getFirstResult()).containsEntry("approved", true);

It wouild be nice if I could have an abstraction on decisionTableResult.getFirstResult() without knowledge about the internal structure of the DmnDecisionTableResult or DmnDecisionResult.

Maybe something that matches the hitpolicy or the result mapping like

assertThat(result).singleResult("approved").isEqualTo(true)

Thank you, Ingo

1 Like

Hi @rfelgent,

don’t wait, just start with a proposal and prepare a pull request.

Thank you, Ingo

Hi Ingo,

I created a PR https://github.com/camunda/camunda-bpm-platform/pull/1080/.

FYI: there is similar functionality implemented via DmnEngineTestRule. Are you aware of it?!

Hi @rfelgent,

thank you for the heads up! I wasn’t aware of this hint: Testing Decisions with the DMN Engine | docs.camunda.org. The last two sentebces sound interesting:

The DmnDecisionResult implements the interface List<DmnDecisionResultEntries> . Whereas the DmnDecisionResultEntries implements the interface Map<String, Object> . This allows you to use common List or Map asserts.

I will give it a try.

Thank you, Ingo