gitgabrio commented on code in PR #6257:
URL:
https://github.com/apache/incubator-kie-drools/pull/6257#discussion_r1959819231
##########
kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/ast/DMNConditionalEvaluator.java:
##########
@@ -31,44 +34,81 @@
import org.kie.dmn.core.impl.DMNRuntimeEventManagerUtils;
import org.kie.dmn.core.util.Msg;
import org.kie.dmn.core.util.MsgUtil;
-import org.kie.dmn.model.api.Conditional;
import org.kie.dmn.model.api.DMNElement;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class DMNConditionalEvaluator implements DMNExpressionEvaluator {
+ public enum EvaluatorType {
+ IF,
+ THEN,
+ ELSE
+ }
+
+ public static class EvaluatorIdentifier {
+ final String id;
+ final EvaluatorType type;
+
+ public EvaluatorIdentifier (String id, EvaluatorType type) {
+ this.id = id;
+ this.type = type;
+ }
+
+ @Override
+ public boolean equals(Object o) {
+ if (o == null || getClass() != o.getClass()) return false;
+ EvaluatorIdentifier that = (EvaluatorIdentifier) o;
+ return Objects.equals(id, that.id) && type == that.type;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(id, type);
+ }
+ }
+
private static final Logger logger =
LoggerFactory.getLogger(DMNConditionalEvaluator.class);
- private DMNExpressionEvaluator ifEvaluator;
- private DMNExpressionEvaluator thenEvaluator;
- private DMNExpressionEvaluator elseEvaluator;
- private DMNElement node;
- private String name;
- private final Map<DMNExpressionEvaluator, String> evaluatorIdMap = new
HashMap<>();
+ private final DMNExpressionEvaluator ifEvaluator;
+ private final DMNExpressionEvaluator thenEvaluator;
+ private final DMNExpressionEvaluator elseEvaluator;
+ private final DMNElement node;
+ private final String name;
+ private final Map<EvaluatorIdentifier, DMNExpressionEvaluator>
evaluatorIdMap;
Review Comment:
Hi @AthiraHari77
this seems unused: could u please remove if so ?
##########
kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/DMNEvaluatorCompiler.java:
##########
@@ -1035,37 +1048,39 @@ private java.util.List<UnaryTest>
textToUnaryTestList(DMNCompilerContext ctx, St
return ctx.getFeelHelper().evaluateUnaryTests(ctx, text, model,
element, errorMsg, msgParams);
}
- private DMNExpressionEvaluator compileConditional(DMNCompilerContext ctx,
DMNModelImpl model, DMNBaseNode node,
- String exprName,
Conditional expression) {
- DMNExpressionEvaluator ifEvaluator = compileExpression(ctx, model,
node, exprName + " [if]",
+ protected DMNExpressionEvaluator compileConditional(DMNCompilerContext
ctx, DMNModelImpl model, DMNBaseNode node,
+ String exprName, Conditional
expression) {
+ DMNExpressionEvaluator ifEvaluator = compileExpression(ctx, model,
node, exprName + " [" +
DMNConditionalEvaluator.EvaluatorType.IF.name().toLowerCase() + "]",
expression.getIf().getExpression());
- DMNExpressionEvaluator thenEvaluator = compileExpression(ctx, model,
node, exprName + " [then]",
+ DMNExpressionEvaluator thenEvaluator = compileExpression(ctx, model,
node, exprName + " [" +
DMNConditionalEvaluator.EvaluatorType.THEN.name().toLowerCase() + "]",
Review Comment:
This
`exprName + " [" + (enum).name().toLowerCase() + "]"`
is replicated, and could also be replaced with a String.format: could you
please create a specific method for that, to
1. avoid replication
2. have only one single point of modification, if needed ?
Thanks!
##########
kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/ast/DMNConditionalEvaluatorTest.java:
##########
@@ -172,4 +162,35 @@ void manageBooleanOrNullIfResultWithNull() {
assertThat(conditionalEvaluationEvent.getEvaluatorResultResult()).isEqualTo(elseEvaluationMock);
assertThat(conditionalEvaluationEvent.getExecutedId()).isEqualTo(ELSE_ELEMENT_ID);
}
+
+ @Test
+ void testMapEvaluatorIdentifiers() {
+ Map<DMNConditionalEvaluator.EvaluatorType,
DMNConditionalEvaluator.EvaluatorIdentifier> mapEvaluatorIdentifiers =
DMNConditionalEvaluator.mapEvaluatorIdentifiers(EVALUATOR_ID_MAP);
+
+
assertThat(mapEvaluatorIdentifiers.get(DMNConditionalEvaluator.EvaluatorType.IF)).isEqualTo(ifIdentifier);
+
assertThat(mapEvaluatorIdentifiers.get(DMNConditionalEvaluator.EvaluatorType.THEN)).isEqualTo(thenIdentifier);
+
assertThat(mapEvaluatorIdentifiers.get(DMNConditionalEvaluator.EvaluatorType.ELSE)).isEqualTo(elseIdentifier);
+ }
+
+ @Test
+ void testGetEvaluatorIdentifier() {
+ Map<DMNConditionalEvaluator.EvaluatorType,
DMNConditionalEvaluator.EvaluatorIdentifier> evaluatorIdentifierMap = new
HashMap<>();
+ evaluatorIdentifierMap.put(DMNConditionalEvaluator.EvaluatorType.IF,
ifIdentifier);
+ evaluatorIdentifierMap.put(DMNConditionalEvaluator.EvaluatorType.THEN,
thenIdentifier);
+ evaluatorIdentifierMap.put(DMNConditionalEvaluator.EvaluatorType.ELSE,
elseIdentifier);
+
+ DMNConditionalEvaluator.EvaluatorIdentifier resultIf =
DMNConditionalEvaluator.getEvaluatorIdentifier(evaluatorIdentifierMap,
DMNConditionalEvaluator.EvaluatorType.IF);
+ DMNConditionalEvaluator.EvaluatorIdentifier resultThen =
DMNConditionalEvaluator.getEvaluatorIdentifier(evaluatorIdentifierMap,
DMNConditionalEvaluator.EvaluatorType.THEN);
+ DMNConditionalEvaluator.EvaluatorIdentifier resultElse =
DMNConditionalEvaluator.getEvaluatorIdentifier(evaluatorIdentifierMap,
DMNConditionalEvaluator.EvaluatorType.ELSE);
+ assertThat(resultIf).isEqualTo(ifIdentifier);
+ assertThat(resultThen).isEqualTo(thenIdentifier);
+ assertThat(resultElse).isEqualTo(elseIdentifier);
+ }
+
+ @Test
+ void testMissingEvaluatorIdentifier() {
+ Map<DMNConditionalEvaluator.EvaluatorType,
DMNConditionalEvaluator.EvaluatorIdentifier> evaluatorIdentifierMap = new
HashMap<>();
+ String errorMessage = "Missing THEN evaluator in evaluatorIdMap";
+ assertThatRuntimeException().isThrownBy(() ->
DMNConditionalEvaluator.getEvaluatorIdentifier(evaluatorIdentifierMap,
DMNConditionalEvaluator.EvaluatorType.THEN)).withMessage(errorMessage);
Review Comment:
👍 ❤️
##########
kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/compiler/DMNEvaluatorCompilerTest.java:
##########
@@ -81,10 +106,97 @@ void getFEELDialectAdaptedFEELWrongExpressionLanguage() {
.hasMessage(expectedMessage);
}
+ @Test
+ void testGetEvaluatorIdentifierMap() {
+ String ifExprName = "testExpression [if]" ;
+ String thenExprName = "testExpression [then]";
+ String elseExprName = "testExpression [else]";
+ DMNConditionalEvaluator.EvaluatorIdentifier ifIdentifier = new
DMNConditionalEvaluator.EvaluatorIdentifier("_96D34F2E-3CC0-45A6-9455-2F960361A9CC",
DMNConditionalEvaluator.EvaluatorType.IF);
+ DMNConditionalEvaluator.EvaluatorIdentifier thenIdentifier = new
DMNConditionalEvaluator.EvaluatorIdentifier("_F9D2FA33-4604-4AAA-8FF1-5A4AC5055385",
DMNConditionalEvaluator.EvaluatorType.THEN);
+ DMNConditionalEvaluator.EvaluatorIdentifier elseIdentifier = new
DMNConditionalEvaluator.EvaluatorIdentifier("_7C843AB8-961C-4A95-83B3-2D1593DF297C",
DMNConditionalEvaluator.EvaluatorType.ELSE);
+
+ Resource resource =
ResourceFactory.newClassPathResource("valid_models/DMNv1_5/ConditionalEvent.dmn");
+ DMNRuntime dmnRuntime =
DMNRuntimeBuilder.fromDefaults().buildConfiguration()
+
.fromResources(Collections.singletonList(resource)).getOrElseThrow(RuntimeException::new);
+ assertThat(dmnRuntime).isNotNull();
+ String nameSpace =
"https://kie.org/dmn/_5B448C78-0DBF-4554-92A4-8C0247EB01FD";
+
+ final DMNModel dmnModel = dmnRuntime.getModel(nameSpace,
"DMN_00DF4B93-0243-4813-BA70-A1894AC723BE");
+ assertThat(dmnModel).isNotNull();
+ DMNModelInstrumentedBase retrieved = getNodeById(dmnModel,
"_096DC616-A4D5-449C-A350-491E42F3C8FB");
+ Conditional expr = (Conditional) retrieved;
+ DMNBaseNode dmnBaseNode = getNodeByName(dmnModel, "B");
+ DMNType numType = dmnBaseNode.getType();
+ DMN_COMPILER_CONTEXT.enterFrame();
Review Comment:
There are some issues here
1. DMN_COMPILER_CONTEXT is a static member; whatever modification is done to
it, it will be propagated to other test, potentially breaking them
2. this DMN_COMPILER_CONTEXT is not even the same used during runtime
instantiation, so there is no relationship with it
3. I'm not sure about the need of the "enterFrame()" invocation but, a)
there is not an exitFrame() b) it may have side effects c) I think is not
needed at all
##########
kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/impl/DMNRuntimeEventManagerUtilsTest.java:
##########
@@ -77,4 +86,20 @@ void fireAfterConditionalEvaluation() {
assertThat(evaluateConditionalEvent.getEvaluatorResultResult()).isEqualTo(evaluatorResult);
assertThat(evaluateConditionalEvent.getExecutedId()).isEqualTo(executedId);
}
+
+ @Test
+ void testConditionalEvent() {
Review Comment:
The scope of this class is to the the Events that are fired during execution
- see previous test.
Here, it does not matter the final result of the execution, but we have to
verify that expected events (in that case `AfterEvaluateConditionalEvent` )
have actually been fired, with expected values
##########
kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/ast/DMNConditionalEvaluatorTest.java:
##########
@@ -172,4 +162,35 @@ void manageBooleanOrNullIfResultWithNull() {
assertThat(conditionalEvaluationEvent.getEvaluatorResultResult()).isEqualTo(elseEvaluationMock);
assertThat(conditionalEvaluationEvent.getExecutedId()).isEqualTo(ELSE_ELEMENT_ID);
}
+
+ @Test
+ void testMapEvaluatorIdentifiers() {
+ Map<DMNConditionalEvaluator.EvaluatorType,
DMNConditionalEvaluator.EvaluatorIdentifier> mapEvaluatorIdentifiers =
DMNConditionalEvaluator.mapEvaluatorIdentifiers(EVALUATOR_ID_MAP);
+
+
assertThat(mapEvaluatorIdentifiers.get(DMNConditionalEvaluator.EvaluatorType.IF)).isEqualTo(ifIdentifier);
+
assertThat(mapEvaluatorIdentifiers.get(DMNConditionalEvaluator.EvaluatorType.THEN)).isEqualTo(thenIdentifier);
+
assertThat(mapEvaluatorIdentifiers.get(DMNConditionalEvaluator.EvaluatorType.ELSE)).isEqualTo(elseIdentifier);
+ }
+
+ @Test
+ void testGetEvaluatorIdentifier() {
+ Map<DMNConditionalEvaluator.EvaluatorType,
DMNConditionalEvaluator.EvaluatorIdentifier> evaluatorIdentifierMap = new
HashMap<>();
+ evaluatorIdentifierMap.put(DMNConditionalEvaluator.EvaluatorType.IF,
ifIdentifier);
+ evaluatorIdentifierMap.put(DMNConditionalEvaluator.EvaluatorType.THEN,
thenIdentifier);
+ evaluatorIdentifierMap.put(DMNConditionalEvaluator.EvaluatorType.ELSE,
elseIdentifier);
+
+ DMNConditionalEvaluator.EvaluatorIdentifier resultIf =
DMNConditionalEvaluator.getEvaluatorIdentifier(evaluatorIdentifierMap,
DMNConditionalEvaluator.EvaluatorType.IF);
Review Comment:
Lines from 182 to 187 could be compacted with a loop over
evaluatorIdentifierMap and a one-line assertion: could you please refactor it ?
##########
kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/compiler/DMNEvaluatorCompiler.java:
##########
@@ -1035,37 +1048,39 @@ private java.util.List<UnaryTest>
textToUnaryTestList(DMNCompilerContext ctx, St
return ctx.getFeelHelper().evaluateUnaryTests(ctx, text, model,
element, errorMsg, msgParams);
}
- private DMNExpressionEvaluator compileConditional(DMNCompilerContext ctx,
DMNModelImpl model, DMNBaseNode node,
- String exprName,
Conditional expression) {
- DMNExpressionEvaluator ifEvaluator = compileExpression(ctx, model,
node, exprName + " [if]",
+ protected DMNExpressionEvaluator compileConditional(DMNCompilerContext
ctx, DMNModelImpl model, DMNBaseNode node,
+ String exprName, Conditional
expression) {
+ DMNExpressionEvaluator ifEvaluator = compileExpression(ctx, model,
node, exprName + " [" +
DMNConditionalEvaluator.EvaluatorType.IF.name().toLowerCase() + "]",
Review Comment:
Please, do not use that
`(enum).name().toLowerCase()`
construct.
Whenever there is a String to be bound to an enum, it is better to define it
as specific property of the enum itself, so that the twos are independent.
See, as example,
[UnaryOperator](https://github.com/apache/incubator-kie-drools/blob/d27006e40f4e9f7f0c2203fdf1b0b16f8e930a9d/kie-dmn/kie-dmn-feel/src/main/java/org/kie/dmn/feel/lang/ast/UnaryTestNode.java#L41)
##########
kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/ast/DMNConditionalEvaluator.java:
##########
@@ -94,7 +134,9 @@ protected EvaluatorResult
manageBooleanOrNullIfResult(Boolean booleanResult, DMN
DMNExpressionEvaluator evaluatorToUse = booleanResult != null &&
booleanResult ? thenEvaluator : elseEvaluator;
EvaluatorResult toReturn = evaluatorToUse.evaluate(eventManager,
result);
- String executedId = evaluatorIdMap.get(evaluatorToUse);
+
Review Comment:
Could you please remove those empty lines ?
##########
kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/compiler/DMNEvaluatorCompilerTest.java:
##########
@@ -81,10 +106,97 @@ void getFEELDialectAdaptedFEELWrongExpressionLanguage() {
.hasMessage(expectedMessage);
}
+ @Test
+ void testGetEvaluatorIdentifierMap() {
+ String ifExprName = "testExpression [if]" ;
+ String thenExprName = "testExpression [then]";
+ String elseExprName = "testExpression [else]";
+ DMNConditionalEvaluator.EvaluatorIdentifier ifIdentifier = new
DMNConditionalEvaluator.EvaluatorIdentifier("_96D34F2E-3CC0-45A6-9455-2F960361A9CC",
DMNConditionalEvaluator.EvaluatorType.IF);
+ DMNConditionalEvaluator.EvaluatorIdentifier thenIdentifier = new
DMNConditionalEvaluator.EvaluatorIdentifier("_F9D2FA33-4604-4AAA-8FF1-5A4AC5055385",
DMNConditionalEvaluator.EvaluatorType.THEN);
+ DMNConditionalEvaluator.EvaluatorIdentifier elseIdentifier = new
DMNConditionalEvaluator.EvaluatorIdentifier("_7C843AB8-961C-4A95-83B3-2D1593DF297C",
DMNConditionalEvaluator.EvaluatorType.ELSE);
+
+ Resource resource =
ResourceFactory.newClassPathResource("valid_models/DMNv1_5/ConditionalEvent.dmn");
+ DMNRuntime dmnRuntime =
DMNRuntimeBuilder.fromDefaults().buildConfiguration()
+
.fromResources(Collections.singletonList(resource)).getOrElseThrow(RuntimeException::new);
+ assertThat(dmnRuntime).isNotNull();
+ String nameSpace =
"https://kie.org/dmn/_5B448C78-0DBF-4554-92A4-8C0247EB01FD";
+
+ final DMNModel dmnModel = dmnRuntime.getModel(nameSpace,
"DMN_00DF4B93-0243-4813-BA70-A1894AC723BE");
+ assertThat(dmnModel).isNotNull();
+ DMNModelInstrumentedBase retrieved = getNodeById(dmnModel,
"_096DC616-A4D5-449C-A350-491E42F3C8FB");
+ Conditional expr = (Conditional) retrieved;
+ DMNBaseNode dmnBaseNode = getNodeByName(dmnModel, "B");
+ DMNType numType = dmnBaseNode.getType();
+ DMN_COMPILER_CONTEXT.enterFrame();
+ DMN_COMPILER_CONTEXT.setVariable("num", numType);
+ DMNExpressionEvaluator ifEvaluator =
dmnEvaluatorCompiler.compileExpression(DMN_COMPILER_CONTEXT, (DMNModelImpl)
dmnModel, dmnBaseNode, ifExprName, expr.getIf().getExpression());
+ DMNExpressionEvaluator thenEvaluator =
dmnEvaluatorCompiler.compileExpression(DMN_COMPILER_CONTEXT, (DMNModelImpl)
dmnModel, dmnBaseNode, thenExprName, expr.getThen().getExpression());
+ DMNExpressionEvaluator elseEvaluator =
dmnEvaluatorCompiler.compileExpression(DMN_COMPILER_CONTEXT, (DMNModelImpl)
dmnModel, dmnBaseNode, elseExprName, expr.getElse().getExpression());
+
+ Map<DMNConditionalEvaluator.EvaluatorIdentifier,
DMNExpressionEvaluator> result = getEvaluatorIdentifierMap(expr, ifEvaluator,
thenEvaluator, elseEvaluator);
+ assertThat(result).hasSize(3);
+ assertThat(result.get(ifIdentifier)).isEqualTo(ifEvaluator);
+ assertThat(result.get(thenIdentifier)).isEqualTo(thenEvaluator);
+ assertThat(result.get(elseIdentifier)).isEqualTo(elseEvaluator);
+ }
+
+ @Test
+ void testGetEvaluatorIdentifier() {
+ DMNConditionalEvaluator.EvaluatorIdentifier ifIdentifier = new
DMNConditionalEvaluator.EvaluatorIdentifier(IF_ELEMENT_ID, IF);
+ DMNConditionalEvaluator.EvaluatorIdentifier thenIdentifier = new
DMNConditionalEvaluator.EvaluatorIdentifier(THEN_ELEMENT_ID, THEN);
+ DMNConditionalEvaluator.EvaluatorIdentifier elseIdentifier = new
DMNConditionalEvaluator.EvaluatorIdentifier(ELSE_ELEMENT_ID, ELSE);
+ DMNConditionalEvaluator.EvaluatorIdentifier ifEvaluatorIdentifier =
getEvaluatorIdentifier(IF_ELEMENT_ID, IF);
+ DMNConditionalEvaluator.EvaluatorIdentifier thenEvaluatorIdentifier =
getEvaluatorIdentifier(THEN_ELEMENT_ID, THEN);
+ DMNConditionalEvaluator.EvaluatorIdentifier elseEvaluatorIdentifier =
getEvaluatorIdentifier(ELSE_ELEMENT_ID, ELSE);
+
+ assertThat(ifEvaluatorIdentifier).isEqualTo(ifIdentifier);
+ assertThat(thenEvaluatorIdentifier).isEqualTo(thenIdentifier);
+ assertThat(elseEvaluatorIdentifier).isEqualTo(elseIdentifier);
+ }
+
+ @Test
+ void testCompileConditional() {
+ String exprName = "testExpression";
+ Resource resource =
ResourceFactory.newClassPathResource("valid_models/DMNv1_5/ConditionalEvent.dmn");
+ DMNRuntime dmnRuntime =
DMNRuntimeBuilder.fromDefaults().buildConfiguration()
+
.fromResources(Collections.singletonList(resource)).getOrElseThrow(RuntimeException::new);
+ assertThat(dmnRuntime).isNotNull();
+ String nameSpace =
"https://kie.org/dmn/_5B448C78-0DBF-4554-92A4-8C0247EB01FD";
+
+ final DMNModel dmnModel = dmnRuntime.getModel(nameSpace,
"DMN_00DF4B93-0243-4813-BA70-A1894AC723BE");
+ assertThat(dmnModel).isNotNull();
+ DMNModelInstrumentedBase retrieved = getNodeById(dmnModel,
"_096DC616-A4D5-449C-A350-491E42F3C8FB");
+ DMNBaseNode dmnBaseNode = getNodeByName(dmnModel, "B");
+ DMNType numType = dmnBaseNode.getType();
+ DMN_COMPILER_CONTEXT.enterFrame();
Review Comment:
See previous comment about usage of static property DMN_COMPILER_CONTEXT
##########
kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/compiler/DMNEvaluatorCompilerTest.java:
##########
@@ -81,10 +106,97 @@ void getFEELDialectAdaptedFEELWrongExpressionLanguage() {
.hasMessage(expectedMessage);
}
+ @Test
+ void testGetEvaluatorIdentifierMap() {
+ String ifExprName = "testExpression [if]" ;
+ String thenExprName = "testExpression [then]";
+ String elseExprName = "testExpression [else]";
+ DMNConditionalEvaluator.EvaluatorIdentifier ifIdentifier = new
DMNConditionalEvaluator.EvaluatorIdentifier("_96D34F2E-3CC0-45A6-9455-2F960361A9CC",
DMNConditionalEvaluator.EvaluatorType.IF);
+ DMNConditionalEvaluator.EvaluatorIdentifier thenIdentifier = new
DMNConditionalEvaluator.EvaluatorIdentifier("_F9D2FA33-4604-4AAA-8FF1-5A4AC5055385",
DMNConditionalEvaluator.EvaluatorType.THEN);
+ DMNConditionalEvaluator.EvaluatorIdentifier elseIdentifier = new
DMNConditionalEvaluator.EvaluatorIdentifier("_7C843AB8-961C-4A95-83B3-2D1593DF297C",
DMNConditionalEvaluator.EvaluatorType.ELSE);
+
+ Resource resource =
ResourceFactory.newClassPathResource("valid_models/DMNv1_5/ConditionalEvent.dmn");
+ DMNRuntime dmnRuntime =
DMNRuntimeBuilder.fromDefaults().buildConfiguration()
+
.fromResources(Collections.singletonList(resource)).getOrElseThrow(RuntimeException::new);
+ assertThat(dmnRuntime).isNotNull();
+ String nameSpace =
"https://kie.org/dmn/_5B448C78-0DBF-4554-92A4-8C0247EB01FD";
+
+ final DMNModel dmnModel = dmnRuntime.getModel(nameSpace,
"DMN_00DF4B93-0243-4813-BA70-A1894AC723BE");
+ assertThat(dmnModel).isNotNull();
+ DMNModelInstrumentedBase retrieved = getNodeById(dmnModel,
"_096DC616-A4D5-449C-A350-491E42F3C8FB");
Review Comment:
Please assert that retrieved is not null
##########
kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/compiler/DMNEvaluatorCompilerTest.java:
##########
@@ -81,10 +106,97 @@ void getFEELDialectAdaptedFEELWrongExpressionLanguage() {
.hasMessage(expectedMessage);
}
+ @Test
+ void testGetEvaluatorIdentifierMap() {
+ String ifExprName = "testExpression [if]" ;
+ String thenExprName = "testExpression [then]";
+ String elseExprName = "testExpression [else]";
+ DMNConditionalEvaluator.EvaluatorIdentifier ifIdentifier = new
DMNConditionalEvaluator.EvaluatorIdentifier("_96D34F2E-3CC0-45A6-9455-2F960361A9CC",
DMNConditionalEvaluator.EvaluatorType.IF);
+ DMNConditionalEvaluator.EvaluatorIdentifier thenIdentifier = new
DMNConditionalEvaluator.EvaluatorIdentifier("_F9D2FA33-4604-4AAA-8FF1-5A4AC5055385",
DMNConditionalEvaluator.EvaluatorType.THEN);
+ DMNConditionalEvaluator.EvaluatorIdentifier elseIdentifier = new
DMNConditionalEvaluator.EvaluatorIdentifier("_7C843AB8-961C-4A95-83B3-2D1593DF297C",
DMNConditionalEvaluator.EvaluatorType.ELSE);
+
+ Resource resource =
ResourceFactory.newClassPathResource("valid_models/DMNv1_5/ConditionalEvent.dmn");
+ DMNRuntime dmnRuntime =
DMNRuntimeBuilder.fromDefaults().buildConfiguration()
+
.fromResources(Collections.singletonList(resource)).getOrElseThrow(RuntimeException::new);
+ assertThat(dmnRuntime).isNotNull();
+ String nameSpace =
"https://kie.org/dmn/_5B448C78-0DBF-4554-92A4-8C0247EB01FD";
+
+ final DMNModel dmnModel = dmnRuntime.getModel(nameSpace,
"DMN_00DF4B93-0243-4813-BA70-A1894AC723BE");
+ assertThat(dmnModel).isNotNull();
+ DMNModelInstrumentedBase retrieved = getNodeById(dmnModel,
"_096DC616-A4D5-449C-A350-491E42F3C8FB");
+ Conditional expr = (Conditional) retrieved;
+ DMNBaseNode dmnBaseNode = getNodeByName(dmnModel, "B");
+ DMNType numType = dmnBaseNode.getType();
+ DMN_COMPILER_CONTEXT.enterFrame();
+ DMN_COMPILER_CONTEXT.setVariable("num", numType);
+ DMNExpressionEvaluator ifEvaluator =
dmnEvaluatorCompiler.compileExpression(DMN_COMPILER_CONTEXT, (DMNModelImpl)
dmnModel, dmnBaseNode, ifExprName, expr.getIf().getExpression());
+ DMNExpressionEvaluator thenEvaluator =
dmnEvaluatorCompiler.compileExpression(DMN_COMPILER_CONTEXT, (DMNModelImpl)
dmnModel, dmnBaseNode, thenExprName, expr.getThen().getExpression());
+ DMNExpressionEvaluator elseEvaluator =
dmnEvaluatorCompiler.compileExpression(DMN_COMPILER_CONTEXT, (DMNModelImpl)
dmnModel, dmnBaseNode, elseExprName, expr.getElse().getExpression());
+
+ Map<DMNConditionalEvaluator.EvaluatorIdentifier,
DMNExpressionEvaluator> result = getEvaluatorIdentifierMap(expr, ifEvaluator,
thenEvaluator, elseEvaluator);
+ assertThat(result).hasSize(3);
+ assertThat(result.get(ifIdentifier)).isEqualTo(ifEvaluator);
+ assertThat(result.get(thenIdentifier)).isEqualTo(thenEvaluator);
+ assertThat(result.get(elseIdentifier)).isEqualTo(elseEvaluator);
+ }
+
+ @Test
+ void testGetEvaluatorIdentifier() {
+ DMNConditionalEvaluator.EvaluatorIdentifier ifIdentifier = new
DMNConditionalEvaluator.EvaluatorIdentifier(IF_ELEMENT_ID, IF);
+ DMNConditionalEvaluator.EvaluatorIdentifier thenIdentifier = new
DMNConditionalEvaluator.EvaluatorIdentifier(THEN_ELEMENT_ID, THEN);
+ DMNConditionalEvaluator.EvaluatorIdentifier elseIdentifier = new
DMNConditionalEvaluator.EvaluatorIdentifier(ELSE_ELEMENT_ID, ELSE);
+ DMNConditionalEvaluator.EvaluatorIdentifier ifEvaluatorIdentifier =
getEvaluatorIdentifier(IF_ELEMENT_ID, IF);
+ DMNConditionalEvaluator.EvaluatorIdentifier thenEvaluatorIdentifier =
getEvaluatorIdentifier(THEN_ELEMENT_ID, THEN);
+ DMNConditionalEvaluator.EvaluatorIdentifier elseEvaluatorIdentifier =
getEvaluatorIdentifier(ELSE_ELEMENT_ID, ELSE);
+
+ assertThat(ifEvaluatorIdentifier).isEqualTo(ifIdentifier);
+ assertThat(thenEvaluatorIdentifier).isEqualTo(thenIdentifier);
+ assertThat(elseEvaluatorIdentifier).isEqualTo(elseIdentifier);
+ }
+
+ @Test
+ void testCompileConditional() {
+ String exprName = "testExpression";
+ Resource resource =
ResourceFactory.newClassPathResource("valid_models/DMNv1_5/ConditionalEvent.dmn");
+ DMNRuntime dmnRuntime =
DMNRuntimeBuilder.fromDefaults().buildConfiguration()
+
.fromResources(Collections.singletonList(resource)).getOrElseThrow(RuntimeException::new);
+ assertThat(dmnRuntime).isNotNull();
+ String nameSpace =
"https://kie.org/dmn/_5B448C78-0DBF-4554-92A4-8C0247EB01FD";
+
+ final DMNModel dmnModel = dmnRuntime.getModel(nameSpace,
"DMN_00DF4B93-0243-4813-BA70-A1894AC723BE");
+ assertThat(dmnModel).isNotNull();
+ DMNModelInstrumentedBase retrieved = getNodeById(dmnModel,
"_096DC616-A4D5-449C-A350-491E42F3C8FB");
Review Comment:
Please assert that retrieved is not null
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]