diff --git a/kogito-codegen-modules/kogito-codegen-decisions/src/main/java/org/kie/kogito/codegen/decision/DecisionValidation.java b/kogito-codegen-modules/kogito-codegen-decisions/src/main/java/org/kie/kogito/codegen/decision/DecisionValidation.java index f5f194ccbba..dd9894ee7e0 100644 --- a/kogito-codegen-modules/kogito-codegen-decisions/src/main/java/org/kie/kogito/codegen/decision/DecisionValidation.java +++ b/kogito-codegen-modules/kogito-codegen-decisions/src/main/java/org/kie/kogito/codegen/decision/DecisionValidation.java @@ -82,13 +82,10 @@ static void dmnValidateResources(KogitoBuildContext context, Collection schemaModelValidations = DMNValidatorFactory.newValidator(Arrays.asList(new ExtendedDMNProfile())) + List schemaModelValidations = DMNValidatorFactory.newValidator(List.of(new ExtendedDMNProfile())) .validateUsing(DMNValidator.Validation.VALIDATE_SCHEMA, DMNValidator.Validation.VALIDATE_MODEL) - .theseModels(resources.stream() - .map(DecisionValidation::resourceToReader) - .collect(Collectors.toList()) - .toArray(new Reader[] {})); + .theseModels(resources.toArray(new Resource[] {})); logValidationMessages(schemaModelValidations, DecisionValidation::extractMsgPrefix, DMNMessage::getText); processMessagesHandleErrors(validateOption, schemaModelValidations); } @@ -187,18 +184,17 @@ static void dmnValidateDecisionTablesInModels(KogitoBuildContext context, Collec } private static void processMessagesHandleErrors(ValidationOption validateOption, Collection messages) { - List errors = messages.stream().filter(m -> m.getLevel() == Level.ERROR).collect(Collectors.toList()); + List errors = messages.stream().filter(m -> m.getLevel() == Level.ERROR).toList(); if (!errors.isEmpty()) { if (validateOption != ValidationOption.IGNORE) { StringBuilder sb = new StringBuilder("DMN Validation schema and model validation contained errors").append("\n"); sb.append("You may configure ").append(DecisionCodegen.VALIDATION_CONFIGURATION_KEY).append("=IGNORE to ignore validation errors").append("\n"); sb.append("DMN Validation errors:").append("\n"); - sb.append(errors.stream().map(m -> modelName(m) + ": " + m.getMessage()).collect(Collectors.joining(",\n"))); + sb.append(errors.stream().map(m -> modelName(m) + ": " + m.getText()).collect(Collectors.joining(",\n"))); LOG.error(sb.toString()); throw new RuntimeException(sb.toString()); } else { LOG.warn("DMN Validation encountered errors but validation configuration was set to IGNORE, continuing with no blocking error."); - return; } } } diff --git a/kogito-codegen-modules/kogito-codegen-decisions/src/test/java/org/kie/kogito/codegen/decision/DecisionCodegenTest.java b/kogito-codegen-modules/kogito-codegen-decisions/src/test/java/org/kie/kogito/codegen/decision/DecisionCodegenTest.java index beaef72378c..962d99632ec 100644 --- a/kogito-codegen-modules/kogito-codegen-decisions/src/test/java/org/kie/kogito/codegen/decision/DecisionCodegenTest.java +++ b/kogito-codegen-modules/kogito-codegen-decisions/src/test/java/org/kie/kogito/codegen/decision/DecisionCodegenTest.java @@ -52,6 +52,7 @@ import static java.util.Collections.singleton; import static org.assertj.core.api.Assertions.assertThat; import static org.junit.jupiter.api.Assertions.assertEquals; +import static org.junit.jupiter.api.Assertions.assertTrue; import static org.kie.kogito.codegen.api.utils.KogitoContextTestUtils.mockClassAvailabilityResolver; import static org.kie.kogito.grafana.utils.GrafanaDashboardUtils.DISABLED_DOMAIN_DASHBOARDS; import static org.kie.kogito.grafana.utils.GrafanaDashboardUtils.DISABLED_OPERATIONAL_DASHBOARDS; @@ -211,7 +212,8 @@ public void resilientToDuplicateDMNIDs(KogitoBuildContext.Builder contextBuilder public void emptyName(KogitoBuildContext.Builder contextBuilder) { DecisionCodegen codeGenerator = getDecisionCodegen("src/test/resources/decision-empty-name", contextBuilder); RuntimeException re = Assertions.assertThrows(RuntimeException.class, codeGenerator::generate); - assertEquals("Model name should not be empty", re.getMessage()); + String expected = "DMN: Invalid name '': Name cannot be null or empty (DMN id: _f27bb64b-6fc7-4e1f-9848-11ba35e0df44, The listed name is not a valid FEEL identifier)"; + assertTrue(re.getMessage().contains(expected)); } @ParameterizedTest diff --git a/kogito-codegen-modules/kogito-codegen-decisions/src/test/resources/decision-empty-name/vacationDays.dmn b/kogito-codegen-modules/kogito-codegen-decisions/src/test/resources/decision-empty-name/vacationDays.dmn index e6b96c58a76..69a239b2676 100644 --- a/kogito-codegen-modules/kogito-codegen-decisions/src/test/resources/decision-empty-name/vacationDays.dmn +++ b/kogito-codegen-modules/kogito-codegen-decisions/src/test/resources/decision-empty-name/vacationDays.dmn @@ -1,196 +1,63 @@ - - - - - string - - - string - - - string - - - string - - - - - string - - - string - - - string - - - Any - - - tAddress - - - - - number - - + + + + + + + string + + number - - string - - - tEmployee - - - - + + + - - - - - - - - - - employee.address.country - - - - - 15 - - - - - "US" - - - 10 - - - - - "IT" - - - 20 - - - - - - - - - - - - + + + + - - - - - employee - - - - - - null - - - - - - vacationDays - - - - - - null - - - + + + + + Say Hello( An Imported Person ) + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file + + + + + + + "Hello " + Person.name + "!" + + + + +