Skip to content

Commit

Permalink
feature/MODELINKS-248 Do not show empty arrays for extended mapping (#…
Browse files Browse the repository at this point in the history
…325)

* feature/MODELINKS-248 Do not show empty arrays for extended mapping

* feature/MODELINKS-248 Add unit test

---------

Co-authored-by: ElenaShm <[email protected]>
  • Loading branch information
elena-shmygaliova and ShmElena authored Sep 23, 2024
1 parent d6a34b4 commit 745c78c
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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");
}
}

0 comments on commit 745c78c

Please sign in to comment.