From daf139b58bad44d3999c480349eae2e953d492d1 Mon Sep 17 00:00:00 2001 From: CeciliaLiu8 Date: Tue, 23 Apr 2024 11:03:26 -0500 Subject: [PATCH] MAT-7035 qdm library name can have underscore --- pom.xml | 2 +- .../ErrorHandlingControllerAdvice.java | 10 +++++++--- .../controllers/CqlLibraryControllerMvcTest.java | 16 ++++++++-------- 3 files changed, 16 insertions(+), 12 deletions(-) diff --git a/pom.xml b/pom.xml index 57bc290..16aa454 100644 --- a/pom.xml +++ b/pom.xml @@ -102,7 +102,7 @@ gov.cms.madie madie-java-models - 0.6.30-SNAPSHOT + 0.6.34-SNAPSHOT org.apache.commons diff --git a/src/main/java/gov/cms/madie/cqllibraryservice/controllers/ErrorHandlingControllerAdvice.java b/src/main/java/gov/cms/madie/cqllibraryservice/controllers/ErrorHandlingControllerAdvice.java index a0d55be..6a9b71f 100644 --- a/src/main/java/gov/cms/madie/cqllibraryservice/controllers/ErrorHandlingControllerAdvice.java +++ b/src/main/java/gov/cms/madie/cqllibraryservice/controllers/ErrorHandlingControllerAdvice.java @@ -52,9 +52,13 @@ Map onMethodArgumentNotValidException( .getAllErrors() .forEach( (error) -> { - String fieldName = ((FieldError) error).getField(); - String errorMessage = error.getDefaultMessage(); - validationErrors.put(fieldName, errorMessage); + if (error instanceof FieldError) { + String fieldName = ((FieldError) error).getField(); + String errorMessage = error.getDefaultMessage(); + validationErrors.put(fieldName, errorMessage); + } else { + validationErrors.put(error.getObjectName(), error.getDefaultMessage()); + } }); Map errorAttributes = getErrorAttributes(request, HttpStatus.BAD_REQUEST); errorAttributes.put("validationErrors", validationErrors); diff --git a/src/test/java/gov/cms/madie/cqllibraryservice/controllers/CqlLibraryControllerMvcTest.java b/src/test/java/gov/cms/madie/cqllibraryservice/controllers/CqlLibraryControllerMvcTest.java index 27c5f60..fc9c845 100644 --- a/src/test/java/gov/cms/madie/cqllibraryservice/controllers/CqlLibraryControllerMvcTest.java +++ b/src/test/java/gov/cms/madie/cqllibraryservice/controllers/CqlLibraryControllerMvcTest.java @@ -148,11 +148,11 @@ public void testCreateCqlLibraryReturnsValidationErrorForLowercaseStartCharacter .contentType(MediaType.APPLICATION_JSON_VALUE)) .andExpect(status().isBadRequest()) .andExpect( - jsonPath("$.validationErrors.cqlLibraryName") + jsonPath("$.validationErrors.cqlLibrary") .value( "Library name must start with an upper case letter, " + "followed by alpha-numeric character(s) and must not contain " - + "spaces or other special characters.")); + + "spaces or other special characters except of underscore for QDM.")); verifyNoInteractions(repository); } @@ -175,11 +175,11 @@ public void testCreateCqlLibraryReturnsValidationErrorForContainingSpaces() thro .contentType(MediaType.APPLICATION_JSON_VALUE)) .andExpect(status().isBadRequest()) .andExpect( - jsonPath("$.validationErrors.cqlLibraryName") + jsonPath("$.validationErrors.cqlLibrary") .value( "Library name must start with an upper case letter, " + "followed by alpha-numeric character(s) and must not contain " - + "spaces or other special characters.")); + + "spaces or other special characters except of underscore for QDM.")); verifyNoInteractions(repository); } @@ -202,11 +202,11 @@ public void testCreateCqlLibraryReturnsValidationErrorForContainingUnderscore() .contentType(MediaType.APPLICATION_JSON_VALUE)) .andExpect(status().isBadRequest()) .andExpect( - jsonPath("$.validationErrors.cqlLibraryName") + jsonPath("$.validationErrors.cqlLibrary") .value( "Library name must start with an upper case letter, " + "followed by alpha-numeric character(s) and must not contain " - + "spaces or other special characters.")); + + "spaces or other special characters except of underscore for QDM.")); verifyNoInteractions(repository); } @@ -230,11 +230,11 @@ public void testCreateCqlLibraryReturnsValidationErrorForContainingSpecialCharac .contentType(MediaType.APPLICATION_JSON_VALUE)) .andExpect(status().isBadRequest()) .andExpect( - jsonPath("$.validationErrors.cqlLibraryName") + jsonPath("$.validationErrors.cqlLibrary") .value( "Library name must start with an upper case letter, " + "followed by alpha-numeric character(s) and must not contain " - + "spaces or other special characters.")); + + "spaces or other special characters except of underscore for QDM.")); verifyNoInteractions(repository); }