1

I am working on Camunda DMN file. Here I want to test the DMN Decision Table. So I prepared java code to test it.

Here my doubt is, can we create POJO class(getter and setter) using DMN xml during runtime?

We don't have to included any hared coded value like variable name/ variable datatype. Those variables/datatype should pick from xml and include in our code.

Nvr
  • 21
  • 3

1 Answers1

1

A DMN evaluation, in testing done as shown here: https://docs.camunda.org/manual/7.17/user-guide/dmn-engine/testing/ will return you a DmnDecisionResult. This is a Java Object, you can use to access the results.

Example:

package org.camunda.demo;

import org.camunda.bpm.dmn.engine.DmnDecisionTableResult;
import org.camunda.bpm.engine.test.Deployment;
import org.camunda.bpm.engine.test.ProcessEngineRule;
import org.junit.Rule;
import org.junit.Test;

import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.entry;
import static org.camunda.bpm.engine.test.assertions.ProcessEngineTests.withVariables;
import static org.camunda.bpm.engine.test.assertions.bpmn.BpmnAwareTests.decisionService;

public class DMNUnitTest {

    @Rule
    public ProcessEngineRule rule = new ProcessEngineRule();

    @Test
    @Deployment(resources = {"Buyer.dmn"})
    public void testTweetApprovalAlwaysApprovedContent() {
        DmnDecisionTableResult results = decisionService().evaluateDecisionTableByKey("Decision_Buyer", withVariables(
                "productGroup", "Food",
                "productDepartment","Fruit",
                "productClass", "",
                "halal",false));
        assertThat(results).hasSize(1);
        assertThat(results.getSingleResult()).containsOnly(entry("candidateGroups", "Fruit"));
    }


}
rob2universe
  • 7,059
  • 39
  • 54
  • @rob2univerese, thanks for your valuable answer. But here I don't want hardcoded variable name. The code should work for any DMN file, no need hardcoded variable name, that is my question. – Nvr Aug 29 '22 at 06:01
  • Hi, your question above is "Here my doubt is, can we create POJO class using DMN xml during runtime?". Do you maybe want to update your question to reflect in more details what you want to achieve and to add this question? – rob2universe Aug 29 '22 at 06:09
  • Hi, I have edited my question. please have a look. – Nvr Aug 29 '22 at 07:00
  • This is not very verbose. I am not sure how you want to test if your decision table does the right thing from a business perspective without referring to specific data. Anyway, if you need those flexible, you can read the XML or use the Model API to inspect the data ids used in the columns. – rob2universe Aug 29 '22 at 08:54