Create POJO Class using XML during run time

Viewed 34

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.

1 Answers

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"));
    }


}
Related