From 3659d207d2223a4a5b045421bcd7b26ed1e9eaca Mon Sep 17 00:00:00 2001 From: athira Date: Sun, 1 Dec 2024 23:22:43 +0530 Subject: [PATCH 1/7] [incubator-kie-issues#1605] Adding required model --- kie-dmn/kie-dmn-core/pom.xml | 32 +++++++++++ .../org/kie/dmn/core/impl/DMNRuntimeImpl.java | 25 +++++---- .../internal/utils/DMNRuntimeBuilderTest.java | 29 ++++++++++ .../DMNv1_5/Invalid_decisions_model.dmn | 53 +++++++++++++++++++ 4 files changed, 130 insertions(+), 9 deletions(-) create mode 100644 kie-dmn/kie-dmn-test-resources/src/test/resources/invalid_models/DMNv1_5/Invalid_decisions_model.dmn diff --git a/kie-dmn/kie-dmn-core/pom.xml b/kie-dmn/kie-dmn-core/pom.xml index ab4f01aae28..8166f3db3f9 100644 --- a/kie-dmn/kie-dmn-core/pom.xml +++ b/kie-dmn/kie-dmn-core/pom.xml @@ -37,6 +37,7 @@ org.kie.dmn.core + 3.6.1 @@ -276,5 +277,36 @@ true + + + + org.apache.maven.plugins + maven-dependency-plugin + ${dependency-plugin.version} + + + unpack + generate-test-resources + + unpack + + + + + org.kie + kie-dmn-test-resources + ${project.version} + jar + tests + true + ${project.build.directory}/test-classes/org/kie/dmn/core + **/*.dmn + + + + + + + diff --git a/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/impl/DMNRuntimeImpl.java b/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/impl/DMNRuntimeImpl.java index 203c44f32af..bfcbd527855 100644 --- a/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/impl/DMNRuntimeImpl.java +++ b/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/impl/DMNRuntimeImpl.java @@ -30,6 +30,7 @@ import javax.xml.namespace.QName; import org.drools.kiesession.rulebase.InternalKnowledgeBase; +import org.kie.api.builder.Message; import org.kie.dmn.api.core.DMNContext; import org.kie.dmn.api.core.DMNDecisionResult; import org.kie.dmn.api.core.DMNMessage; @@ -111,16 +112,22 @@ public DMNResult evaluateAll(DMNModel model, DMNContext context) { Objects.requireNonNull(model, () -> MsgUtil.createMessage(Msg.PARAM_CANNOT_BE_NULL, "model")); Objects.requireNonNull(context, () -> MsgUtil.createMessage(Msg.PARAM_CANNOT_BE_NULL, "context")); boolean performRuntimeTypeCheck = performRuntimeTypeCheck(model); - DMNResultImpl result = createResult( model, context ); - DMNRuntimeEventManagerUtils.fireBeforeEvaluateAll( eventManager, model, result ); - // the engine should evaluate all Decisions belonging to the "local" model namespace, not imported decision explicitly. - Set decisions = model.getDecisions().stream().filter(d -> d.getModelNamespace().equals(model.getNamespace())).collect(Collectors.toSet()); - for( DecisionNode decision : decisions ) { - evaluateDecision(context, result, decision, performRuntimeTypeCheck); + if (model.hasErrors()) { + List messages = model.getMessages(DMNMessage.Severity.ERROR); + String errorMessage = messages.stream().map(Message::getText).collect(Collectors.joining(", ")); + throw new IllegalStateException(errorMessage); + } else { + DMNResultImpl result = createResult( model, context ); + DMNRuntimeEventManagerUtils.fireBeforeEvaluateAll( eventManager, model, result ); + // the engine should evaluate all Decisions belonging to the "local" model namespace, not imported decision explicitly. + Set decisions = model.getDecisions().stream().filter(d -> d.getModelNamespace().equals(model.getNamespace())).collect(Collectors.toSet()); + for( DecisionNode decision : decisions ) { + evaluateDecision(context, result, decision, performRuntimeTypeCheck); + } + DMNRuntimeEventManagerUtils.fireAfterEvaluateAll( eventManager, model, result ); + return result; + } } - DMNRuntimeEventManagerUtils.fireAfterEvaluateAll( eventManager, model, result ); - return result; - } @Override @Deprecated diff --git a/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/internal/utils/DMNRuntimeBuilderTest.java b/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/internal/utils/DMNRuntimeBuilderTest.java index f10cec99ede..c9edfb93d4e 100644 --- a/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/internal/utils/DMNRuntimeBuilderTest.java +++ b/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/internal/utils/DMNRuntimeBuilderTest.java @@ -18,13 +18,22 @@ */ package org.kie.dmn.core.internal.utils; +import java.io.File; import java.util.Collections; +import org.drools.util.FileUtils; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.kie.api.io.Resource; +import org.kie.dmn.api.core.DMNContext; +import org.kie.dmn.api.core.DMNModel; +import org.kie.dmn.api.core.DMNRuntime; +import org.kie.dmn.core.api.DMNFactory; import org.kie.dmn.core.impl.DMNRuntimeImpl; +import org.kie.internal.io.ResourceFactory; import static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.assertThatThrownBy; class DMNRuntimeBuilderTest { @@ -43,4 +52,24 @@ void buildFromConfiguration() { .fromResources(Collections.emptyList()).getOrElseThrow(RuntimeException::new); assertThat(retrieved).isNotNull(); } + + @Test + void fromDefaultsMultipleDecisionWithoutInputDataReference() { + File modelFile = FileUtils.getFile("Invalid_decisions_model.dmn"); + assertThat(modelFile).isNotNull().exists(); + Resource modelResource = ResourceFactory.newFileResource(modelFile); + DMNRuntime dmnRuntime = DMNRuntimeBuilder.fromDefaults().buildConfiguration() + .fromResources(Collections.singletonList(modelResource)).getOrElseThrow(RuntimeException::new); + assertThat(dmnRuntime).isNotNull(); + String nameSpace = "https://kie.org/dmn/_BDC29BCF-B5DC-4AD7-8A5F-43DC08780F97"; + + final DMNModel dmnModel = dmnRuntime.getModel( + nameSpace, + "DMN_1A4BD262-7672-4887-9F25-986EE5277D16"); + assertThat(dmnModel).isNotNull(); + DMNContext context = DMNFactory.newContext(); + context.set( "Person Age", 24 ); + assertThatThrownBy(() -> dmnRuntime.evaluateAll(dmnModel, context)) + .isInstanceOf(IllegalStateException.class); + } } \ No newline at end of file diff --git a/kie-dmn/kie-dmn-test-resources/src/test/resources/invalid_models/DMNv1_5/Invalid_decisions_model.dmn b/kie-dmn/kie-dmn-test-resources/src/test/resources/invalid_models/DMNv1_5/Invalid_decisions_model.dmn new file mode 100644 index 00000000000..e73f3f0425a --- /dev/null +++ b/kie-dmn/kie-dmn-test-resources/src/test/resources/invalid_models/DMNv1_5/Invalid_decisions_model.dmn @@ -0,0 +1,53 @@ + + + + + + + + + Can Drive + + Person Age >= 18 + + + Person Age >= 18 + + + + + + + + + Person Age>=18 + + + + + + + + 190 + + + 190 + + + + + + + + + + + + + + + + + + + From f2c914436434ac295cd112582118a4832ff2b07f Mon Sep 17 00:00:00 2001 From: athira Date: Tue, 10 Dec 2024 14:55:24 +0530 Subject: [PATCH 2/7] [incubator-kie-issues#1619] Code changes --- .../org/kie/dmn/core/impl/DMNRuntimeImpl.java | 41 ++++++++++++------- .../internal/utils/DMNRuntimeBuilderTest.java | 41 +++++++++++++++++++ 2 files changed, 67 insertions(+), 15 deletions(-) diff --git a/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/impl/DMNRuntimeImpl.java b/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/impl/DMNRuntimeImpl.java index bfcbd527855..bc93aba270e 100644 --- a/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/impl/DMNRuntimeImpl.java +++ b/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/impl/DMNRuntimeImpl.java @@ -18,6 +18,7 @@ */ package org.kie.dmn.core.impl; +import java.util.Arrays; import java.util.Collection; import java.util.List; import java.util.Map; @@ -112,22 +113,19 @@ public DMNResult evaluateAll(DMNModel model, DMNContext context) { Objects.requireNonNull(model, () -> MsgUtil.createMessage(Msg.PARAM_CANNOT_BE_NULL, "model")); Objects.requireNonNull(context, () -> MsgUtil.createMessage(Msg.PARAM_CANNOT_BE_NULL, "context")); boolean performRuntimeTypeCheck = performRuntimeTypeCheck(model); - if (model.hasErrors()) { - List messages = model.getMessages(DMNMessage.Severity.ERROR); - String errorMessage = messages.stream().map(Message::getText).collect(Collectors.joining(", ")); - throw new IllegalStateException(errorMessage); - } else { - DMNResultImpl result = createResult( model, context ); - DMNRuntimeEventManagerUtils.fireBeforeEvaluateAll( eventManager, model, result ); - // the engine should evaluate all Decisions belonging to the "local" model namespace, not imported decision explicitly. - Set decisions = model.getDecisions().stream().filter(d -> d.getModelNamespace().equals(model.getNamespace())).collect(Collectors.toSet()); - for( DecisionNode decision : decisions ) { - evaluateDecision(context, result, decision, performRuntimeTypeCheck); - } - DMNRuntimeEventManagerUtils.fireAfterEvaluateAll( eventManager, model, result ); - return result; - } + if (model.hasErrors()){ + handleModelErrors(model); + } + DMNResultImpl result = createResult( model, context ); + DMNRuntimeEventManagerUtils.fireBeforeEvaluateAll( eventManager, model, result ); + // the engine should evaluate all Decisions belonging to the "local" model namespace, not imported decision explicitly. + Set decisions = model.getDecisions().stream().filter(d -> d.getModelNamespace().equals(model.getNamespace())).collect(Collectors.toSet()); + for( DecisionNode decision : decisions ) { + evaluateDecision(context, result, decision, performRuntimeTypeCheck); } + DMNRuntimeEventManagerUtils.fireAfterEvaluateAll( eventManager, model, result ); + return result; + } @Override @Deprecated @@ -155,6 +153,13 @@ public DMNResult evaluateByName( DMNModel model, DMNContext context, String... d if (decisionNames.length == 0) { throw new IllegalArgumentException(MsgUtil.createMessage(Msg.PARAM_CANNOT_BE_EMPTY, "decisionNames")); } + List errorMessages = model.getMessages(DMNMessage.Severity.ERROR); + errorMessages.stream().filter(message -> Arrays.stream(decisionNames).anyMatch(decision -> message.getText().contains(decision))) + .findAny().ifPresent(message -> { + throw new IllegalStateException(message.getText()); + }); + + System.out.println(errorMessages); final DMNResultImpl result = createResult( model, context ); for (String name : decisionNames) { evaluateByNameInternal( model, context, result, name ); @@ -761,6 +766,12 @@ private static String getDependencyIdentifier(DMNNode callerNode, DMNNode node) } + private static void handleModelErrors(DMNModel model) { + List messages = model.getMessages(DMNMessage.Severity.ERROR); + String errorMessage = messages.stream().map(Message::getText).collect(Collectors.joining(", ")); + throw new IllegalStateException(errorMessage); + } + public boolean performRuntimeTypeCheck(DMNModel model) { Objects.requireNonNull(model, () -> MsgUtil.createMessage(Msg.PARAM_CANNOT_BE_NULL, "model")); return overrideRuntimeTypeCheck || ((DMNModelImpl) model).isRuntimeTypeCheck(); diff --git a/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/internal/utils/DMNRuntimeBuilderTest.java b/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/internal/utils/DMNRuntimeBuilderTest.java index c9edfb93d4e..feaa00a3c8f 100644 --- a/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/internal/utils/DMNRuntimeBuilderTest.java +++ b/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/internal/utils/DMNRuntimeBuilderTest.java @@ -27,6 +27,7 @@ import org.kie.api.io.Resource; import org.kie.dmn.api.core.DMNContext; import org.kie.dmn.api.core.DMNModel; +import org.kie.dmn.api.core.DMNResult; import org.kie.dmn.api.core.DMNRuntime; import org.kie.dmn.core.api.DMNFactory; import org.kie.dmn.core.impl.DMNRuntimeImpl; @@ -72,4 +73,44 @@ void fromDefaultsMultipleDecisionWithoutInputDataReference() { assertThatThrownBy(() -> dmnRuntime.evaluateAll(dmnModel, context)) .isInstanceOf(IllegalStateException.class); } + + @Test + void multipleDecisionWithoutInputDataReferencesEvaluateWrongDecision() { + File modelFile = FileUtils.getFile("Invalid_decisions_model.dmn"); + assertThat(modelFile).isNotNull().exists(); + Resource modelResource = ResourceFactory.newFileResource(modelFile); + DMNRuntime dmnRuntime = DMNRuntimeBuilder.fromDefaults().buildConfiguration() + .fromResources(Collections.singletonList(modelResource)).getOrElseThrow(RuntimeException::new); + assertThat(dmnRuntime).isNotNull(); + String nameSpace = "https://kie.org/dmn/_BDC29BCF-B5DC-4AD7-8A5F-43DC08780F97"; + + final DMNModel dmnModel = dmnRuntime.getModel( + nameSpace, + "DMN_1A4BD262-7672-4887-9F25-986EE5277D16"); + assertThat(dmnModel).isNotNull(); + DMNContext context = DMNFactory.newContext(); + context.set( "Person Age", 24 ); + assertThatThrownBy(() -> dmnRuntime.evaluateByName(dmnModel, context, "Can Drive?")) + .isInstanceOf(IllegalStateException.class); + } + + @Test + void multipleDecisionWithoutInputDataReferencesValuateCorrectDecision() { + File modelFile = FileUtils.getFile("Invalid_decisions_model.dmn"); + assertThat(modelFile).isNotNull().exists(); + Resource modelResource = ResourceFactory.newFileResource(modelFile); + DMNRuntime dmnRuntime = DMNRuntimeBuilder.fromDefaults().buildConfiguration() + .fromResources(Collections.singletonList(modelResource)).getOrElseThrow(RuntimeException::new); + assertThat(dmnRuntime).isNotNull(); + String nameSpace = "https://kie.org/dmn/_BDC29BCF-B5DC-4AD7-8A5F-43DC08780F97"; + + final DMNModel dmnModel = dmnRuntime.getModel( + nameSpace, + "DMN_1A4BD262-7672-4887-9F25-986EE5277D16"); + assertThat(dmnModel).isNotNull(); + DMNContext context = DMNFactory.newContext(); + context.set( "Person Age", 24 ); + DMNResult dmnResult = dmnRuntime.evaluateByName(dmnModel, context, "Can Vote?"); + assertThat(dmnResult).isNotNull(); + } } \ No newline at end of file From e713f039884ca5f341af6f8bdcb0af5a36f6b4e3 Mon Sep 17 00:00:00 2001 From: athira Date: Thu, 12 Dec 2024 13:34:18 +0530 Subject: [PATCH 3/7] [incubator-kie-issues#1619] Code changes --- .../org/kie/dmn/core/impl/DMNRuntimeImpl.java | 5 ++ .../internal/utils/DMNRuntimeBuilderTest.java | 88 +++++++++++++++++-- .../invalid_models/DMNv1_5/InvalidFeel.dmn | 36 ++++++++ 3 files changed, 122 insertions(+), 7 deletions(-) create mode 100644 kie-dmn/kie-dmn-test-resources/src/test/resources/invalid_models/DMNv1_5/InvalidFeel.dmn diff --git a/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/impl/DMNRuntimeImpl.java b/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/impl/DMNRuntimeImpl.java index bc93aba270e..29d69fda0be 100644 --- a/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/impl/DMNRuntimeImpl.java +++ b/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/impl/DMNRuntimeImpl.java @@ -196,6 +196,11 @@ public DMNResult evaluateById( DMNModel model, DMNContext context, String... dec if (decisionIds.length == 0) { throw new IllegalArgumentException(MsgUtil.createMessage(Msg.PARAM_CANNOT_BE_EMPTY, "decisionIds")); } + List errorMessages = model.getMessages(DMNMessage.Severity.ERROR); + errorMessages.stream().filter(message -> Arrays.stream(decisionIds).anyMatch(decision -> message.getText().contains(decision))) + .findAny().ifPresent(message -> { + throw new IllegalStateException(message.getText()); + }); final DMNResultImpl result = createResult( model, context ); for ( String id : decisionIds ) { evaluateByIdInternal( model, context, result, id ); diff --git a/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/internal/utils/DMNRuntimeBuilderTest.java b/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/internal/utils/DMNRuntimeBuilderTest.java index feaa00a3c8f..c8c8467ba23 100644 --- a/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/internal/utils/DMNRuntimeBuilderTest.java +++ b/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/internal/utils/DMNRuntimeBuilderTest.java @@ -34,7 +34,8 @@ import org.kie.internal.io.ResourceFactory; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.Assertions.assertThatThrownBy; +import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertThrows; class DMNRuntimeBuilderTest { @@ -70,12 +71,15 @@ void fromDefaultsMultipleDecisionWithoutInputDataReference() { assertThat(dmnModel).isNotNull(); DMNContext context = DMNFactory.newContext(); context.set( "Person Age", 24 ); - assertThatThrownBy(() -> dmnRuntime.evaluateAll(dmnModel, context)) - .isInstanceOf(IllegalStateException.class); + String errorMessage = "DMN: Error compiling FEEL expression 'Person Age >= 18' for name 'Can Drive?' on node 'Can Drive?': syntax error near 'Age' (DMN id: _563E78C7-EFD1-4109-9F30-B14922EF68DF, Error compiling the referenced FEEL expression) "; + IllegalStateException exception = assertThrows(IllegalStateException.class, () -> { + dmnRuntime.evaluateAll(dmnModel, context); + }); + assertEquals(errorMessage, exception.getMessage()); } @Test - void multipleDecisionWithoutInputDataReferencesEvaluateWrongDecision() { + void evaluateWrongDecisionWithoutInputDataReferencesByName() { File modelFile = FileUtils.getFile("Invalid_decisions_model.dmn"); assertThat(modelFile).isNotNull().exists(); Resource modelResource = ResourceFactory.newFileResource(modelFile); @@ -90,12 +94,15 @@ void multipleDecisionWithoutInputDataReferencesEvaluateWrongDecision() { assertThat(dmnModel).isNotNull(); DMNContext context = DMNFactory.newContext(); context.set( "Person Age", 24 ); - assertThatThrownBy(() -> dmnRuntime.evaluateByName(dmnModel, context, "Can Drive?")) - .isInstanceOf(IllegalStateException.class); + String errorMessage = "DMN: Error compiling FEEL expression 'Person Age >= 18' for name 'Can Drive?' on node 'Can Drive?': syntax error near 'Age' (DMN id: _563E78C7-EFD1-4109-9F30-B14922EF68DF, Error compiling the referenced FEEL expression) "; + IllegalStateException exception = assertThrows(IllegalStateException.class, () -> { + dmnRuntime.evaluateByName(dmnModel, context, "Can Drive"); + }); + assertEquals(errorMessage, exception.getMessage()); } @Test - void multipleDecisionWithoutInputDataReferencesValuateCorrectDecision() { + void evaluateRightDecisionWithoutInputDataReferencesByName() { File modelFile = FileUtils.getFile("Invalid_decisions_model.dmn"); assertThat(modelFile).isNotNull().exists(); Resource modelResource = ResourceFactory.newFileResource(modelFile); @@ -113,4 +120,71 @@ void multipleDecisionWithoutInputDataReferencesValuateCorrectDecision() { DMNResult dmnResult = dmnRuntime.evaluateByName(dmnModel, context, "Can Vote?"); assertThat(dmnResult).isNotNull(); } + + @Test + void evaluateWrongDecisionWithoutInputDataReferencesById() { + File modelFile = FileUtils.getFile("Invalid_decisions_model.dmn"); + assertThat(modelFile).isNotNull().exists(); + Resource modelResource = ResourceFactory.newFileResource(modelFile); + DMNRuntime dmnRuntime = DMNRuntimeBuilder.fromDefaults().buildConfiguration() + .fromResources(Collections.singletonList(modelResource)).getOrElseThrow(RuntimeException::new); + assertThat(dmnRuntime).isNotNull(); + String nameSpace = "https://kie.org/dmn/_BDC29BCF-B5DC-4AD7-8A5F-43DC08780F97"; + + final DMNModel dmnModel = dmnRuntime.getModel( + nameSpace, + "DMN_1A4BD262-7672-4887-9F25-986EE5277D16"); + assertThat(dmnModel).isNotNull(); + DMNContext context = DMNFactory.newContext(); + context.set( "Person Age", 24 ); + String errorMessage = "DMN: Error compiling FEEL expression 'Person Age >= 18' for name 'Can Drive?' on node 'Can Drive?': syntax error near 'Age' (DMN id: _563E78C7-EFD1-4109-9F30-B14922EF68DF, Error compiling the referenced FEEL expression) "; + IllegalStateException exception = assertThrows(IllegalStateException.class, () -> { + dmnRuntime.evaluateById(dmnModel, context, "_563E78C7-EFD1-4109-9F30-B14922EF68DF"); + }); + assertEquals(errorMessage, exception.getMessage()); + } + + @Test + void evaluateRightDecisionWithoutInputDataReferencesById() { + File modelFile = FileUtils.getFile("Invalid_decisions_model.dmn"); + assertThat(modelFile).isNotNull().exists(); + Resource modelResource = ResourceFactory.newFileResource(modelFile); + DMNRuntime dmnRuntime = DMNRuntimeBuilder.fromDefaults().buildConfiguration() + .fromResources(Collections.singletonList(modelResource)).getOrElseThrow(RuntimeException::new); + assertThat(dmnRuntime).isNotNull(); + String nameSpace = "https://kie.org/dmn/_BDC29BCF-B5DC-4AD7-8A5F-43DC08780F97"; + + final DMNModel dmnModel = dmnRuntime.getModel( + nameSpace, + "DMN_1A4BD262-7672-4887-9F25-986EE5277D16"); + assertThat(dmnModel).isNotNull(); + DMNContext context = DMNFactory.newContext(); + context.set( "Person Age", 24 ); + DMNResult dmnResult = dmnRuntime.evaluateById(dmnModel, context, "_7ACCB8BC-A382-4530-B8EE-AD32D187FD8B"); + assertThat(dmnResult).isNotNull(); + } + + @Test + void evaluateDecisionWithInvalidFeelError() { + File modelFile = FileUtils.getFile("InvalidFeel.dmn"); + assertThat(modelFile).isNotNull().exists(); + Resource modelResource = ResourceFactory.newFileResource(modelFile); + DMNRuntime dmnRuntime = DMNRuntimeBuilder.fromDefaults().buildConfiguration() + .fromResources(Collections.singletonList(modelResource)).getOrElseThrow(RuntimeException::new); + assertThat(dmnRuntime).isNotNull(); + String nameSpace = "https://kie.org/dmn/_9DF86C49-C80A-4744-9F50-BCE65A89C98C"; + + final DMNModel dmnModel = dmnRuntime.getModel( + nameSpace, + "DMN_33900B8B-73DD-4D1E-87E9-F6C3FE534B43"); + assertThat(dmnModel).isNotNull(); + DMNContext context = DMNFactory.newContext(); + context.set( "Person Age", 24 ); + String errorMessage = "DMN: Error compiling FEEL expression 'Person Age >?= 18' for name 'Can Drive' on node 'Can Drive': Unknown variable '?' (DMN id: _F477B6E0-C617-4087-9648-DE25A711C5F9, Error compiling the referenced FEEL expression) "; + IllegalStateException exception = assertThrows(IllegalStateException.class, () -> { + dmnRuntime.evaluateByName(dmnModel, context, "Can Drive"); + }); + assertEquals(errorMessage, exception.getMessage()); + } + } \ No newline at end of file diff --git a/kie-dmn/kie-dmn-test-resources/src/test/resources/invalid_models/DMNv1_5/InvalidFeel.dmn b/kie-dmn/kie-dmn-test-resources/src/test/resources/invalid_models/DMNv1_5/InvalidFeel.dmn new file mode 100644 index 00000000000..9bccb547986 --- /dev/null +++ b/kie-dmn/kie-dmn-test-resources/src/test/resources/invalid_models/DMNv1_5/InvalidFeel.dmn @@ -0,0 +1,36 @@ + + + + + + + + + + + + Person Age >?= 18 + + + + + + + + 190 + + + + + + + + + + + + + + + + From b51cb9369d5ce8b0119fd1b2bfcc342c2dce1c18 Mon Sep 17 00:00:00 2001 From: athira Date: Mon, 16 Dec 2024 12:57:44 +0530 Subject: [PATCH 4/7] [incubator-kie-issues#1619] Code refactoring --- kie-dmn/kie-dmn-core/pom.xml | 2 - .../org/kie/dmn/core/impl/DMNRuntimeImpl.java | 24 ++++---- .../internal/utils/DMNRuntimeBuilderTest.java | 58 ++++++++++++------- .../DMNv1_5/MultipleErrorDecision.dmn | 52 +++++++++++++++++ 4 files changed, 102 insertions(+), 34 deletions(-) create mode 100644 kie-dmn/kie-dmn-test-resources/src/test/resources/invalid_models/DMNv1_5/MultipleErrorDecision.dmn diff --git a/kie-dmn/kie-dmn-core/pom.xml b/kie-dmn/kie-dmn-core/pom.xml index 8166f3db3f9..cfa0dea7c8b 100644 --- a/kie-dmn/kie-dmn-core/pom.xml +++ b/kie-dmn/kie-dmn-core/pom.xml @@ -37,7 +37,6 @@ org.kie.dmn.core - 3.6.1 @@ -282,7 +281,6 @@ org.apache.maven.plugins maven-dependency-plugin - ${dependency-plugin.version} unpack diff --git a/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/impl/DMNRuntimeImpl.java b/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/impl/DMNRuntimeImpl.java index 29d69fda0be..7b85fd427f9 100644 --- a/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/impl/DMNRuntimeImpl.java +++ b/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/impl/DMNRuntimeImpl.java @@ -153,13 +153,7 @@ public DMNResult evaluateByName( DMNModel model, DMNContext context, String... d if (decisionNames.length == 0) { throw new IllegalArgumentException(MsgUtil.createMessage(Msg.PARAM_CANNOT_BE_EMPTY, "decisionNames")); } - List errorMessages = model.getMessages(DMNMessage.Severity.ERROR); - errorMessages.stream().filter(message -> Arrays.stream(decisionNames).anyMatch(decision -> message.getText().contains(decision))) - .findAny().ifPresent(message -> { - throw new IllegalStateException(message.getText()); - }); - - System.out.println(errorMessages); + identifyDecisionErrors(model, decisionNames); final DMNResultImpl result = createResult( model, context ); for (String name : decisionNames) { evaluateByNameInternal( model, context, result, name ); @@ -196,11 +190,7 @@ public DMNResult evaluateById( DMNModel model, DMNContext context, String... dec if (decisionIds.length == 0) { throw new IllegalArgumentException(MsgUtil.createMessage(Msg.PARAM_CANNOT_BE_EMPTY, "decisionIds")); } - List errorMessages = model.getMessages(DMNMessage.Severity.ERROR); - errorMessages.stream().filter(message -> Arrays.stream(decisionIds).anyMatch(decision -> message.getText().contains(decision))) - .findAny().ifPresent(message -> { - throw new IllegalStateException(message.getText()); - }); + identifyDecisionErrors(model, decisionIds); final DMNResultImpl result = createResult( model, context ); for ( String id : decisionIds ) { evaluateByIdInternal( model, context, result, id ); @@ -777,6 +767,16 @@ private static void handleModelErrors(DMNModel model) { throw new IllegalStateException(errorMessage); } + private static void identifyDecisionErrors(DMNModel model, String... decisions) { + List errorMessages = model.getMessages(DMNMessage.Severity.ERROR); + List identifiedErrors = errorMessages.stream() + .filter(message -> Arrays.stream(decisions).anyMatch(decision -> message.getText().contains(decision))) + .map(Message::getText).collect(Collectors.toList()); + if (!identifiedErrors.isEmpty()) { + throw new IllegalStateException(String.join(", ", identifiedErrors)); + } + } + public boolean performRuntimeTypeCheck(DMNModel model) { Objects.requireNonNull(model, () -> MsgUtil.createMessage(Msg.PARAM_CANNOT_BE_NULL, "model")); return overrideRuntimeTypeCheck || ((DMNModelImpl) model).isRuntimeTypeCheck(); diff --git a/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/internal/utils/DMNRuntimeBuilderTest.java b/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/internal/utils/DMNRuntimeBuilderTest.java index c8c8467ba23..eaae25aa940 100644 --- a/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/internal/utils/DMNRuntimeBuilderTest.java +++ b/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/internal/utils/DMNRuntimeBuilderTest.java @@ -34,8 +34,7 @@ import org.kie.internal.io.ResourceFactory; import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; +import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; class DMNRuntimeBuilderTest { @@ -72,11 +71,10 @@ void fromDefaultsMultipleDecisionWithoutInputDataReference() { DMNContext context = DMNFactory.newContext(); context.set( "Person Age", 24 ); String errorMessage = "DMN: Error compiling FEEL expression 'Person Age >= 18' for name 'Can Drive?' on node 'Can Drive?': syntax error near 'Age' (DMN id: _563E78C7-EFD1-4109-9F30-B14922EF68DF, Error compiling the referenced FEEL expression) "; - IllegalStateException exception = assertThrows(IllegalStateException.class, () -> { - dmnRuntime.evaluateAll(dmnModel, context); - }); - assertEquals(errorMessage, exception.getMessage()); - } + assertThatThrownBy(() -> dmnRuntime.evaluateAll(dmnModel, context)) + .isInstanceOf(IllegalStateException.class) + .hasMessage(errorMessage); + } @Test void evaluateWrongDecisionWithoutInputDataReferencesByName() { @@ -95,10 +93,9 @@ void evaluateWrongDecisionWithoutInputDataReferencesByName() { DMNContext context = DMNFactory.newContext(); context.set( "Person Age", 24 ); String errorMessage = "DMN: Error compiling FEEL expression 'Person Age >= 18' for name 'Can Drive?' on node 'Can Drive?': syntax error near 'Age' (DMN id: _563E78C7-EFD1-4109-9F30-B14922EF68DF, Error compiling the referenced FEEL expression) "; - IllegalStateException exception = assertThrows(IllegalStateException.class, () -> { - dmnRuntime.evaluateByName(dmnModel, context, "Can Drive"); - }); - assertEquals(errorMessage, exception.getMessage()); + assertThatThrownBy(() -> dmnRuntime.evaluateByName(dmnModel, context, "Can Drive")) + .isInstanceOf(IllegalStateException.class) + .hasMessage(errorMessage); } @Test @@ -138,10 +135,9 @@ void evaluateWrongDecisionWithoutInputDataReferencesById() { DMNContext context = DMNFactory.newContext(); context.set( "Person Age", 24 ); String errorMessage = "DMN: Error compiling FEEL expression 'Person Age >= 18' for name 'Can Drive?' on node 'Can Drive?': syntax error near 'Age' (DMN id: _563E78C7-EFD1-4109-9F30-B14922EF68DF, Error compiling the referenced FEEL expression) "; - IllegalStateException exception = assertThrows(IllegalStateException.class, () -> { - dmnRuntime.evaluateById(dmnModel, context, "_563E78C7-EFD1-4109-9F30-B14922EF68DF"); - }); - assertEquals(errorMessage, exception.getMessage()); + assertThatThrownBy(() -> dmnRuntime.evaluateById(dmnModel, context, "_563E78C7-EFD1-4109-9F30-B14922EF68DF")) + .isInstanceOf(IllegalStateException.class) + .hasMessage(errorMessage); } @Test @@ -179,12 +175,34 @@ void evaluateDecisionWithInvalidFeelError() { "DMN_33900B8B-73DD-4D1E-87E9-F6C3FE534B43"); assertThat(dmnModel).isNotNull(); DMNContext context = DMNFactory.newContext(); - context.set( "Person Age", 24 ); + context.set("Person Age", 24); String errorMessage = "DMN: Error compiling FEEL expression 'Person Age >?= 18' for name 'Can Drive' on node 'Can Drive': Unknown variable '?' (DMN id: _F477B6E0-C617-4087-9648-DE25A711C5F9, Error compiling the referenced FEEL expression) "; - IllegalStateException exception = assertThrows(IllegalStateException.class, () -> { - dmnRuntime.evaluateByName(dmnModel, context, "Can Drive"); - }); - assertEquals(errorMessage, exception.getMessage()); + assertThatThrownBy(() -> dmnRuntime.evaluateByName(dmnModel, context, "Can Drive")) + .isInstanceOf(IllegalStateException.class) + .hasMessage(errorMessage); + + } + + @Test + void evaluateMultipleErrorDecision() { + File modelFile = FileUtils.getFile("MultipleErrorDecision.dmn"); + assertThat(modelFile).isNotNull().exists(); + Resource modelResource = ResourceFactory.newFileResource(modelFile); + DMNRuntime dmnRuntime = DMNRuntimeBuilder.fromDefaults().buildConfiguration() + .fromResources(Collections.singletonList(modelResource)).getOrElseThrow(RuntimeException::new); + assertThat(dmnRuntime).isNotNull(); + String nameSpace = "https://kie.org/dmn/_36ADF828-4BE5-41E1-8808-6245D13C6AB4"; + + final DMNModel dmnModel = dmnRuntime.getModel( + nameSpace, + "DMN_45A15AF7-9910-4EAD-B249-8AE218B3BF43"); + assertThat(dmnModel).isNotNull(); + DMNContext context = DMNFactory.newContext(); + context.set( "Person Age", 24 ); + String errorMessage = "DMN: Error compiling FEEL expression 'Age + 20.?>' for name 'ContextEntry-1' on node 'Can Vote?': syntax error near '+' (DMN id: _B7D17199-0568-40EE-94D0-FDFAB0E97868, Error compiling the referenced FEEL expression) , DMN: Error compiling FEEL expression 'if Age > 25 \"YES\" elsesss \"NO\"' for name 'Can Vote?' on node 'Can Vote?': syntax error near '\"YES\"' (DMN id: _59E71393-14B3-405D-A0B4-3C1E6562823F, Error compiling the referenced FEEL expression) "; + assertThatThrownBy(() -> dmnRuntime.evaluateByName(dmnModel, context, "Can Vote")) + .isInstanceOf(IllegalStateException.class) + .hasMessage(errorMessage); } } \ No newline at end of file diff --git a/kie-dmn/kie-dmn-test-resources/src/test/resources/invalid_models/DMNv1_5/MultipleErrorDecision.dmn b/kie-dmn/kie-dmn-test-resources/src/test/resources/invalid_models/DMNv1_5/MultipleErrorDecision.dmn new file mode 100644 index 00000000000..3f5387e8764 --- /dev/null +++ b/kie-dmn/kie-dmn-test-resources/src/test/resources/invalid_models/DMNv1_5/MultipleErrorDecision.dmn @@ -0,0 +1,52 @@ + + + + + + + + + + + + + + + Age + 20.?> + + + + + if Age > 25 "YES" elsesss "NO" + + + + + + + + + + 120 + + + 190 + + + 190 + + + + + + + + + + + + + + + + From 6310666db55bf5a86f3a6aa136a38df463c93678 Mon Sep 17 00:00:00 2001 From: athira Date: Mon, 16 Dec 2024 22:57:38 +0530 Subject: [PATCH 5/7] [incubator-kie-issues#1619] Code cleanup --- .../org/kie/dmn/core/impl/DMNRuntimeImpl.java | 16 ++---- .../internal/utils/DMNRuntimeBuilderTest.java | 42 ++++++++++++++ .../invalid_models/DMNv1_5/MultipleError.dmn | 41 ++++++++++++++ .../valid_models/DMNv1_5/MultipleDecision.dmn | 55 +++++++++++++++++++ 4 files changed, 142 insertions(+), 12 deletions(-) create mode 100644 kie-dmn/kie-dmn-test-resources/src/test/resources/invalid_models/DMNv1_5/MultipleError.dmn create mode 100644 kie-dmn/kie-dmn-test-resources/src/test/resources/valid_models/DMNv1_5/MultipleDecision.dmn diff --git a/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/impl/DMNRuntimeImpl.java b/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/impl/DMNRuntimeImpl.java index 7b85fd427f9..b335f3a7fd1 100644 --- a/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/impl/DMNRuntimeImpl.java +++ b/kie-dmn/kie-dmn-core/src/main/java/org/kie/dmn/core/impl/DMNRuntimeImpl.java @@ -20,6 +20,7 @@ import java.util.Arrays; import java.util.Collection; +import java.util.Collections; import java.util.List; import java.util.Map; import java.util.Objects; @@ -113,9 +114,7 @@ public DMNResult evaluateAll(DMNModel model, DMNContext context) { Objects.requireNonNull(model, () -> MsgUtil.createMessage(Msg.PARAM_CANNOT_BE_NULL, "model")); Objects.requireNonNull(context, () -> MsgUtil.createMessage(Msg.PARAM_CANNOT_BE_NULL, "context")); boolean performRuntimeTypeCheck = performRuntimeTypeCheck(model); - if (model.hasErrors()){ - handleModelErrors(model); - } + identifyDecisionErrors(model); DMNResultImpl result = createResult( model, context ); DMNRuntimeEventManagerUtils.fireBeforeEvaluateAll( eventManager, model, result ); // the engine should evaluate all Decisions belonging to the "local" model namespace, not imported decision explicitly. @@ -761,17 +760,10 @@ private static String getDependencyIdentifier(DMNNode callerNode, DMNNode node) } - private static void handleModelErrors(DMNModel model) { - List messages = model.getMessages(DMNMessage.Severity.ERROR); - String errorMessage = messages.stream().map(Message::getText).collect(Collectors.joining(", ")); - throw new IllegalStateException(errorMessage); - } - private static void identifyDecisionErrors(DMNModel model, String... decisions) { List errorMessages = model.getMessages(DMNMessage.Severity.ERROR); - List identifiedErrors = errorMessages.stream() - .filter(message -> Arrays.stream(decisions).anyMatch(decision -> message.getText().contains(decision))) - .map(Message::getText).collect(Collectors.toList()); + List identifiedErrors = errorMessages.stream().map(Message::getText) + .filter(messages -> decisions.length == 0 || Arrays.stream(decisions).anyMatch(messages::contains)).collect(Collectors.toList()); if (!identifiedErrors.isEmpty()) { throw new IllegalStateException(String.join(", ", identifiedErrors)); } diff --git a/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/internal/utils/DMNRuntimeBuilderTest.java b/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/internal/utils/DMNRuntimeBuilderTest.java index eaae25aa940..fd6bb60a6c0 100644 --- a/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/internal/utils/DMNRuntimeBuilderTest.java +++ b/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/internal/utils/DMNRuntimeBuilderTest.java @@ -76,6 +76,26 @@ void fromDefaultsMultipleDecisionWithoutInputDataReference() { .hasMessage(errorMessage); } + @Test + void evaluateMultipleDecisionModel() { + File modelFile = FileUtils.getFile("MultipleDecision.dmn"); + assertThat(modelFile).isNotNull().exists(); + Resource modelResource = ResourceFactory.newFileResource(modelFile); + DMNRuntime dmnRuntime = DMNRuntimeBuilder.fromDefaults().buildConfiguration() + .fromResources(Collections.singletonList(modelResource)).getOrElseThrow(RuntimeException::new); + assertThat(dmnRuntime).isNotNull(); + String nameSpace = "https://kie.org/dmn/_CADD03FC-4ABD-46D2-B631-E7FDE384D6D7"; + + final DMNModel dmnModel = dmnRuntime.getModel( + nameSpace, + "DMN_54AA2CFA-2374-4FCE-8F16-B594DFF87EBE"); + assertThat(dmnModel).isNotNull(); + DMNContext context = DMNFactory.newContext(); + context.set( "Person Age", 24 ); + DMNResult dmnResult = dmnRuntime.evaluateAll(dmnModel, context); + assertThat(dmnResult).isNotNull(); + } + @Test void evaluateWrongDecisionWithoutInputDataReferencesByName() { File modelFile = FileUtils.getFile("Invalid_decisions_model.dmn"); @@ -205,4 +225,26 @@ void evaluateMultipleErrorDecision() { .hasMessage(errorMessage); } + @Test + void evaluateMultipleErrorModel() { + File modelFile = FileUtils.getFile("MultipleError.dmn"); + assertThat(modelFile).isNotNull().exists(); + Resource modelResource = ResourceFactory.newFileResource(modelFile); + DMNRuntime dmnRuntime = DMNRuntimeBuilder.fromDefaults().buildConfiguration() + .fromResources(Collections.singletonList(modelResource)).getOrElseThrow(RuntimeException::new); + assertThat(dmnRuntime).isNotNull(); + String nameSpace = "https://kie.org/dmn/_231A34DE-33C6-4787-A51F-228C910D5EAF"; + + final DMNModel dmnModel = dmnRuntime.getModel( + nameSpace, + "DMN_DC99A8C4-4524-407D-B3D1-577442AED995"); + assertThat(dmnModel).isNotNull(); + DMNContext context = DMNFactory.newContext(); + context.set( "Person Age", 24 ); + String errorMessage = "DMN: Error compiling FEEL expression 'Person Age >= 18' for name 'Can Vote?' on node 'Can Vote?': syntax error near 'Age' (DMN id: _E3EF0CCA-0F1E-42B1-8C65-124D77C07E38, Error compiling the referenced FEEL expression) , DMN: Error compiling FEEL expression 'Person Age >=18' for name 'Can Drive?' on node 'Can Drive?': syntax error near 'Age' (DMN id: _B2F31CDD-29D1-4C20-93B8-8FB8E11E1FFC, Error compiling the referenced FEEL expression) "; + assertThatThrownBy(() -> dmnRuntime.evaluateByName(dmnModel, context, "Can Vote?", "Can Drive?")) + .isInstanceOf(IllegalStateException.class) + .hasMessage(errorMessage); + } + } \ No newline at end of file diff --git a/kie-dmn/kie-dmn-test-resources/src/test/resources/invalid_models/DMNv1_5/MultipleError.dmn b/kie-dmn/kie-dmn-test-resources/src/test/resources/invalid_models/DMNv1_5/MultipleError.dmn new file mode 100644 index 00000000000..53f2404f729 --- /dev/null +++ b/kie-dmn/kie-dmn-test-resources/src/test/resources/invalid_models/DMNv1_5/MultipleError.dmn @@ -0,0 +1,41 @@ + + + + + + + + + Person Age >= 18 + + + + + + Person Age >=18 + + + + + + + + 190 + + + 190 + + + + + + + + + + + + + + + diff --git a/kie-dmn/kie-dmn-test-resources/src/test/resources/valid_models/DMNv1_5/MultipleDecision.dmn b/kie-dmn/kie-dmn-test-resources/src/test/resources/valid_models/DMNv1_5/MultipleDecision.dmn new file mode 100644 index 00000000000..0cc94c20b6d --- /dev/null +++ b/kie-dmn/kie-dmn-test-resources/src/test/resources/valid_models/DMNv1_5/MultipleDecision.dmn @@ -0,0 +1,55 @@ + + + + + + + + + + + + Person Age >= 18 + + + + + + + + + Person Age>=18 + + + + + + + + 190 + + + 190 + + + + + + + + + + + + + + + + + + + + + + + From df0ef60203caaa5a0f740363b6a63fd0a6bbd78d Mon Sep 17 00:00:00 2001 From: athira Date: Tue, 17 Dec 2024 14:32:10 +0530 Subject: [PATCH 6/7] [incubator-kie-issues#1619] Fix review comments --- .../invalid_models/DMNv1_5/InvalidFeel.dmn | 18 ++++++++++++++++++ .../DMNv1_5/Invalid_decisions_model.dmn | 18 ++++++++++++++++++ .../invalid_models/DMNv1_5/MultipleError.dmn | 18 ++++++++++++++++++ .../DMNv1_5/MultipleErrorDecision.dmn | 18 ++++++++++++++++++ 4 files changed, 72 insertions(+) diff --git a/kie-dmn/kie-dmn-test-resources/src/test/resources/invalid_models/DMNv1_5/InvalidFeel.dmn b/kie-dmn/kie-dmn-test-resources/src/test/resources/invalid_models/DMNv1_5/InvalidFeel.dmn index 9bccb547986..b7b58f6ae11 100644 --- a/kie-dmn/kie-dmn-test-resources/src/test/resources/invalid_models/DMNv1_5/InvalidFeel.dmn +++ b/kie-dmn/kie-dmn-test-resources/src/test/resources/invalid_models/DMNv1_5/InvalidFeel.dmn @@ -1,4 +1,22 @@ + diff --git a/kie-dmn/kie-dmn-test-resources/src/test/resources/invalid_models/DMNv1_5/Invalid_decisions_model.dmn b/kie-dmn/kie-dmn-test-resources/src/test/resources/invalid_models/DMNv1_5/Invalid_decisions_model.dmn index e73f3f0425a..75383661572 100644 --- a/kie-dmn/kie-dmn-test-resources/src/test/resources/invalid_models/DMNv1_5/Invalid_decisions_model.dmn +++ b/kie-dmn/kie-dmn-test-resources/src/test/resources/invalid_models/DMNv1_5/Invalid_decisions_model.dmn @@ -1,4 +1,22 @@ + diff --git a/kie-dmn/kie-dmn-test-resources/src/test/resources/invalid_models/DMNv1_5/MultipleError.dmn b/kie-dmn/kie-dmn-test-resources/src/test/resources/invalid_models/DMNv1_5/MultipleError.dmn index 53f2404f729..caef1591de9 100644 --- a/kie-dmn/kie-dmn-test-resources/src/test/resources/invalid_models/DMNv1_5/MultipleError.dmn +++ b/kie-dmn/kie-dmn-test-resources/src/test/resources/invalid_models/DMNv1_5/MultipleError.dmn @@ -1,4 +1,22 @@ + diff --git a/kie-dmn/kie-dmn-test-resources/src/test/resources/invalid_models/DMNv1_5/MultipleErrorDecision.dmn b/kie-dmn/kie-dmn-test-resources/src/test/resources/invalid_models/DMNv1_5/MultipleErrorDecision.dmn index 3f5387e8764..bfe20aedbc7 100644 --- a/kie-dmn/kie-dmn-test-resources/src/test/resources/invalid_models/DMNv1_5/MultipleErrorDecision.dmn +++ b/kie-dmn/kie-dmn-test-resources/src/test/resources/invalid_models/DMNv1_5/MultipleErrorDecision.dmn @@ -1,4 +1,22 @@ + From 2e252fe95be0f8702c1db19f4a1b57a954d11805 Mon Sep 17 00:00:00 2001 From: athira Date: Tue, 17 Dec 2024 21:25:11 +0530 Subject: [PATCH 7/7] [incubator-kie-issues#1619] Fix review comments --- .../internal/utils/DMNRuntimeBuilderTest.java | 38 +++++++++---------- .../valid_models/DMNv1_5/MultipleDecision.dmn | 18 +++++++++ 2 files changed, 37 insertions(+), 19 deletions(-) diff --git a/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/internal/utils/DMNRuntimeBuilderTest.java b/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/internal/utils/DMNRuntimeBuilderTest.java index fd6bb60a6c0..1ed6dc20f8e 100644 --- a/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/internal/utils/DMNRuntimeBuilderTest.java +++ b/kie-dmn/kie-dmn-core/src/test/java/org/kie/dmn/core/internal/utils/DMNRuntimeBuilderTest.java @@ -34,7 +34,7 @@ import org.kie.internal.io.ResourceFactory; import static org.assertj.core.api.Assertions.assertThat; -import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; +import static org.assertj.core.api.Assertions.assertThatIllegalStateException; class DMNRuntimeBuilderTest { @@ -71,9 +71,9 @@ void fromDefaultsMultipleDecisionWithoutInputDataReference() { DMNContext context = DMNFactory.newContext(); context.set( "Person Age", 24 ); String errorMessage = "DMN: Error compiling FEEL expression 'Person Age >= 18' for name 'Can Drive?' on node 'Can Drive?': syntax error near 'Age' (DMN id: _563E78C7-EFD1-4109-9F30-B14922EF68DF, Error compiling the referenced FEEL expression) "; - assertThatThrownBy(() -> dmnRuntime.evaluateAll(dmnModel, context)) - .isInstanceOf(IllegalStateException.class) - .hasMessage(errorMessage); + assertThatIllegalStateException().isThrownBy(() -> { + dmnRuntime.evaluateAll(dmnModel, context); + }).withMessage(errorMessage); } @Test @@ -113,9 +113,9 @@ void evaluateWrongDecisionWithoutInputDataReferencesByName() { DMNContext context = DMNFactory.newContext(); context.set( "Person Age", 24 ); String errorMessage = "DMN: Error compiling FEEL expression 'Person Age >= 18' for name 'Can Drive?' on node 'Can Drive?': syntax error near 'Age' (DMN id: _563E78C7-EFD1-4109-9F30-B14922EF68DF, Error compiling the referenced FEEL expression) "; - assertThatThrownBy(() -> dmnRuntime.evaluateByName(dmnModel, context, "Can Drive")) - .isInstanceOf(IllegalStateException.class) - .hasMessage(errorMessage); + assertThatIllegalStateException().isThrownBy(() -> { + dmnRuntime.evaluateByName(dmnModel, context, "Can Drive"); + }).withMessage(errorMessage); } @Test @@ -155,9 +155,9 @@ void evaluateWrongDecisionWithoutInputDataReferencesById() { DMNContext context = DMNFactory.newContext(); context.set( "Person Age", 24 ); String errorMessage = "DMN: Error compiling FEEL expression 'Person Age >= 18' for name 'Can Drive?' on node 'Can Drive?': syntax error near 'Age' (DMN id: _563E78C7-EFD1-4109-9F30-B14922EF68DF, Error compiling the referenced FEEL expression) "; - assertThatThrownBy(() -> dmnRuntime.evaluateById(dmnModel, context, "_563E78C7-EFD1-4109-9F30-B14922EF68DF")) - .isInstanceOf(IllegalStateException.class) - .hasMessage(errorMessage); + assertThatIllegalStateException().isThrownBy(() -> { + dmnRuntime.evaluateById(dmnModel, context, "_563E78C7-EFD1-4109-9F30-B14922EF68DF"); + }).withMessage(errorMessage); } @Test @@ -197,9 +197,9 @@ void evaluateDecisionWithInvalidFeelError() { DMNContext context = DMNFactory.newContext(); context.set("Person Age", 24); String errorMessage = "DMN: Error compiling FEEL expression 'Person Age >?= 18' for name 'Can Drive' on node 'Can Drive': Unknown variable '?' (DMN id: _F477B6E0-C617-4087-9648-DE25A711C5F9, Error compiling the referenced FEEL expression) "; - assertThatThrownBy(() -> dmnRuntime.evaluateByName(dmnModel, context, "Can Drive")) - .isInstanceOf(IllegalStateException.class) - .hasMessage(errorMessage); + assertThatIllegalStateException().isThrownBy(() -> { + dmnRuntime.evaluateByName(dmnModel, context, "Can Drive"); + }).withMessage(errorMessage); } @@ -220,9 +220,9 @@ void evaluateMultipleErrorDecision() { DMNContext context = DMNFactory.newContext(); context.set( "Person Age", 24 ); String errorMessage = "DMN: Error compiling FEEL expression 'Age + 20.?>' for name 'ContextEntry-1' on node 'Can Vote?': syntax error near '+' (DMN id: _B7D17199-0568-40EE-94D0-FDFAB0E97868, Error compiling the referenced FEEL expression) , DMN: Error compiling FEEL expression 'if Age > 25 \"YES\" elsesss \"NO\"' for name 'Can Vote?' on node 'Can Vote?': syntax error near '\"YES\"' (DMN id: _59E71393-14B3-405D-A0B4-3C1E6562823F, Error compiling the referenced FEEL expression) "; - assertThatThrownBy(() -> dmnRuntime.evaluateByName(dmnModel, context, "Can Vote")) - .isInstanceOf(IllegalStateException.class) - .hasMessage(errorMessage); + assertThatIllegalStateException().isThrownBy(() -> { + dmnRuntime.evaluateByName(dmnModel, context, "Can Vote"); + }).withMessage(errorMessage); } @Test @@ -242,9 +242,9 @@ void evaluateMultipleErrorModel() { DMNContext context = DMNFactory.newContext(); context.set( "Person Age", 24 ); String errorMessage = "DMN: Error compiling FEEL expression 'Person Age >= 18' for name 'Can Vote?' on node 'Can Vote?': syntax error near 'Age' (DMN id: _E3EF0CCA-0F1E-42B1-8C65-124D77C07E38, Error compiling the referenced FEEL expression) , DMN: Error compiling FEEL expression 'Person Age >=18' for name 'Can Drive?' on node 'Can Drive?': syntax error near 'Age' (DMN id: _B2F31CDD-29D1-4C20-93B8-8FB8E11E1FFC, Error compiling the referenced FEEL expression) "; - assertThatThrownBy(() -> dmnRuntime.evaluateByName(dmnModel, context, "Can Vote?", "Can Drive?")) - .isInstanceOf(IllegalStateException.class) - .hasMessage(errorMessage); + assertThatIllegalStateException().isThrownBy(() -> { + dmnRuntime.evaluateByName(dmnModel, context, "Can Vote?", "Can Drive?"); + }).withMessage(errorMessage); } } \ No newline at end of file diff --git a/kie-dmn/kie-dmn-test-resources/src/test/resources/valid_models/DMNv1_5/MultipleDecision.dmn b/kie-dmn/kie-dmn-test-resources/src/test/resources/valid_models/DMNv1_5/MultipleDecision.dmn index 0cc94c20b6d..c85554c46d7 100644 --- a/kie-dmn/kie-dmn-test-resources/src/test/resources/valid_models/DMNv1_5/MultipleDecision.dmn +++ b/kie-dmn/kie-dmn-test-resources/src/test/resources/valid_models/DMNv1_5/MultipleDecision.dmn @@ -1,4 +1,22 @@ +