package com.test; import com.fasterxml.jackson.annotation.JsonValue; import org.camunda.bpm.dmn.engine.DmnDecision; import org.camunda.bpm.dmn.engine.DmnDecisionTableResult; import org.camunda.bpm.dmn.engine.DmnEngine; import org.camunda.bpm.dmn.engine.DmnEngineConfiguration; import org.camunda.bpm.engine.variable.VariableMap; import org.camunda.bpm.engine.variable.impl.VariableMapImpl; import org.camunda.spin.Spin; import org.camunda.spin.json.SpinJsonNode; import org.junit.jupiter.api.BeforeAll; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import java.io.InputStream; import java.util.List; import java.util.Map; import static java.util.Arrays.asList; import static org.hamcrest.CoreMatchers.is; import static org.hamcrest.MatcherAssert.assertThat; public class DmnJsonValueTest { protected static DmnDecisionTable CURRENT_DMN_DECISION_TABLE; protected DmnEngine dmnEngine; protected DmnDecision decision; @BeforeEach void setup() { dmnEngine = DmnEngineConfiguration .createDefaultDmnEngineConfiguration() .buildEngine(); // Parse decision ClassLoader contextClassLoader = Thread.currentThread().getContextClassLoader(); InputStream inputStream = contextClassLoader.getResourceAsStream(CURRENT_DMN_DECISION_TABLE.getFileName()); decision = dmnEngine.parseDecision(CURRENT_DMN_DECISION_TABLE.getKey(), inputStream); } @BeforeAll public static void initialization() { CURRENT_DMN_DECISION_TABLE = DmnDecisionTable.TEST_DMN; } @Test void testJson() { String caseField = "{\"Data\": {\"appealType\": \"refusalOfHumanRights\"}}"; VariableMap inputVariables = new VariableMapImpl(); inputVariables.putValue("eventId", "test"); inputVariables.putValue("postEventState", "submitted"); final SpinJsonNode json = Spin.JSON(caseField); inputVariables.putValue("CaseField", json); DmnDecisionTableResult dmnDecisionTableResult = evaluateDmnTable(inputVariables); final List> expectation = asList( Map.of( "taskId", "Done" )); assertThat(dmnDecisionTableResult.getResultList(), is(expectation)); } public DmnDecisionTableResult evaluateDmnTable(Map variables) { return dmnEngine.evaluateDecisionTable(decision, variables); } public enum DmnDecisionTable { TEST_DMN("dmn-json", "test-dmn.dmn"); @JsonValue private final String key; private final String fileName; DmnDecisionTable(String key, String fileName) { this.key = key; this.fileName = fileName; } public String getKey() { return key; } public String getFileName() { return fileName; } } }