From 745c78c9c5137a184f07471829f4d2b2f00a9dc7 Mon Sep 17 00:00:00 2001 From: elena-shmygaliova Date: Mon, 23 Sep 2024 12:48:40 +0300 Subject: [PATCH] feature/MODELINKS-248 Do not show empty arrays for extended mapping (#325) * feature/MODELINKS-248 Do not show empty arrays for extended mapping * feature/MODELINKS-248 Add unit test --------- Co-authored-by: ElenaShm --- .../authority-storage/authorityDto.yaml | 4 ++++ .../converter/AuthorityMapperTest.java | 21 +++++++++++++++++++ 2 files changed, 25 insertions(+) diff --git a/src/main/resources/swagger.api/schemas/authority-storage/authorityDto.yaml b/src/main/resources/swagger.api/schemas/authority-storage/authorityDto.yaml index 49703bf1..d0d83717 100644 --- a/src/main/resources/swagger.api/schemas/authority-storage/authorityDto.yaml +++ b/src/main/resources/swagger.api/schemas/authority-storage/authorityDto.yaml @@ -149,21 +149,25 @@ properties: description: See also from tracing term that represents broader, more general concepts related to the authority record items: $ref: './relatedHeading.yaml' + x-field-extra-annotation: "@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_EMPTY)" saftNarrowerTerm: type: array description: See also from tracing term that that represents narrower, more specific concepts derived from the authority record items: $ref: './relatedHeading.yaml' + x-field-extra-annotation: "@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_EMPTY)" saftEarlierHeading: type: array description: See also from tracing heading that was previously used to represent the concept or entity described by the authority record. This field is used to track the evolution of terms or headings over time, facilitating the linking of historical and current data. items: $ref: './relatedHeading.yaml' + x-field-extra-annotation: "@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_EMPTY)" saftLaterHeading: type: array description: See also from tracing heading that replaced the current heading used in the authority record. This field helps in maintaining the continuity of catalog records by linking past headings to their more current versions. items: $ref: './relatedHeading.yaml' + x-field-extra-annotation: "@com.fasterxml.jackson.annotation.JsonInclude(com.fasterxml.jackson.annotation.JsonInclude.Include.NON_EMPTY)" identifiers: type: array description: An extensible set of name-value pairs of identifiers associated with the resource diff --git a/src/test/java/org/folio/entlinks/controller/converter/AuthorityMapperTest.java b/src/test/java/org/folio/entlinks/controller/converter/AuthorityMapperTest.java index 108f2123..e12439ff 100644 --- a/src/test/java/org/folio/entlinks/controller/converter/AuthorityMapperTest.java +++ b/src/test/java/org/folio/entlinks/controller/converter/AuthorityMapperTest.java @@ -8,7 +8,11 @@ import static org.folio.support.base.TestConstants.TEST_ID; import static org.folio.support.base.TestConstants.TEST_PROPERTY_VALUE; import static org.folio.support.base.TestConstants.TEST_VERSION; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertTrue; +import com.fasterxml.jackson.core.JsonProcessingException; +import com.fasterxml.jackson.databind.ObjectMapper; import java.util.ArrayList; import java.util.List; import org.folio.entlinks.domain.dto.AuthorityDto; @@ -298,4 +302,21 @@ private static AuthorityDto createAuthorityDto() { dto.setSourceFileId(TEST_ID); return dto; } + + @Test + void serializedDtoShouldNotContainEmptyArraysForExtendedFields() throws JsonProcessingException { + + String serializedDto = new ObjectMapper().writeValueAsString(new AuthorityDto()); + + assertTrue(serializedDto.contains("\"saftGenreTerm\""), + "JSON should contain 'saftGenreTerm' key when it's an empty array"); + assertFalse(serializedDto.contains("\"saftBroaderTerm\""), + "JSON should not contain 'saftBroaderTerm' key when it's an empty array"); + assertFalse(serializedDto.contains("\"saftNarrowerTerm\""), + "JSON should not contain 'saftNarrowerTerm' key when it's an empty array"); + assertFalse(serializedDto.contains("\"saftEarlierHeading\""), + "JSON should not contain 'saftEarlierHeading' key when it's an empty array"); + assertFalse(serializedDto.contains("\"saftLaterHeading\""), + "JSON should not contain 'saftLaterHeading' key when it's an empty array"); + } }