diff --git a/CHANGELOG.md b/CHANGELOG.md index f72294efe..656950cc4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -6,6 +6,10 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/) ## Unreleased +### Fixed + +- Fixed Nullpointer in `Manifestation.toString()` + ## [9.3.2](https://github.com/dbmdz/metadata-service/releases/tag/9.3.2) - 2024-08-09 ### Added diff --git a/metasvc-model/src/main/java/de/digitalcollections/model/identifiable/entity/manifestation/Manifestation.java b/metasvc-model/src/main/java/de/digitalcollections/model/identifiable/entity/manifestation/Manifestation.java index 31f46f5ba..a33948bc7 100644 --- a/metasvc-model/src/main/java/de/digitalcollections/model/identifiable/entity/manifestation/Manifestation.java +++ b/metasvc-model/src/main/java/de/digitalcollections/model/identifiable/entity/manifestation/Manifestation.java @@ -409,11 +409,12 @@ public int hashCode() { * @param relations a list of EntityRelations * @return A texual representation of the list with subject uuid, predicate and object uuid */ - private String dumpShortenedRelations(List relations) { + protected static String dumpShortenedRelations(List relations) { return "[" + (relations == null ? "null" : relations.stream() + .filter(Objects::nonNull) .map(EntityRelation::toShortenedString) .collect(Collectors.joining(","))) + "]"; diff --git a/metasvc-model/src/test/java/de/digitalcollections/model/identifiable/entity/manifestation/ManifestationTest.java b/metasvc-model/src/test/java/de/digitalcollections/model/identifiable/entity/manifestation/ManifestationTest.java new file mode 100644 index 000000000..b37058642 --- /dev/null +++ b/metasvc-model/src/test/java/de/digitalcollections/model/identifiable/entity/manifestation/ManifestationTest.java @@ -0,0 +1,47 @@ +package de.digitalcollections.model.identifiable.entity.manifestation; + +import static org.assertj.core.api.Assertions.assertThat; + +import de.digitalcollections.model.identifiable.entity.agent.Person; +import de.digitalcollections.model.identifiable.entity.relation.EntityRelation; +import java.util.ArrayList; +import java.util.List; +import java.util.UUID; +import org.junit.jupiter.api.DisplayName; +import org.junit.jupiter.api.Test; + +@DisplayName("The Manifestation") +class ManifestationTest { + + @DisplayName("only dumps uuids of relations in toString to avoid recursion") + @Test + public void testToString() { + Person author = Person.builder().uuid(UUID.randomUUID()).build(); + Manifestation manifestation = Manifestation.builder().uuid(UUID.randomUUID()).build(); + EntityRelation entityRelation = + EntityRelation.builder().subject(author).predicate("foo").object(manifestation).build(); + manifestation.setRelations(List.of(entityRelation)); + + String actual = manifestation.toString(); + + String expected = + "Manifestation{composition='null', dimensions='null', expressionTypes=[], relations=[EntityRelation{subject=" + + author.getUuid() + + ", predicate='foo', object=" + + manifestation.getUuid() + + "}], language=null, manifestationType=null, manufacturingType=null, mediaTypes=[], otherLanguages=[], parents=[], publicationInfo=null, distributionInfo=null, productionInfo=null, scale='null', subjects=[], " + + "titles=[], version='null', work=null, customAttributes=null, navDate=null, refId=0, notes=[], description=null, identifiableObjectType=MANIFESTATION, identifiers=[], label=null, localizedUrlAliases=null, previewImage=null, previewImageRenderingHints=null, tags=[], type=ENTITY, created=null, lastModified=null, uuid=" + + manifestation.getUuid() + + "}"; + assertThat(actual).isEqualTo(expected); + } + + @DisplayName("can dump shortened Strings for weird manifestations") + @Test + public void shortenedStringsForWeirdManifestations() { + List relations = new ArrayList<>(); + relations.add(null); // yes, that's an actual real-world example! + String actual = Manifestation.dumpShortenedRelations(relations); + assertThat(actual).isEqualTo("[]"); + } +} diff --git a/metasvc-model/src/test/java/de/digitalcollections/model/jackson/identifiable/entity/manifestation/ManifestationTest.java b/metasvc-model/src/test/java/de/digitalcollections/model/jackson/identifiable/entity/manifestation/ManifestationTest.java index fa55d010b..2bb8c9141 100644 --- a/metasvc-model/src/test/java/de/digitalcollections/model/jackson/identifiable/entity/manifestation/ManifestationTest.java +++ b/metasvc-model/src/test/java/de/digitalcollections/model/jackson/identifiable/entity/manifestation/ManifestationTest.java @@ -1,7 +1,5 @@ package de.digitalcollections.model.jackson.identifiable.entity.manifestation; -import static org.assertj.core.api.Assertions.assertThat; - import de.digitalcollections.model.RelationSpecification; import de.digitalcollections.model.identifiable.Identifier; import de.digitalcollections.model.identifiable.entity.agent.Person; @@ -201,27 +199,4 @@ public void testSerializeDeserialize() throws Exception { manifestation, "serializedTestObjects/identifiable/entity/manifestation/Manifestation.json"); } - - @DisplayName("only dumps uuids of relations in toString to avoid recursion") - @Test - public void testToString() { - Person author = Person.builder().uuid(UUID.randomUUID()).build(); - Manifestation manifestation = Manifestation.builder().uuid(UUID.randomUUID()).build(); - EntityRelation entityRelation = - EntityRelation.builder().subject(author).predicate("foo").object(manifestation).build(); - manifestation.setRelations(List.of(entityRelation)); - - String actual = manifestation.toString(); - - String expected = - "Manifestation{composition='null', dimensions='null', expressionTypes=[], relations=[EntityRelation{subject=" - + author.getUuid() - + ", predicate='foo', object=" - + manifestation.getUuid() - + "}], language=null, manifestationType=null, manufacturingType=null, mediaTypes=[], otherLanguages=[], parents=[], publicationInfo=null, distributionInfo=null, productionInfo=null, scale='null', subjects=[], " - + "titles=[], version='null', work=null, customAttributes=null, navDate=null, refId=0, notes=[], description=null, identifiableObjectType=MANIFESTATION, identifiers=[], label=null, localizedUrlAliases=null, previewImage=null, previewImageRenderingHints=null, tags=[], type=ENTITY, created=null, lastModified=null, uuid=" - + manifestation.getUuid() - + "}"; - assertThat(actual).isEqualTo(expected); - } }