To easily test DMN decisions in a JUnit test, the DMN engine provides aJUnit Rule. The DmnEngineRule creates a new default DMN engine. The DMN engine can be used in test cases to parse and evaluate decisions.
public class DecisionTest {
@Rule
public DmnEngineRule dmnEngineRule = new DmnEngineRule();
@Test
public void test() {
DmnEngine dmnEngine = dmnEngineRule.getDmnEngine();
// load DMN file
InputStream inputStream = ...;
//create and add variables
VariableMap variables = Variables.createVariables();
DmnDecision decision = dmnEngine.parseDecision("decision", inputStream);
DmnDecisionResult result = dmnEngine.evaluateDecision(decision, variables);
// assert the result
// ...
}
}
If you want to create a DMN engine with a custom configuration, you can passthis to the DMN engine rule.
public class DecisionTest {
@Rule
public DmnEngineRule dmnEngineRule = new DmnEngineRule(createCustomConfiguration());
public DmnEngineConfiguration createCustomConfiguration() {
// create and return custom configuration
return ...;
}
@Test
public void test() {
DmnEngine customDmnEngine = dmnEngineRule.getDmnEngine();
// ...
}
}
The DmnDecisionResult implements the interfaceList<DmnDecisionResultEntries>
. Whereas the DmnDecisionResultEntries implements the interface Map<String, Object>
.This allows you to use common List
or Map
asserts.
原文: https://docs.camunda.org/manual/7.9/user-guide/dmn-engine/testing/