diff --git a/pom.xml b/pom.xml index 047a4ff9..d27fbe78 100644 --- a/pom.xml +++ b/pom.xml @@ -47,7 +47,7 @@ 2.17.2 2.17.2 1.5.1 - 5.0.4 + 5.0.5 1.18.1 3.3.0 2.4 diff --git a/src/main/java/info/freelibrary/iiif/presentation/v3/AbstractCanvas.java b/src/main/java/info/freelibrary/iiif/presentation/v3/AbstractCanvas.java index b9b9a00f..f2be3981 100644 --- a/src/main/java/info/freelibrary/iiif/presentation/v3/AbstractCanvas.java +++ b/src/main/java/info/freelibrary/iiif/presentation/v3/AbstractCanvas.java @@ -74,15 +74,15 @@ abstract class AbstractCanvas> extends NavigableReso /** The canvas' optional minter. */ private Minter myMinter; - /** The canvas' other canvases (other than painting or supplementing). */ - private List> myOtherAnnotations; - /** The painting annotations on the canvas. */ private List> myPaintingPageList; /** The supplementing annotations on the canvas. */ private List> mySupplementingPageList; + /** The canvas' other canvases (other than painting or supplementing). */ + private List> myWebAnnotations; + /** The canvas' width. */ private int myWidth; @@ -149,8 +149,7 @@ public boolean equals(final Object aObject) { other = (AbstractCanvas) aObject; return Objects.equals(myDuration, other.myDuration) && Objects.equals(myHeight, other.myHeight) && - Objects.equals(myWidth, other.myWidth) && - Objects.equals(myOtherAnnotations, other.myOtherAnnotations) && + Objects.equals(myWidth, other.myWidth) && Objects.equals(myWebAnnotations, other.myWebAnnotations) && Objects.equals(myPaintingPageList, other.myPaintingPageList) && Objects.equals(mySupplementingPageList, other.mySupplementingPageList) && super.equals(other); } @@ -187,20 +186,6 @@ public Optional getMinter() { return Optional.ofNullable(myMinter); } - /** - * Gets the canvas' annotation pages that aren't related to painting. - * - * @return The canvas' non-painting annotation pages - */ - @JsonIgnore - public List> getOtherAnnotations() { - if (myOtherAnnotations == null) { - myOtherAnnotations = new ArrayList<>(); - } - - return myOtherAnnotations; - } - /** * Gets the canvas' annotation pages for painting annotations. * @@ -230,6 +215,20 @@ public List> getSupplementingPages() { return mySupplementingPageList; } + /** + * Gets the canvas' annotation pages that aren't related to painting. + * + * @return The canvas' non-painting annotation pages + */ + @JsonIgnore + public List> getWebAnnotations() { + if (myWebAnnotations == null) { + myWebAnnotations = new ArrayList<>(); + } + + return myWebAnnotations; + } + /** * Gets the width of the canvas. * @@ -243,7 +242,7 @@ public int getWidth() { @Override public int hashCode() { - return Objects.hash(super.hashCode(), myDuration, myHeight, myWidth, myOtherAnnotations, myPaintingPageList, + return Objects.hash(super.hashCode(), myDuration, myHeight, myWidth, myWebAnnotations, myPaintingPageList, mySupplementingPageList); } @@ -309,36 +308,6 @@ public T setMinter(final Minter aMinter) { return (T) this; } - /** - * Sets the canvas' annotation pages from an array. - * - * @param aAnnotationArray An array of annotation pages - * @return The canvas - */ - @JsonIgnore - @SafeVarargs - public final T setOtherAnnotations(final AnnotationPage... aAnnotationArray) { - return setOtherAnnotations(Arrays.asList(aAnnotationArray)); - } - - /** - * Sets the canvas annotation pages from a list. - * - * @param aAnnotationList A list of annotation pages - * @return The canvas - */ - @JsonIgnore - @SuppressWarnings({ JDK.UNCHECKED }) - public T setOtherAnnotations(final List> aAnnotationList) { - final List> annotations = getOtherAnnotations(); - - Objects.requireNonNull(aAnnotationList); - annotations.clear(); - annotations.addAll(aAnnotationList); - - return (T) this; - } - /** * Sets the canvas' painting pages. * @@ -409,6 +378,36 @@ public T setSupplementingPages(final List... aAnnotationArray) { + return setWebAnnotations(Arrays.asList(aAnnotationArray)); + } + + /** + * Sets the canvas annotation pages from a list. + * + * @param aAnnotationList A list of annotation pages + * @return The canvas + */ + @JsonIgnore + @SuppressWarnings({ JDK.UNCHECKED }) + public T setWebAnnotations(final List> aAnnotationList) { + final List> annotations = getWebAnnotations(); + + Objects.requireNonNull(aAnnotationList); + annotations.clear(); + annotations.addAll(aAnnotationList); + + return (T) this; + } + /** * Sets the width and height of the canvas. * @@ -430,17 +429,6 @@ public T setWidthHeight(final int aWidth, final int aHeight) { return (T) this; } - /** - * Gets the manifest context. The manifest can either have a single context or an array of contexts (Cf. - * https://iiif.io/api/presentation/3.0/#46-linked-data-context-and-extensions) - * - * @return The manifest context - */ - @Override - @JsonGetter(JsonKeys.CONTEXT) - @JsonInclude(Include.NON_NULL) - protected abstract Object getJsonContext(); - /** * Paints a canvas, that has been initialized with a minter, with the supplied content resources. If the canvas was * not initialized with a minter, a {@code MintingException} is thrown. @@ -731,7 +719,7 @@ private List> getAnnotations() { final List> annotations = new ArrayList<>(); getSupplementingPages().forEach(annotations::add); - getOtherAnnotations().forEach(annotations::add); + getWebAnnotations().forEach(annotations::add); return annotations; } @@ -908,7 +896,7 @@ private Minter getMinter(final String aMessageCode) { @JsonSetter(JsonKeys.ANNOTATIONS) private > AbstractCanvas setAnnotations(final Object aObject) { final List> supplementingPages = getSupplementingPages(); - final List> otherAnnotations = getOtherAnnotations(); + final List> otherAnnotations = getWebAnnotations(); final List> annotationList = getDeserializedPageList(aObject); supplementingPages.clear(); diff --git a/src/main/java/info/freelibrary/iiif/presentation/v3/AbstractContentResource.java b/src/main/java/info/freelibrary/iiif/presentation/v3/AbstractContentResource.java index 154cb36b..adead6d6 100644 --- a/src/main/java/info/freelibrary/iiif/presentation/v3/AbstractContentResource.java +++ b/src/main/java/info/freelibrary/iiif/presentation/v3/AbstractContentResource.java @@ -112,7 +112,6 @@ public List> getAnnotations() { * * @return The media type format of the content resource */ - @JsonInclude(Include.NON_EMPTY) @JsonSerialize(contentUsing = MediaTypeSerializer.class, keyUsing = MediaTypeKeySerializer.class) public Optional getFormat() { return Optional.ofNullable(myFormat); @@ -189,7 +188,6 @@ public T setFormat(final MediaType aMediaType) { * @return A form of language ready to be serialized */ @JsonGetter(JsonKeys.LANGUAGE) - @JsonInclude(Include.NON_EMPTY) private Object getLanguage() { final List languages = getLanguages(); return languages.size() == SINGLE_INSTANCE ? languages.get(0) : languages; diff --git a/src/main/java/info/freelibrary/iiif/presentation/v3/AbstractResource.java b/src/main/java/info/freelibrary/iiif/presentation/v3/AbstractResource.java index 5c2e80bb..2b6a2913 100644 --- a/src/main/java/info/freelibrary/iiif/presentation/v3/AbstractResource.java +++ b/src/main/java/info/freelibrary/iiif/presentation/v3/AbstractResource.java @@ -1,12 +1,12 @@ package info.freelibrary.iiif.presentation.v3; -import java.net.URI; import java.util.ArrayList; import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Objects; +import java.util.Optional; import com.fasterxml.jackson.annotation.JsonGetter; import com.fasterxml.jackson.annotation.JsonIgnore; @@ -14,7 +14,6 @@ import com.fasterxml.jackson.annotation.JsonProperty; import com.fasterxml.jackson.annotation.JsonPropertyOrder; import com.fasterxml.jackson.annotation.JsonSetter; -import com.fasterxml.jackson.annotation.JsonUnwrapped; import com.fasterxml.jackson.core.JsonProcessingException; import com.fasterxml.jackson.databind.annotation.JsonDeserialize; @@ -54,9 +53,6 @@ JsonKeys.ITEMS, JsonKeys.SERVICE, JsonKeys.STRUCTURES, JsonKeys.SERVICES, JsonKeys.NAV_DATE, JsonKeys.ANNOTATIONS }) abstract class AbstractResource> implements Resource { - /** The IIIF Presentation context URI. */ - protected static final URI PRESENTATION_CONTEXT_URI = URI.create("http://iiif.io/api/presentation/3/context.json"); - /** The logger used by abstract resources. */ private static final Logger LOGGER = LoggerFactory.getLogger(AbstractResource.class, MessageCodes.BUNDLE); @@ -229,9 +225,9 @@ public String getID() { * @return The label */ @Override - @JsonUnwrapped - public Label getLabel() { - return myLabel; + @JsonGetter(JsonKeys.LABEL) + public Optional getSummary() { + return Optional.ofNullable(mySummary); } /** @@ -672,6 +668,7 @@ public T setServices(final Service... aServiceArray) { * @return The resource */ @Override + @JsonSetter(JsonKeys.SUMMARY) @SuppressWarnings(JDK.UNCHECKED) public T setSummary(final Summary aSummary) { Objects.requireNonNull(aSummary); diff --git a/src/main/java/info/freelibrary/iiif/presentation/v3/AccompanyingCanvas.java b/src/main/java/info/freelibrary/iiif/presentation/v3/AccompanyingCanvas.java index 14ee1f1f..81e61a9f 100644 --- a/src/main/java/info/freelibrary/iiif/presentation/v3/AccompanyingCanvas.java +++ b/src/main/java/info/freelibrary/iiif/presentation/v3/AccompanyingCanvas.java @@ -210,9 +210,4 @@ public final AccompanyingCanvas supplementWith(final String aCanvasRegion, final List aContentList) { return super.supplement(this, new MediaFragmentSelector(aCanvasRegion), false, aContentList); } - - @Override - protected Object getJsonContext() { - return null; - } } diff --git a/src/main/java/info/freelibrary/iiif/presentation/v3/AnnotationCollection.java b/src/main/java/info/freelibrary/iiif/presentation/v3/AnnotationCollection.java index 7eabc3d7..6dbe764b 100644 --- a/src/main/java/info/freelibrary/iiif/presentation/v3/AnnotationCollection.java +++ b/src/main/java/info/freelibrary/iiif/presentation/v3/AnnotationCollection.java @@ -92,8 +92,8 @@ public > Optional> getLastPage() { * @return The viewing direction */ @JsonGetter(JsonKeys.VIEWING_DIRECTION) - public ViewingDirection getViewingDirection() { - return myViewingDirection; + public Optional getViewingDirection() { + return Optional.ofNullable(myViewingDirection); } @Override diff --git a/src/main/java/info/freelibrary/iiif/presentation/v3/AnnotationPage.java b/src/main/java/info/freelibrary/iiif/presentation/v3/AnnotationPage.java index 3aae80a7..27d5028c 100644 --- a/src/main/java/info/freelibrary/iiif/presentation/v3/AnnotationPage.java +++ b/src/main/java/info/freelibrary/iiif/presentation/v3/AnnotationPage.java @@ -11,6 +11,8 @@ import com.fasterxml.jackson.annotation.JsonGetter; import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonInclude.Include; import com.fasterxml.jackson.annotation.JsonSetter; import info.freelibrary.util.Logger; @@ -33,6 +35,7 @@ * @param The type of annotation encapsulated on the page */ @SuppressWarnings({ PMD.GOD_CLASS, PMD.EXCESSIVE_IMPORTS, PMD.COUPLING_BETWEEN_OBJECTS }) +@JsonInclude(Include.NON_EMPTY) public class AnnotationPage> extends AbstractResource> implements Resource> { @@ -256,13 +259,14 @@ public > AnnotationPage setNextPage(final AnnotationP } /** - * Gets the context when the annotation page is intended to be used outside of a manifest. + * Gets the context only when the annotation page is intended to be used outside of a manifest, as indicated by + * using {@code AnnotationPage#setExternalContext()}. * * @return The context URI */ @JsonGetter(JsonKeys.CONTEXT) - private URI getExternalContext() { - return isExternal ? PRESENTATION_CONTEXT_URI : null; + private Optional getExternalContext() { + return isExternal ? Optional.of(ContextList.PRESENTATION_CONTEXT_URI) : Optional.empty(); } /** @@ -293,7 +297,7 @@ private String getListIDs(final List aAnnotationList) { */ @JsonSetter(JsonKeys.CONTEXT) private AnnotationPage setExternalContext(final String aContextURI) { - if (PRESENTATION_CONTEXT_URI.toString().equalsIgnoreCase(aContextURI)) { + if (ContextList.PRESENTATION_CONTEXT_URI.toString().equalsIgnoreCase(aContextURI)) { setExternalContext(); } diff --git a/src/main/java/info/freelibrary/iiif/presentation/v3/Canvas.java b/src/main/java/info/freelibrary/iiif/presentation/v3/Canvas.java index 55e2152d..593dad97 100644 --- a/src/main/java/info/freelibrary/iiif/presentation/v3/Canvas.java +++ b/src/main/java/info/freelibrary/iiif/presentation/v3/Canvas.java @@ -27,10 +27,10 @@ public class Canvas extends AbstractCanvas implements CanvasResource { /** The canvas' accompanying canvas. */ - private Optional myAccompanyingCanvas; + private AccompanyingCanvas myAccompanyingCanvas; /** The canvas' placeholder canvas. */ - private Optional myPlaceholderCanvas; + private PlaceholderCanvas myPlaceholderCanvas; /** * Creates a new canvas, using the supplied minter to create the canvas ID. @@ -104,7 +104,7 @@ public boolean equals(final Object aObject) { @JsonGetter(JsonKeys.ACCOMPANYING_CANVAS) @JsonInclude(Include.NON_ABSENT) public Optional getAccompanyingCanvas() { - return myAccompanyingCanvas; + return Optional.ofNullable(myAccompanyingCanvas); } @Override @@ -124,7 +124,7 @@ public List> getPaintingPages() { @JsonGetter(JsonKeys.PLACEHOLDER_CANVAS) @JsonInclude(Include.NON_ABSENT) public Optional getPlaceholderCanvas() { - return myPlaceholderCanvas; + return Optional.ofNullable(myPlaceholderCanvas); } @Override @@ -204,7 +204,7 @@ public final Canvas paintWith(final String aCanvasRegion, final List aContentList) { return super.supplement(this, new MediaFragmentSelector(aCanvasRegion), false, aContentList); } - - @Override - protected Object getJsonContext() { - return null; - } } diff --git a/src/main/java/info/freelibrary/iiif/presentation/v3/CanvasResource.java b/src/main/java/info/freelibrary/iiif/presentation/v3/CanvasResource.java index a1a0b117..0b5ff51c 100644 --- a/src/main/java/info/freelibrary/iiif/presentation/v3/CanvasResource.java +++ b/src/main/java/info/freelibrary/iiif/presentation/v3/CanvasResource.java @@ -58,7 +58,7 @@ public interface CanvasResource> extends Resource * * @return The canvas' non-painting annotation pages */ - List> getOtherAnnotations(); + List> getWebAnnotations(); /** * Gets the canvas' annotation pages for painting annotations. @@ -424,7 +424,7 @@ public interface CanvasResource> extends Resource * @return The canvas */ @SuppressWarnings(JDK.UNCHECKED) - T setOtherAnnotations(AnnotationPage... aAnnotationArray); + T setWebAnnotations(AnnotationPage... aAnnotationArray); /** * Sets the canvas annotation pages from a list. @@ -432,7 +432,7 @@ public interface CanvasResource> extends Resource * @param aAnnotationList A list of annotation pages * @return The canvas */ - T setOtherAnnotations(List> aAnnotationList); + T setWebAnnotations(List> aAnnotationList); /** * Sets the canvas' annotation pages for painting annotations. diff --git a/src/main/java/info/freelibrary/iiif/presentation/v3/Collection.java b/src/main/java/info/freelibrary/iiif/presentation/v3/Collection.java index 57d41996..ddd86b03 100644 --- a/src/main/java/info/freelibrary/iiif/presentation/v3/Collection.java +++ b/src/main/java/info/freelibrary/iiif/presentation/v3/Collection.java @@ -1,7 +1,6 @@ package info.freelibrary.iiif.presentation.v3; -import java.net.URI; import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -17,8 +16,10 @@ import info.freelibrary.util.ListUtils; import info.freelibrary.util.warnings.Eclipse; +import info.freelibrary.util.warnings.JDK; import info.freelibrary.util.warnings.PMD; +import info.freelibrary.iiif.presentation.v3.annotations.WebAnnotation; import info.freelibrary.iiif.presentation.v3.exts.geo.NavPlace; import info.freelibrary.iiif.presentation.v3.ids.UriUtils; import info.freelibrary.iiif.presentation.v3.properties.Behavior; @@ -42,6 +43,9 @@ public class Collection extends NavigableResource implements Resourc /** The collection's accompanying canvas. */ private AccompanyingCanvas myAccompanyingCanvas; + /** The collection's annotations. */ + private List> myAnnotations; + /** The collection's list of items. */ private List myItems; @@ -62,6 +66,7 @@ public class Collection extends NavigableResource implements Resourc */ public Collection(final String aID, final Label aLabel) { super(ResourceTypes.COLLECTION, aID, aLabel, CollectionBehavior.class); + getContextList(); // Initializes the context list } /** @@ -69,6 +74,7 @@ public Collection(final String aID, final Label aLabel) { */ private Collection() { super(ResourceTypes.COLLECTION, CollectionBehavior.class); + getContextList(); // Initializes the context list } @Override @@ -88,6 +94,7 @@ public boolean equals(final Object aObject) { return Objects.equals(myAccompanyingCanvas, other.myAccompanyingCanvas) && Objects.equals(myPlaceholderCanvas, other.myPlaceholderCanvas) && Objects.equals(myViewingDirection, other.myViewingDirection) && + ListUtils.equals(myAnnotations, other.myAnnotations) && ListUtils.equals(myServiceDefinitions, other.myServiceDefinitions) && ListUtils.equals(myItems, other.myItems) && super.equals(other); } @@ -104,14 +111,18 @@ public Optional getAccompanyingCanvas() { } /** - * Gets the primary collection context. + * Gets the collection's annotation pages. * - * @return The collection context + * @return This collection's annotation pages */ - @Override - @JsonIgnore - public URI getContext() { - return PRESENTATION_CONTEXT_URI; + @JsonGetter(JsonKeys.ANNOTATIONS) + @SuppressWarnings({ JDK.UNCHECKED }) + public List> getAnnotations() { + if (myAnnotations == null) { + myAnnotations = new ArrayList<>(); + } + + return myAnnotations; } /** @@ -159,14 +170,14 @@ public List getServiceDefinitions() { * @return The viewing direction */ @JsonGetter(JsonKeys.VIEWING_DIRECTION) - public ViewingDirection getViewingDirection() { - return myViewingDirection; + public Optional getViewingDirection() { + return Optional.ofNullable(myViewingDirection); } @Override public int hashCode() { - return Objects.hash(super.hashCode(), myAccompanyingCanvas, myPlaceholderCanvas, myViewingDirection, - myServiceDefinitions, myItems); + return Objects.hash(super.hashCode(), myAccompanyingCanvas, myPlaceholderCanvas, myAnnotations, + myViewingDirection, myServiceDefinitions, myItems); } /** @@ -181,6 +192,41 @@ public Collection setAccompanyingCanvas(final AccompanyingCanvas aCanvas) { return this; } + /** + * Sets the collection's annotation pages. + * + * @param aPageArray An array of annotation pages + * @return This collection + */ + @SafeVarargs + @JsonIgnore + public final Collection setAnnotations(final AnnotationPage... aPageArray) { + final List> annotations = getAnnotations(); + + Objects.requireNonNull(aPageArray); + annotations.clear(); + Arrays.stream(aPageArray).forEach(annotations::add); + + return this; + } + + /** + * Sets the collection's annotation pages. + * + * @param aPageList A list of annotation pages + * @return This collection + */ + @JsonSetter(JsonKeys.ANNOTATIONS) + public Collection setAnnotations(final List> aPageList) { + final List> annotations = getAnnotations(); + + Objects.requireNonNull(aPageList); + annotations.clear(); + annotations.addAll(aPageList); + + return this; + } + @Override @JsonIgnore public Collection setBehaviors(final Behavior... aBehaviorArray) { @@ -202,6 +248,18 @@ public Collection setBehaviors(final List aBehaviorList) { return collection; } + /** + * Sets the items associated with this collection. + * + * @param anItemArray An array of manifests and/or collections + * @return This collection + */ + @JsonIgnore + public Collection setItems(final Item... anItemArray) { + myItems = Arrays.asList(anItemArray); + return this; + } + /** * Sets the items associated with this collection. * @@ -306,7 +364,7 @@ public Item(final Collection aCollection) { } myType = Item.Type.fromLabel(ResourceTypes.COLLECTION).orElseThrow(); - myLabel = Objects.requireNonNull(aCollection.getLabel()); + aCollection.getLabel().ifPresent(label -> myLabel = label); myID = aCollection.getID(); // ID rules should have been checked by Collection already } @@ -324,7 +382,7 @@ public Item(final Manifest aManifest) { } myType = Item.Type.fromLabel(ResourceTypes.MANIFEST).orElseThrow(); - myLabel = Objects.requireNonNull(aManifest.getLabel()); + aManifest.getLabel().ifPresent(label -> myLabel = label); myID = aManifest.getID(); // ID rules should have been checked by Manifest already } @@ -352,8 +410,8 @@ public String getID() { * @return The item label */ @JsonGetter(JsonKeys.LABEL) - public Label getLabel() { - return myLabel; + public Optional getSummary() { return mySourceCanvas.getSummary(); } @@ -221,6 +201,11 @@ public String getType() { return mySourceCanvas.getType(); } + @Override + public List> getWebAnnotations() { + return mySourceCanvas.getWebAnnotations(); + } + @Override public int getWidth() { return mySourceCanvas.getWidth(); @@ -231,11 +216,6 @@ public int hashCode() { return mySourceCanvas.hashCode(); } - @Override - public boolean removeContext(final URI aContextURI) { - return mySourceCanvas.removeContext(aContextURI); - } - @Override public Canvas setAccompanyingCanvas(final AccompanyingCanvas aCanvas) { return mySourceCanvas.setAccompanyingCanvas(aCanvas); @@ -381,11 +361,6 @@ protected float convertToFinitePositiveFloat(final Number aNumber) { return mySourceCanvas.convertToFinitePositiveFloat(aNumber); } - @Override - protected Object getJsonContext() { - return mySourceCanvas.getJsonContext(); - } - @Override boolean canFrame(final ContentResource aContent) { return mySourceCanvas.canFrame(aContent); diff --git a/src/main/java/info/freelibrary/iiif/presentation/v3/Resource.java b/src/main/java/info/freelibrary/iiif/presentation/v3/Resource.java index a4c5968c..19e39935 100644 --- a/src/main/java/info/freelibrary/iiif/presentation/v3/Resource.java +++ b/src/main/java/info/freelibrary/iiif/presentation/v3/Resource.java @@ -2,6 +2,7 @@ package info.freelibrary.iiif.presentation.v3; import java.util.List; +import java.util.Optional; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonSetter; @@ -44,9 +45,9 @@ public interface Resource> { List getHomepages(); /** - * Gets the resource ID. + * Gets the ID. * - * @return The resource's ID + * @return The ID */ String getID(); @@ -55,7 +56,7 @@ public interface Resource> { * * @return The resource's label */ - Label getLabel(); + Optional getSummary(); /** * Gets a list of resource thumbnails. A thumbnail can be any type of content resource, not just diff --git a/src/main/java/info/freelibrary/iiif/presentation/v3/TextualBody.java b/src/main/java/info/freelibrary/iiif/presentation/v3/TextualBody.java index 6a3ca440..f785ac1a 100644 --- a/src/main/java/info/freelibrary/iiif/presentation/v3/TextualBody.java +++ b/src/main/java/info/freelibrary/iiif/presentation/v3/TextualBody.java @@ -1,6 +1,8 @@ package info.freelibrary.iiif.presentation.v3; +import static info.freelibrary.util.Constants.EMPTY; + import java.util.Locale; import java.util.Objects; import java.util.Optional; @@ -89,21 +91,21 @@ public TextualBody(final SkolemIriFactory aFactory) { * @return An optional media type form of format */ @Override - @JsonInclude(Include.NON_EMPTY) @JsonSerialize(contentUsing = MediaTypeSerializer.class, keyUsing = MediaTypeKeySerializer.class) public Optional getFormat() { return Optional.ofNullable(myFormat); } /** - * Gets the ID of the TextualBody if it's serializable; else, it returns a null. + * Gets the ID of the TextualBody if it's serializable and has an ID; else, an empty string is returned. The empty + * string is ignored when the object is serialized to JSON. * * @return A serializable ID */ @Override @JsonGetter(JsonKeys.ID) public String getID() { - return hasSerializableID ? myID : null; + return hasSerializableID && myID != null ? myID : EMPTY; } /** @@ -112,8 +114,8 @@ public String getID() { * @return This TextualBody */ @JsonGetter(JsonKeys.LANGUAGE) - public String getLanguage() { - return myLocale == null ? null : myLocale.toLanguageTag(); + public Optional getLanguage() { + return myLocale == null ? Optional.empty() : Optional.ofNullable(myLocale.toLanguageTag()); } /** @@ -122,8 +124,8 @@ public String getLanguage() { * @return The purpose of the textual body */ @JsonGetter(JsonKeys.PURPOSE) - public Purpose getPurpose() { - return myPurpose; + public Optional getPurpose() { + return Optional.ofNullable(myPurpose); } @Override diff --git a/src/main/java/info/freelibrary/iiif/presentation/v3/utils/json/ContextListDeserializer.java b/src/main/java/info/freelibrary/iiif/presentation/v3/utils/json/ContextListDeserializer.java new file mode 100644 index 00000000..3fce2cce --- /dev/null +++ b/src/main/java/info/freelibrary/iiif/presentation/v3/utils/json/ContextListDeserializer.java @@ -0,0 +1,66 @@ + +package info.freelibrary.iiif.presentation.v3.utils.json; + +import static info.freelibrary.iiif.presentation.v3.ContextList.PRESENTATION_CONTEXT_URI; + +import java.io.IOException; +import java.net.URI; +import java.util.List; + +import com.fasterxml.jackson.core.JsonParser; +import com.fasterxml.jackson.databind.DeserializationContext; +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.deser.std.StdDeserializer; + +import info.freelibrary.iiif.presentation.v3.ContextList; + +/** + * A custom deserializer for ContextList. Deserialization is a little different because it either deserializes from a + * single string or a list of strings, depending on list size. + */ +public class ContextListDeserializer extends StdDeserializer> { + + /** The {@code ContextListDeserializer}'s {@code serialVersionUID}. */ + private static final long serialVersionUID = 3623670131870204191L; + + /** + * Creates a new {@link ContextList} deserializer. + */ + protected ContextListDeserializer() { + this(null); + } + + /** + * Creates a new {@link ContextList} deserializer. + * + * @param aClass The class to deserialize + */ + protected ContextListDeserializer(final Class aClass) { + super(aClass); + } + + @Override + public List deserialize(final JsonParser aParser, final DeserializationContext aContext) throws IOException { + final JsonNode currentNode = aParser.getCodec().readTree(aParser); + final ContextList contexts = new ContextList(); + + if (currentNode.isArray()) { + currentNode.forEach(context -> { + final URI uri = URI.create(context.textValue()); + + if (!PRESENTATION_CONTEXT_URI.equals(uri)) { + contexts.add(uri); + } + }); + } else { + final URI uri = URI.create(currentNode.textValue()); + + if (!PRESENTATION_CONTEXT_URI.equals(uri)) { + contexts.add(uri); + } + } + + return contexts; + } + +} diff --git a/src/main/java/info/freelibrary/iiif/presentation/v3/utils/json/ContextListSerializer.java b/src/main/java/info/freelibrary/iiif/presentation/v3/utils/json/ContextListSerializer.java new file mode 100644 index 00000000..2f5c0e28 --- /dev/null +++ b/src/main/java/info/freelibrary/iiif/presentation/v3/utils/json/ContextListSerializer.java @@ -0,0 +1,53 @@ + +package info.freelibrary.iiif.presentation.v3.utils.json; + +import static info.freelibrary.util.Constants.SINGLE_INSTANCE; + +import java.io.IOException; +import java.net.URI; + +import com.fasterxml.jackson.core.JsonGenerator; +import com.fasterxml.jackson.databind.SerializerProvider; +import com.fasterxml.jackson.databind.ser.std.StdSerializer; + +import info.freelibrary.util.ThrowingConsumer; + +import info.freelibrary.iiif.presentation.v3.ContextList; + +/** + * A custom serializer for ContextList. Serialization is a little different because it either serializes as a single + * string or a list of strings, depending on list size. + */ +public class ContextListSerializer extends StdSerializer { + + /** The {@code ContextListSerializer}'s {@code serialVersionUID}. */ + private static final long serialVersionUID = 7538668057735707536L; + + /** + * Creates a new {@code ContextListSerializer}. + */ + public ContextListSerializer() { + super(ContextList.class, true); + } + + /** + * Creates a new {@code ContextListSerializer} from the supplied class. + * + * @param aClass The class to serialize + */ + public ContextListSerializer(final Class aClass) { + super(aClass, true); + } + + @Override + public void serialize(final ContextList aContextList, final JsonGenerator aJsonGenerator, + final SerializerProvider aProvider) throws IOException { + if (aContextList.size() == SINGLE_INSTANCE) { + aJsonGenerator.writeString(aContextList.get(0).toString()); + } else { + aJsonGenerator.writeStartArray(); + aContextList.stream().map(URI::toString).forEach((ThrowingConsumer) aJsonGenerator::writeString); + aJsonGenerator.writeEndArray(); + } + } +} diff --git a/src/main/resources/iiif_presentation_messages.xml b/src/main/resources/iiif_presentation_messages.xml index 2c9d5f30..68fbc439 100644 --- a/src/main/resources/iiif_presentation_messages.xml +++ b/src/main/resources/iiif_presentation_messages.xml @@ -119,4 +119,8 @@ {} is not a valid navPlace type A physical dimensions service must contain scale and units Supplied Optional was unexpectedly empty + The IIIF Presentation context URI can only exist as the first context in the list + Context '{}' was added at list position 1 because 0 is reserved for the default context + The '{}' context cannot be set as the first context; this position is reserved for the default + IIIF Presentation context diff --git a/src/test/java/info/freelibrary/iiif/presentation/v3/AbstractCanvasTest.java b/src/test/java/info/freelibrary/iiif/presentation/v3/AbstractCanvasTest.java index 17484450..06aa87f2 100644 --- a/src/test/java/info/freelibrary/iiif/presentation/v3/AbstractCanvasTest.java +++ b/src/test/java/info/freelibrary/iiif/presentation/v3/AbstractCanvasTest.java @@ -133,30 +133,6 @@ public final void testSetMinter() { assertTrue(new TestClass(id).setMinter(minter).getMinter().isPresent()); } - /** - * Tests {@link AbstractCanvas#setOtherAnnotations(AnnotationPage)}. - */ - @Test - public final void testSetOtherAnnotations() { - final Minter minter = MinterFactory.getMinter(HTTPS + UUID.randomUUID().toString()); - final AnnotationPage page = new AnnotationPage<>(minter, new Canvas(minter)); - - page.addAnnotations(new BookmarkingAnnotation(minter)); - assertEquals(1, new TestClass(minter).setOtherAnnotations(page).getOtherAnnotations().size()); - } - - /** - * Tests {@link AbstractCanvas#setOtherAnnotations(AnnotationPage)}. - */ - @Test - public final void testSetOtherAnnotationsList() { - final Minter minter = MinterFactory.getMinter(HTTPS + UUID.randomUUID().toString()); - final AnnotationPage page = new AnnotationPage<>(minter, new Canvas(minter)); - - page.addAnnotations(new BookmarkingAnnotation(minter)); - assertEquals(1, new TestClass(minter).setOtherAnnotations(List.of(page)).getOtherAnnotations().size()); - } - /** * Tests {@link AbstractCanvas#setPaintingPages()}. */ @@ -204,6 +180,30 @@ public final void testSetSupplementingPagesList() { .getSupplementingPages().size()); } + /** + * Tests {@link AbstractCanvas#setWebAnnotations(AnnotationPage)}. + */ + @Test + public final void testSetWebAnnotations() { + final Minter minter = MinterFactory.getMinter(HTTPS + UUID.randomUUID().toString()); + final AnnotationPage page = new AnnotationPage<>(minter, new Canvas(minter)); + + page.addAnnotations(new BookmarkingAnnotation(minter)); + assertEquals(1, new TestClass(minter).setWebAnnotations(page).getWebAnnotations().size()); + } + + /** + * Tests {@link AbstractCanvas#setWebAnnotations(AnnotationPage)}. + */ + @Test + public final void testSetWebAnnotationsList() { + final Minter minter = MinterFactory.getMinter(HTTPS + UUID.randomUUID().toString()); + final AnnotationPage page = new AnnotationPage<>(minter, new Canvas(minter)); + + page.addAnnotations(new BookmarkingAnnotation(minter)); + assertEquals(1, new TestClass(minter).setWebAnnotations(List.of(page)).getWebAnnotations().size()); + } + /** * A test class. */ @@ -226,11 +226,6 @@ private TestClass(final Minter aMinter) { private TestClass(final String aID) { super(aID); } - - @Override - protected Object getJsonContext() { - return null; - } } } diff --git a/src/test/java/info/freelibrary/iiif/presentation/v3/AccompanyingCanvasTest.java b/src/test/java/info/freelibrary/iiif/presentation/v3/AccompanyingCanvasTest.java index 0ad7bcd1..48a6dac9 100644 --- a/src/test/java/info/freelibrary/iiif/presentation/v3/AccompanyingCanvasTest.java +++ b/src/test/java/info/freelibrary/iiif/presentation/v3/AccompanyingCanvasTest.java @@ -1,6 +1,7 @@ package info.freelibrary.iiif.presentation.v3; +import static info.freelibrary.iiif.presentation.v3.utils.TestUtils.assertOptEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -81,7 +82,8 @@ public final void testAccompanyingCanvasMinterLabel() { final Label label = new Label(StringUtils.format(LABEL, id)); final AccompanyingCanvas canvas = new AccompanyingCanvas(minter, label); - assertEquals(StringUtils.format(LABEL, id), canvas.getLabel().getString()); + assertTrue(canvas.getLabel().isPresent()); + assertOptEquals(label, canvas.getLabel()); } /** @@ -122,7 +124,7 @@ public final void testAccompanyingCanvasURILabel() { final AccompanyingCanvas canvas = new AccompanyingCanvas(myID, label); assertEquals(myID, canvas.getID()); - assertEquals(label, canvas.getLabel()); + assertOptEquals(label, canvas.getLabel()); } /** diff --git a/src/test/java/info/freelibrary/iiif/presentation/v3/AnnotationCollectionTest.java b/src/test/java/info/freelibrary/iiif/presentation/v3/AnnotationCollectionTest.java index d1a7beb7..7254c26d 100644 --- a/src/test/java/info/freelibrary/iiif/presentation/v3/AnnotationCollectionTest.java +++ b/src/test/java/info/freelibrary/iiif/presentation/v3/AnnotationCollectionTest.java @@ -1,6 +1,7 @@ package info.freelibrary.iiif.presentation.v3; +import static info.freelibrary.iiif.presentation.v3.utils.TestUtils.assertOptEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; import static org.junit.Assert.assertTrue; @@ -159,7 +160,7 @@ public final void testGetSetLastPage() { public void testGetSetViewingDirection() { final AnnotationCollection annotationCollection = new AnnotationCollection(ID, LABEL).setViewingDirection(ViewingDirection.LEFT_TO_RIGHT); - assertEquals(ViewingDirection.LEFT_TO_RIGHT, annotationCollection.getViewingDirection()); + assertOptEquals(ViewingDirection.LEFT_TO_RIGHT, annotationCollection.getViewingDirection()); } /** diff --git a/src/test/java/info/freelibrary/iiif/presentation/v3/CanvasTest.java b/src/test/java/info/freelibrary/iiif/presentation/v3/CanvasTest.java index 537576f5..e699b1bc 100644 --- a/src/test/java/info/freelibrary/iiif/presentation/v3/CanvasTest.java +++ b/src/test/java/info/freelibrary/iiif/presentation/v3/CanvasTest.java @@ -1,6 +1,7 @@ package info.freelibrary.iiif.presentation.v3; +import static info.freelibrary.iiif.presentation.v3.utils.TestUtils.assertOptEquals; import static info.freelibrary.iiif.presentation.v3.utils.TestUtils.format; import static info.freelibrary.iiif.presentation.v3.utils.TestUtils.toJson; import static info.freelibrary.util.Constants.EMPTY; @@ -242,7 +243,7 @@ public final void testCanvasMinterLabel() { final String id = HTTPS + UUID.randomUUID().toString(); final Canvas canvas = new Canvas(MinterFactory.getMinter(id), LABEL); - assertEquals(LABEL, canvas.getLabel()); + assertOptEquals(LABEL, canvas.getLabel()); } /** @@ -264,7 +265,7 @@ public void testConstructorStringLabel() { final Canvas canvas = new Canvas(IMAGE_CANVAS_ID, LABEL); assertEquals(IMAGE_CANVAS_ID, canvas.getID()); - assertEquals(LABEL, canvas.getLabel()); + assertOptEquals(LABEL, canvas.getLabel()); } /** @@ -297,8 +298,7 @@ public final void testGetWidth() { @Test public final void testNavDate() { final NavDate navDate = NavDate.now(); - - assertEquals(navDate, myCanvas.setNavDate(navDate).getNavDate()); + assertOptEquals(navDate, myCanvas.setNavDate(navDate).getNavDate()); } /** diff --git a/src/test/java/info/freelibrary/iiif/presentation/v3/CollectionTest.java b/src/test/java/info/freelibrary/iiif/presentation/v3/CollectionTest.java index 75b12a8f..d05f3b27 100644 --- a/src/test/java/info/freelibrary/iiif/presentation/v3/CollectionTest.java +++ b/src/test/java/info/freelibrary/iiif/presentation/v3/CollectionTest.java @@ -1,6 +1,7 @@ package info.freelibrary.iiif.presentation.v3; +import static info.freelibrary.iiif.presentation.v3.utils.TestUtils.assertOptEquals; import static info.freelibrary.iiif.presentation.v3.utils.TestUtils.format; import static info.freelibrary.util.Constants.EMPTY; import static org.junit.Assert.assertEquals; @@ -143,7 +144,7 @@ public final void testCollectionItemCollection() { final Collection.Item item = new Collection.Item(collection); assertEquals(myID, item.getID()); - assertEquals(myLabel, item.getLabel()); + assertOptEquals(myLabel, item.getLabel()); assertEquals(1, item.getThumbnails().size()); } @@ -156,7 +157,7 @@ public final void testCollectionItemManifest() { final Collection.Item item = new Collection.Item(manifest); assertEquals(myID, item.getID()); - assertEquals(myLabel, item.getLabel()); + assertOptEquals(myLabel, item.getLabel()); assertEquals(1, item.getThumbnails().size()); } @@ -171,7 +172,7 @@ public final void testCollectionItemSetThumbnails() { item.setThumbnails(new ImageContent(myID)); assertEquals(myID, item.getID()); - assertEquals(myLabel, item.getLabel()); + assertOptEquals(myLabel, item.getLabel()); assertEquals(1, item.getThumbnails().size()); } @@ -183,7 +184,7 @@ public void testCollectionManifestManifestConstructor() { final Collection.Item item = new Collection.Item(new Manifest(myID, myLabel)); assertEquals(myID, item.getID()); - assertEquals(myLabel, item.getLabel()); + assertOptEquals(myLabel, item.getLabel()); } /** @@ -215,14 +216,6 @@ public void testGetCollectionNotNull() { assertEquals(0, new Collection(myID, myLabel).getItems().size()); } - /** - * Tests {@link Collection#getContext()}. - */ - @Test - public void testGetContext() { - assertEquals(Collection.PRESENTATION_CONTEXT_URI, new Collection(myID, myLabel).getContext()); - } - /** * Tests setting a navDate. */ @@ -232,7 +225,7 @@ public void testNavDate1() { final NavDate navDate = NavDate.now(); collection.setNavDate(navDate); - assertEquals(navDate, collection.getNavDate()); + assertOptEquals(navDate, collection.getNavDate()); } /** @@ -245,7 +238,7 @@ public void testNavDate2() { final NavDate navDate = new NavDate(zonedDateTime); collection.setNavDate(navDate); - assertEquals(navDate, collection.getNavDate()); + assertOptEquals(navDate, collection.getNavDate()); } /** @@ -283,8 +276,9 @@ public final void testSetDisallowedBehaviors() { public final void testSetNavPlace() { final Manifest manifest = new Manifest(myID, myLabel); final Collection.Item item = new Collection.Item(manifest); + final NavPlace navPlace = new NavPlace(myID); - assertEquals(myID, item.setNavPlace(new NavPlace(myID)).getNavPlace().getID()); + assertOptEquals(navPlace, item.setNavPlace(navPlace).getNavPlace()); } /** @@ -312,7 +306,7 @@ public final void testSetServiceDefinitionsList() { */ @Test public final void testSetViewingDirection() { - assertEquals(ViewingDirection.TOP_TO_BOTTOM, new Collection(myID, myLabel) + assertOptEquals(ViewingDirection.TOP_TO_BOTTOM, new Collection(myID, myLabel) .setViewingDirection(ViewingDirection.TOP_TO_BOTTOM).getViewingDirection()); } diff --git a/src/test/java/info/freelibrary/iiif/presentation/v3/ContextListTest.java b/src/test/java/info/freelibrary/iiif/presentation/v3/ContextListTest.java new file mode 100644 index 00000000..86770cbb --- /dev/null +++ b/src/test/java/info/freelibrary/iiif/presentation/v3/ContextListTest.java @@ -0,0 +1,484 @@ + +package info.freelibrary.iiif.presentation.v3; + +import static info.freelibrary.iiif.presentation.v3.ContextList.PRESENTATION_CONTEXT_URI; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; + +import java.io.ByteArrayOutputStream; +import java.io.PrintStream; +import java.net.URI; +import java.nio.charset.StandardCharsets; +import java.util.ArrayList; +import java.util.Arrays; +import java.util.Collection; +import java.util.Comparator; +import java.util.List; +import java.util.NoSuchElementException; +import java.util.function.Predicate; +import java.util.function.UnaryOperator; + +import org.junit.Test; + +import info.freelibrary.util.Logger; +import info.freelibrary.util.LoggerFactory; + +import info.freelibrary.iiif.presentation.v3.utils.MessageCodes; + +/** + * Tests of {@link ContextList}. + */ +public class ContextListTest extends AbstractTest { + + /** A test logger. */ + private static final Logger LOGGER = LoggerFactory.getLogger(ContextListTest.class, MessageCodes.BUNDLE); + + /** A list of test contexts. */ + private final List myContexts = Arrays.asList(URI.create(getURL()), URI.create(getURL()), URI.create(getURL()), + URI.create(getURL()), URI.create(getURL()), URI.create(getURL()), URI.create(getURL()), + URI.create(getURL()), URI.create(getURL()), URI.create(getURL()), URI.create(getURL()), + ContextList.PRESENTATION_CONTEXT_URI); + + /** + * Test method for {@link ContextList#addAll(Collection)}. + */ + @Test + public final void testAddAllCollectionOfQextendsURI() { + final ContextList contexts = new ContextList(); + + assertEquals(1, contexts.size()); + contexts.addAll(myContexts); + assertEquals(12, contexts.size()); + } + + /** + * Test method for {@link ContextList#addAll(int, Collection)}. + */ + @Test + public final void testAddAllCollectionWithDefaultURI() { + final ContextList contexts = new ContextList(); + final ContextList adds = new ContextList(); + + assertEquals(1, contexts.size()); + contexts.addAll(0, adds); + assertEquals(1, contexts.size()); + } + + /** + * Test method for {@link ContextList#addAll(int, Collection)}. + */ + @Test + public final void testAddAllCollectionWithoutDefaultURI() { + final ContextList contexts = new ContextList(); + final List list = new ArrayList<>(List.of(URI.create(getURL()), URI.create(getURL()))); + + assertEquals(1, contexts.size()); + contexts.addAll(0, list); + assertEquals(3, contexts.size()); + } + + /** + * Test method for {@link ContextList#addAll(int, Collection)}. + */ + @Test + public final void testAddAllIntCollectionOfQextendsURI() { + final ContextList contexts = new ContextList(myContexts); + final URI newURI1 = URI.create(getURL()); + final URI newURI2 = URI.create(getURL()); + final URI oldURI = contexts.get(8); + + assertEquals(12, contexts.size()); + assertEquals(oldURI, contexts.get(8)); + contexts.addAll(8, List.of(newURI1, newURI2)); + assertEquals(14, contexts.size()); + assertEquals(newURI1, contexts.get(8)); + } + + /** + * Test method for {@link ContextList#add(URI)}. + */ + @Test + public final void testAddFalse() { + final ContextList contexts = new ContextList(); + + assertEquals(1, contexts.size()); + assertFalse(contexts.add(ContextList.PRESENTATION_CONTEXT_URI)); + } + + /** + * Test method for {@link ContextList#addFirst(URI)}. + */ + @Test + public final void testAddFirstDefaultURI() { + final ContextList contexts = new ContextList(); + + assertEquals(1, contexts.size()); + contexts.addFirst(ContextList.PRESENTATION_CONTEXT_URI); + assertEquals(1, contexts.size()); + assertEquals(ContextList.PRESENTATION_CONTEXT_URI, contexts.get(0)); + } + + /** + * Test method for {@link ContextList#addFirst(URI)}. + */ + @Test + public final void testAddFirstURI() { + final ContextList contexts = new ContextList(); + final URI uri = URI.create(getURL()); + + assertEquals(1, contexts.size()); + contexts.addFirst(uri); + assertEquals(2, contexts.size()); + assertEquals(ContextList.PRESENTATION_CONTEXT_URI, contexts.get(0)); + assertEquals(uri, contexts.get(1)); + } + + /** + * Test method for {@link ContextList#add(int, URI)}. + */ + @Test + public final void testAddIntURI() { + final ContextList contexts = new ContextList(); + final URI uri = URI.create(getURL()); + + assertEquals(1, contexts.size()); + contexts.add(1, uri); + assertEquals(2, contexts.size()); + assertEquals(uri, contexts.get(1)); + assertEquals(ContextList.PRESENTATION_CONTEXT_URI, contexts.get(0)); + } + + /** + * Test method for {@link ContextList#add(int, URI)}. + */ + @Test + public final void testAddIntUriZeroIndex() { + final ContextList contexts = new ContextList(); + final URI uri = URI.create(getURL()); + + assertEquals(1, contexts.size()); + contexts.add(0, uri); + assertEquals(2, contexts.size()); + assertEquals(uri, contexts.get(1)); + assertEquals(ContextList.PRESENTATION_CONTEXT_URI, contexts.get(0)); + } + + /** + * Test method for {@link ContextList#addLast(URI)}. + */ + @Test + public final void testAddLastDefaultURI() { + final ByteArrayOutputStream out = new ByteArrayOutputStream(); + final PrintStream current = new PrintStream(out, true, StandardCharsets.UTF_8); + final PrintStream previous = System.out; + final ContextList contexts = new ContextList(); + + System.setOut(current); + + assertEquals(1, contexts.size()); + contexts.addLast(ContextList.PRESENTATION_CONTEXT_URI); + assertEquals(1, contexts.size()); + assertEquals(ContextList.PRESENTATION_CONTEXT_URI, contexts.get(0)); + + System.setOut(previous); + + assertTrue(out.toString().contains(LOGGER.getMessage(MessageCodes.JPA_149))); + } + + /** + * Test method for {@link ContextList#addLast(URI)}. + */ + @Test + public final void testAddLastURI() { + final ContextList contexts = new ContextList(); + final URI uri = URI.create(getURL()); + + assertEquals(1, contexts.size()); + contexts.addLast(uri); + assertEquals(2, contexts.size()); + assertEquals(uri, contexts.get(1)); + assertEquals(ContextList.PRESENTATION_CONTEXT_URI, contexts.get(0)); + } + + /** + * Test method for {@link ContextList#add(int, URI)}. + */ + @Test + public final void testAddPresURI() { + final ContextList contexts = new ContextList(); + + assertEquals(1, contexts.size()); + contexts.add(0, ContextList.PRESENTATION_CONTEXT_URI); + assertEquals(1, contexts.size()); + assertEquals(ContextList.PRESENTATION_CONTEXT_URI, contexts.get(0)); + } + + /** + * Test method for {@link ContextList#add(URI)}. + */ + @Test + public final void testAddURI() { + final ContextList contexts = new ContextList(); + final URI uri = URI.create(getURL()); + + assertEquals(1, contexts.size()); + contexts.add(uri); + assertEquals(2, contexts.size()); + assertEquals(uri, contexts.get(1)); + assertEquals(ContextList.PRESENTATION_CONTEXT_URI, contexts.get(0)); + } + + /** + * Test method for {@link ContextList#clear()}. + */ + @Test + public final void testClear() { + final ContextList contexts = new ContextList(myContexts); + + assertEquals(12, contexts.size()); + contexts.clear(); + assertEquals(1, contexts.size()); + } + + /** + * Test method for {@link ContextList#ContextList()}. + */ + @Test + public final void testContextList() { + final ContextList contexts = new ContextList(); + + assertEquals(1, contexts.size()); + assertEquals(ContextList.PRESENTATION_CONTEXT_URI, contexts.get(0)); + } + + /** + * Test method for {@link ContextList#ContextList(List)}. + */ + @Test + public final void testContextListListOfURI() { + final ContextList contexts = new ContextList(myContexts); + + assertEquals(12, contexts.size()); + assertEquals(ContextList.PRESENTATION_CONTEXT_URI, contexts.get(0)); + } + + /** + * Test method for {@link ContextList#equals(Object)}. + */ + @Test + public final void testEqualsNull() { + assertNotEquals(new ContextList(myContexts), null); + } + + /** + * Test method for {@link ContextList#equals(Object)}. + */ + @Test + public final void testEqualsObject() { + final ContextList contexts1 = new ContextList(myContexts); + final ContextList contexts2 = new ContextList(myContexts); + + assertEquals(contexts1, contexts2); + } + + /** + * Test method for {@link ContextList#equals(Object)}. + */ + @Test + public final void testEqualsString() { + assertNotEquals(new ContextList(myContexts), "asdf"); + } + + /** + * Test method for {@link ContextList#hashCode()}. + */ + @Test + public final void testHashCode() { + final ContextList contexts1 = new ContextList(myContexts); + final ContextList contexts2 = new ContextList(myContexts); + + assertEquals(contexts1.hashCode(), contexts2.hashCode()); + } + + /** + * Test method for {@link ContextList#removeAll(Collection)}. + */ + @Test + public final void testRemoveAllCollectionOfQ() { + final ContextList contexts = new ContextList(myContexts); + final URI uri1 = contexts.get(5); + final URI uri2 = contexts.get(8); + final URI uri3 = contexts.get(11); + final List list = List.of(uri1, uri2, uri3); + + assertEquals(12, contexts.size()); + contexts.removeAll(list); + assertEquals(9, contexts.size()); + } + + /** + * Test method for {@link ContextList#remove(Object)}. + */ + @Test + public final void testRemoveDefContextObject() { + assertFalse(new ContextList().remove(ContextList.PRESENTATION_CONTEXT_URI)); + } + + /** + * Test method for {@link ContextList#removeIf(Predicate)}. + */ + @Test + public final void testRemoveIfPredicateOfQsuperURI() { + final ContextList contexts = new ContextList(myContexts); + final URI kept = contexts.get(2); + + contexts.removeIf(uri -> !uri.equals(kept)); + assertEquals(2, contexts.size()); + assertTrue(contexts.contains(kept)); + } + + /** + * Test method for {@link ContextList#removeIf(Predicate)}. + */ + @Test + public final void testRemoveIfPredicateOfQsuperUriNoDefault() { + final ContextList contexts = new ContextList(myContexts); + + contexts.removeIf(uri -> !uri.equals(PRESENTATION_CONTEXT_URI)); + assertEquals(1, contexts.size()); + assertTrue(contexts.contains(PRESENTATION_CONTEXT_URI)); + } + + /** + * Test method for {@link ContextList#remove(int)}. + */ + @Test + public final void testRemoveInt() { + final ContextList contexts = new ContextList(myContexts); + final URI uri = contexts.get(8); + + assertEquals(12, contexts.size()); + assertTrue(contexts.contains(uri)); + contexts.remove(8); + assertEquals(11, contexts.size()); + assertFalse(contexts.contains(uri)); + } + + /** + * Test method for {@link ContextList#removeLast()}. + */ + @Test + public final void testRemoveLast() { + final ContextList contexts = new ContextList(myContexts); + final URI uri = contexts.get(contexts.size() - 1); + + assertTrue(contexts.contains(uri)); + contexts.removeLast(); + assertFalse(contexts.contains(uri)); + } + + /** + * Test method for {@link ContextList#removeLast()}. + */ + @Test(expected = NoSuchElementException.class) + public final void testRemoveLastWhenEmpty() { + new ContextList().removeLast(); + } + + /** + * Test method for {@link ContextList#remove(Object)}. + */ + @Test + public final void testRemoveObject() { + final ContextList contexts = new ContextList(myContexts); + final URI uri = contexts.get(8); + + assertTrue(contexts.contains(uri)); + contexts.remove(uri); + assertFalse(contexts.contains(uri)); + } + + /** + * Test method for {@link ContextList#remove(int)}. + */ + @Test(expected = IndexOutOfBoundsException.class) + public final void testRemoveZeroIndex() { + new ContextList().remove(0); + } + + /** + * Test method for {@link ContextList#replaceAll(UnaryOperator)}. + */ + @Test + public final void testReplaceAllUnaryOperatorOfURI() { + final ContextList contexts = new ContextList(myContexts); + final URI uri = contexts.get(10); + final UnaryOperator uOp = u -> URI.create(u.toString().replace(uri.toString(), getURL())); + + assertTrue(contexts.contains(uri)); + contexts.replaceAll(uOp); + assertFalse(contexts.contains(uri)); + } + + /** + * Test method for {@link ContextList#retainAll(Collection)}. + */ + @Test + public final void testRetainAllCollectionOfQ() { + final ContextList contexts = new ContextList(myContexts); + final URI uri1 = contexts.get(5); + final URI uri2 = contexts.get(8); + + assertEquals(12, contexts.size()); + contexts.retainAll(List.of(uri1, uri2)); + assertEquals(3, contexts.size()); + } + + /** + * Test method for {@link ContextList#set(int, URI)}. + */ + @Test + public final void testSetIntURI() { + final ContextList contexts = new ContextList(myContexts); + final URI uri = URI.create(getURL()); + + assertNotEquals(uri, contexts.get(1)); + contexts.set(1, uri); + assertEquals(uri, contexts.get(1)); + } + + /** + * Test method for {@link ContextList#set(int, URI)}. + */ + @Test(expected = IndexOutOfBoundsException.class) + public final void testSetIntURIException() { + new ContextList(myContexts).set(1, PRESENTATION_CONTEXT_URI); + } + + /** + * Test method for {@link ContextList#set(int, URI)}. + */ + @Test(expected = IndexOutOfBoundsException.class) + public final void testSetIntURIException2() { + new ContextList(myContexts).set(0, URI.create(getURL())); + } + + /** + * Test method for {@link ContextList#set(int, URI)}. + */ + @Test + public final void testSetIntUriStatusQuo() { + new ContextList(myContexts).set(0, PRESENTATION_CONTEXT_URI); + } + + /** + * Test method for {@link ContextList#sort(Comparator)}. + */ + @Test(expected = UnsupportedOperationException.class) + public final void testSortComparatorOfQsuperURI() { + new ContextList(myContexts).sort((aUriOne, aUriTwo) -> 0); + } + +} diff --git a/src/test/java/info/freelibrary/iiif/presentation/v3/ImageContentTest.java b/src/test/java/info/freelibrary/iiif/presentation/v3/ImageContentTest.java index 482f9ee3..8368dfef 100644 --- a/src/test/java/info/freelibrary/iiif/presentation/v3/ImageContentTest.java +++ b/src/test/java/info/freelibrary/iiif/presentation/v3/ImageContentTest.java @@ -1,6 +1,7 @@ package info.freelibrary.iiif.presentation.v3; +import static info.freelibrary.iiif.presentation.v3.utils.TestUtils.assertOptEquals; import static info.freelibrary.util.Constants.EMPTY; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; @@ -217,8 +218,7 @@ public void testSetHeightInt() { @Test public void testSetLabel() { final Label label = new Label("MY LABEL"); - - assertEquals(label, new ImageContent(IMAGE_URI).setLabel(label).getLabel()); + assertOptEquals(label, new ImageContent(IMAGE_URI).setLabel(label).getLabel()); } /** diff --git a/src/test/java/info/freelibrary/iiif/presentation/v3/ManifestTest.java b/src/test/java/info/freelibrary/iiif/presentation/v3/ManifestTest.java index c6be2400..8bc2ee40 100644 --- a/src/test/java/info/freelibrary/iiif/presentation/v3/ManifestTest.java +++ b/src/test/java/info/freelibrary/iiif/presentation/v3/ManifestTest.java @@ -10,10 +10,8 @@ import java.io.File; import java.io.FileReader; import java.io.IOException; -import java.net.URI; import java.util.ArrayList; import java.util.Arrays; -import java.util.Collections; import java.util.List; import java.util.UUID; import java.util.stream.Stream; @@ -86,12 +84,6 @@ public class ManifestTest extends AbstractTest { /** A test width. */ private static final int WIDTH = 6132; - /** A list of test contexts. */ - private final List myContexts = Arrays.asList(URI.create(getURL()), URI.create(getURL()), URI.create(getURL()), - URI.create(getURL()), URI.create(getURL()), URI.create(getURL()), URI.create(getURL()), - URI.create(getURL()), URI.create(getURL()), URI.create(getURL()), URI.create(getURL()), - AbstractResource.PRESENTATION_CONTEXT_URI); - /** The test manifest. */ private Manifest myManifest; @@ -110,6 +102,7 @@ public void setUp() throws IOException { final List firstCanvas = reader1.readAll(); final List secondCanvas = reader2.readAll(); final List metadata = new ArrayList<>(); + final List canvases = new ArrayList<>(); final ImageService3 manifestThumbService; reader1.close(); @@ -138,7 +131,7 @@ public void setUp() throws IOException { new AnnotationPage<>(MANIFEST_SERVER + MANIFEST_ID + "/pageanno/pageanno-2"); canvas1.getPaintingPages().add(page1.addAnnotations(content1)); - myManifest.addCanvases(canvas1); + canvases.add(canvas1); for (final String[] values : firstCanvas) { final String id = MANIFEST_SERVER + values[1] + MANIFEST_THUMBNAIL_PATH; @@ -160,7 +153,7 @@ public void setUp() throws IOException { content2 = new PaintingAnnotation(MANIFEST_SERVER + MANIFEST_ID + "/imageanno/imageanno-2", canvas2); canvas2.getPaintingPages().add(page2.addAnnotations(content2)); - myManifest.addCanvases(canvas2); + canvases.add(canvas2); for (final String[] values : secondCanvas) { final String id = MANIFEST_SERVER + values[1] + MANIFEST_THUMBNAIL_PATH; @@ -177,6 +170,7 @@ public void setUp() throws IOException { myManifest.setRights("http://creativecommons.org/licenses/by/4.0/").setBehaviors(ManifestBehavior.PAGED) .setRequiredStatement(reqStmt).setServices(otherService); + myManifest.setCanvases(canvases); } /** @@ -186,7 +180,7 @@ public void setUp() throws IOException { public void testAddRanges() { final Range range = new Range(HTTPS + UUID.randomUUID().toString()); - myManifest.addRanges(range); + myManifest.setRanges(range); assertEquals(1, myManifest.getRanges().size()); } @@ -197,57 +191,10 @@ public void testAddRanges() { public void testAddRangesList() { final Range range = new Range(HTTPS + UUID.randomUUID().toString()); - myManifest.addRanges(List.of(range)); + myManifest.setRanges(List.of(range)); assertEquals(1, myManifest.getRanges().size()); } - /** - * Tests adding a context URI. - */ - @Test - public void testAddUriContexts() { - assertEquals(1, myManifest.getContexts().size()); - myManifest.addContexts(URI.create(myLoremIpsum.getUrl()), URI.create(myLoremIpsum.getUrl())); - assertEquals(3, myManifest.getContexts().size()); - } - - /** - * Tests clearing the contexts. - */ - @Test - public void testClearContexts() { - assertEquals(1, myManifest.getContexts().size()); - myManifest.addContexts(URI.create(myLoremIpsum.getUrl()), URI.create(myLoremIpsum.getUrl())); - assertEquals(3, myManifest.getContexts().size()); - assertEquals(1, myManifest.clearContexts().getContexts().size()); - } - - /** - * Tests the comparator's sort. - */ - @Test - public final void testComparatorSort() { - final int lastIndex = myContexts.size() - 1; - final List preSort = new ArrayList<>(); - - // Shuffle until our last list item isn't the required one - while (AbstractResource.PRESENTATION_CONTEXT_URI.equals(myContexts.get(lastIndex))) { - Collections.shuffle(myContexts); - } - - // Remember the state of our list before the sort, minus the required Context - assertTrue(preSort.addAll(myContexts)); - assertTrue(preSort.remove(AbstractResource.PRESENTATION_CONTEXT_URI)); - - // Sort list items - Collections.sort(myContexts, new NavigableResource.ContextListComparator<>()); - - // Check that the last URI in the list is our required one and - // that list has same pre-sort order minus the required context - assertEquals(AbstractResource.PRESENTATION_CONTEXT_URI, myContexts.get(lastIndex)); - assertEquals(preSort, myContexts.subList(0, lastIndex)); - } - /** * Tests the manifest constructor. */ @@ -255,16 +202,8 @@ public final void testComparatorSort() { public void testConstructorStringLabel() { myManifest = new Manifest(MANIFEST_URI, new Label(METADATA_PAIRS.get(0)[1])); assertEquals(MANIFEST_URI, myManifest.getID()); - assertEquals(METADATA_PAIRS.get(0)[1], myManifest.getLabel().getString()); - } - - /** - * Tests {@link Manifest#getContext() getContext} method. - */ - @Test - public void testGetPrimaryContext() { - assertEquals(AbstractResource.PRESENTATION_CONTEXT_URI, - myManifest.addContexts(URI.create(myLoremIpsum.getUrl())).getContext()); + assertTrue(myManifest.getLabel().isPresent()); + assertEquals(METADATA_PAIRS.get(0)[1], myManifest.getLabel().get().getString()); } /** @@ -352,27 +291,6 @@ public void testParsingManifest() throws IOException { assertEquals(expected, format(found)); } - /** - * Tests {@link Manifest#removeContext(URI) removeContext} method. - */ - @Test - public void testRemoveContext() { - final URI uri = URI.create("https://asdf.example.com"); - - myManifest.addContexts(uri, URI.create("https://fdsa.example.com")); - assertTrue(myManifest.getContexts().contains(uri)); - assertTrue(myManifest.removeContext(uri)); - assertEquals(2, myManifest.getContexts().size()); - } - - /** - * Tests getting an exception on trying to remove the required context. - */ - @Test(expected = UnsupportedOperationException.class) - public void testRemovePrimaryContext() { - myManifest.removeContext(AbstractResource.PRESENTATION_CONTEXT_URI); - } - /** * Tests setting annotations. */ diff --git a/src/test/java/info/freelibrary/iiif/presentation/v3/NavigableResourceTest.java b/src/test/java/info/freelibrary/iiif/presentation/v3/NavigableResourceTest.java index d7733e17..6453d402 100644 --- a/src/test/java/info/freelibrary/iiif/presentation/v3/NavigableResourceTest.java +++ b/src/test/java/info/freelibrary/iiif/presentation/v3/NavigableResourceTest.java @@ -5,6 +5,9 @@ import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; +import java.net.URI; +import java.util.ArrayList; +import java.util.List; import java.util.UUID; import org.junit.Test; @@ -92,6 +95,54 @@ public final void testNavigableResourceEqualsString() { assertNotEquals(new TestClass(HTTPS + UUID.randomUUID().toString()), EMPTY); } + /** + * Tests {@link NavigableResource#getContextList() NavigableResource}. + */ + @Test + public final void testNavigableResourceGetContextList() { + final String id = UUID.randomUUID().toString(); + final NavigableResource test = new TestClass(HTTPS + id); + + assertEquals(1, test.getContextList().size()); // Uninitialized + assertEquals(1, test.getContextList().size()); // Should now be initialized + } + + /** + * Tests {@link NavigableResource#getContexts() NavigableResource}. + */ + @Test + public final void testNavigableResourceGetContexts() { + final String id = UUID.randomUUID().toString(); + final NavigableResource test = new TestClass(HTTPS + id); + + assertEquals(1, test.getContexts().size()); + } + + /** + * Tests {@link NavigableResource#setContexts(List) NavigableResource}. + */ + @Test + public final void testNavigableResourceSetContextsWithContextList() { + final String id = UUID.randomUUID().toString(); + final NavigableResource test = new TestClass(HTTPS + id); + final ContextList contexts = new ContextList(); + + assertEquals(contexts, test.setContexts(contexts).getContexts()); + } + + /** + * Tests {@link NavigableResource#setContexts(List) NavigableResource}. + */ + @Test + public final void testNavigableResourceSetContextsWithURIList() { + final String id = UUID.randomUUID().toString(); + final NavigableResource test = new TestClass(HTTPS + id); + final List contexts = new ArrayList<>(); + + contexts.add(URI.create(id)); + assertEquals(2, test.setContexts(contexts).getContexts().size()); + } + /** * A test class. */ diff --git a/src/test/java/info/freelibrary/iiif/presentation/v3/PlaceholderCanvasTest.java b/src/test/java/info/freelibrary/iiif/presentation/v3/PlaceholderCanvasTest.java index 7891d319..c20a25e0 100644 --- a/src/test/java/info/freelibrary/iiif/presentation/v3/PlaceholderCanvasTest.java +++ b/src/test/java/info/freelibrary/iiif/presentation/v3/PlaceholderCanvasTest.java @@ -1,6 +1,7 @@ package info.freelibrary.iiif.presentation.v3; +import static info.freelibrary.iiif.presentation.v3.utils.TestUtils.assertOptEquals; import static info.freelibrary.iiif.presentation.v3.utils.TestUtils.format; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertTrue; @@ -283,7 +284,7 @@ public final void testPlaceholderCanvasURILabel() { final PlaceholderCanvas canvas = new PlaceholderCanvas(myID, label); assertEquals(myID, canvas.getID()); - assertEquals(label, canvas.getLabel()); + assertOptEquals(label, canvas.getLabel()); } /** diff --git a/src/test/java/info/freelibrary/iiif/presentation/v3/RangeTest.java b/src/test/java/info/freelibrary/iiif/presentation/v3/RangeTest.java index 0d006b5e..c82ce4e7 100644 --- a/src/test/java/info/freelibrary/iiif/presentation/v3/RangeTest.java +++ b/src/test/java/info/freelibrary/iiif/presentation/v3/RangeTest.java @@ -1,6 +1,7 @@ package info.freelibrary.iiif.presentation.v3; +import static info.freelibrary.iiif.presentation.v3.utils.TestUtils.assertOptEquals; import static info.freelibrary.iiif.presentation.v3.utils.TestUtils.format; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; @@ -158,7 +159,7 @@ public void testGetSetSupplementaryAnnotations() throws JsonProcessingException @Test public void testGetSetViewingDirection() { final Range range = getRange().setViewingDirection(ViewingDirection.LEFT_TO_RIGHT); - assertEquals(ViewingDirection.LEFT_TO_RIGHT, range.getViewingDirection()); + assertOptEquals(ViewingDirection.LEFT_TO_RIGHT, range.getViewingDirection()); } /** @@ -175,7 +176,7 @@ public void testGetStart() { @Test public final void testNavDate() { final NavDate navDate = NavDate.now(); - assertEquals(navDate, getRange().setNavDate(navDate).getNavDate()); + assertOptEquals(navDate, getRange().setNavDate(navDate).getNavDate()); } /** diff --git a/src/test/java/info/freelibrary/iiif/presentation/v3/TextualBodyTest.java b/src/test/java/info/freelibrary/iiif/presentation/v3/TextualBodyTest.java index 69996639..e02dff0d 100644 --- a/src/test/java/info/freelibrary/iiif/presentation/v3/TextualBodyTest.java +++ b/src/test/java/info/freelibrary/iiif/presentation/v3/TextualBodyTest.java @@ -1,6 +1,8 @@ package info.freelibrary.iiif.presentation.v3; +import static info.freelibrary.iiif.presentation.v3.utils.TestUtils.assertOptEquals; +import static info.freelibrary.util.Constants.EMPTY; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotEquals; @@ -61,7 +63,7 @@ public final void testSerializedID() { @Test public final void testSetGetLanguage() { final String language = "fr"; - assertEquals(language, new TextualBody().setLanguage(language).getLanguage()); + assertOptEquals(language, new TextualBody().setLanguage(language).getLanguage()); } /** @@ -78,7 +80,7 @@ public final void testSetGetValue() { */ @Test public final void testTextualBody() { - assertEquals(null, new TextualBody().getID()); + assertEquals(EMPTY, new TextualBody().getID()); } /** @@ -110,6 +112,6 @@ public final void testToString() throws IOException { @Test public final void testUnserializeID() { final TextualBody textualBody = new TextualBody(SkolemIriFactory.getFactory()).serializeID(false); - assertEquals(null, textualBody.getID()); + assertEquals(EMPTY, textualBody.getID()); } } diff --git a/src/test/java/info/freelibrary/iiif/presentation/v3/examples/CookbooksTest.java b/src/test/java/info/freelibrary/iiif/presentation/v3/examples/CookbooksTest.java index 144a6e8c..fded4baf 100644 --- a/src/test/java/info/freelibrary/iiif/presentation/v3/examples/CookbooksTest.java +++ b/src/test/java/info/freelibrary/iiif/presentation/v3/examples/CookbooksTest.java @@ -301,7 +301,7 @@ public final void test0005WithMinter() throws IOException { imageContent.setWidthHeight(4032, 3024).setFormat(IMAGE_JPEG).setServices(service); canvas.setWidthHeight(4032, 3024).paintWith(imageContent); - manifest.addCanvases(canvas); + manifest.setCanvases(canvas); System.out.println(manifest); @@ -376,7 +376,7 @@ public final void test0006WithMinter() throws IOException { manifest.setRequiredStatement(new RequiredStatement(reqStmtLabel, reqStmt)); imageContent.setWidthHeight(1114, 991).setFormat(IMAGE_JPEG).setServices(service); - manifest.addCanvases(canvas.setWidthHeight(1114, 991).paintWith(imageContent)); + manifest.setCanvases(canvas.setWidthHeight(1114, 991).paintWith(imageContent)); System.out.println(manifest); @@ -421,7 +421,7 @@ public final void test0006WithMinterAndMatrix() throws IOException { manifest.setRequiredStatement(reqStatement); imageContent.setWidthHeight(1114, 991).setFormat(IMAGE_JPEG).setServices(service); - manifest.addCanvases(canvas.setWidthHeight(1114, 991).paintWith(imageContent)); + manifest.setCanvases(canvas.setWidthHeight(1114, 991).paintWith(imageContent)); System.out.println(manifest); @@ -470,7 +470,7 @@ public final void test0006WithoutMinter() throws IOException { imageContent.setWidthHeight(1114, 991).setFormat(IMAGE_JPEG).setServices(service); page.addAnnotations(annotation.setBody(imageContent).setTarget(new Target(canvas))); - manifest.addCanvases(canvas.setWidthHeight(1114, 991).setPaintingPages(page)); + manifest.setCanvases(canvas.setWidthHeight(1114, 991).setPaintingPages(page)); System.out.println(manifest); @@ -503,7 +503,7 @@ public final void test0007WithMinter() throws IOException { "Glen Robson, IIIF Technical Coordinator. CC BY-SA 3.0 "))); imageContent.setWidthHeight(4032, 3024).setFormat(IMAGE_JPEG).setServices(service); - manifest.addCanvases(canvas.setWidthHeight(4032, 3024).paintWith(imageContent)); + manifest.setCanvases(canvas.setWidthHeight(4032, 3024).paintWith(imageContent)); System.out.println(manifest); @@ -540,7 +540,7 @@ public final void test0007WithoutMinter() throws IOException { imageContent.setWidthHeight(4032, 3024).setFormat(IMAGE_JPEG).setServices(service); page.addAnnotations(annotation.setBody(imageContent).setTarget(new Target(canvas))); - manifest.addCanvases(canvas.setWidthHeight(4032, 3024).setPaintingPages(page)); + manifest.setCanvases(canvas.setWidthHeight(4032, 3024).setPaintingPages(page)); System.out.println(manifest); @@ -571,7 +571,7 @@ public final void test0008WithMinter() throws IOException { "Glen Robson, IIIF Technical Coordinator. CC BY-SA 3.0 "))); imageContent.setWidthHeight(4032, 3024).setFormat(IMAGE_JPEG).setServices(service); - manifest.addCanvases(canvas.setWidthHeight(4032, 3024).paintWith(imageContent)); + manifest.setCanvases(canvas.setWidthHeight(4032, 3024).paintWith(imageContent)); System.out.println(manifest); @@ -606,7 +606,7 @@ public final void test0008WithoutMinter() throws IOException { imageContent.setWidthHeight(4032, 3024).setFormat(IMAGE_JPEG).setServices(service); page.addAnnotations(annotation.setBody(imageContent).setTarget(new Target(canvas))); - manifest.addCanvases(canvas.setWidthHeight(4032, 3024).setPaintingPages(page)); + manifest.setCanvases(canvas.setWidthHeight(4032, 3024).setPaintingPages(page)); System.out.println(manifest); @@ -676,7 +676,7 @@ public final void test0009WithMinter() throws IOException { imageContent5.setWidthHeight(3198, 4632).setFormat(IMAGE_JPEG).setServices(service5); canvas5.setWidthHeight(3198, 4632).paintWith(imageContent5); - manifest.addCanvases(canvas1, canvas2, canvas3, canvas4, canvas5); + manifest.setCanvases(canvas1, canvas2, canvas3, canvas4, canvas5); System.out.println(manifest); @@ -730,7 +730,7 @@ public final void test0009WithMinterLooped() throws IOException { }); manifest.setBehaviors(PAGED); - manifest.addCanvases(canvases); + manifest.setCanvases(canvases); System.out.println(manifest); @@ -790,7 +790,7 @@ public final void test0009WithoutMinterLooped() throws IOException { } manifest.setBehaviors(PAGED); - manifest.addCanvases(canvases); + manifest.setCanvases(canvases); System.out.println(manifest); @@ -847,7 +847,7 @@ public final void test0010WithMinterLoopedRTL() throws IOException { manifest.setSummary(new Summary("en", "Playbill for \"Akiba gongen kaisen-banashi,\" \"Futatsu chōchō kuruwa nikki\" and \"Godairiki koi no fūjime\" performed at the Chikugo Theater in Osaka from the fifth month of Kaei 2 (May, 1849); main actors: Gadō Kataoka II, Ebizō Ichikawa VI, Kitō Sawamura II, Daigorō Mimasu IV and Karoku Nakamura I; on front cover: producer Mominosuke Ichikawa's crest.")); manifest.setViewingDirection(RIGHT_TO_LEFT); - manifest.addCanvases(canvases); + manifest.setCanvases(canvases); System.out.println(manifest); @@ -899,7 +899,7 @@ public final void test0010WithMinterLoopedTTB() throws IOException { manifest.setSummary(new Summary("en", "William Lewis Sachtleben was an American long-distance cyclist who rode across Asia from Istanbul to Peking in 1891 to 1892 with Thomas Gaskell Allen Jr., his classmate from Washington University. This was part of a longer journey that began the day after they had graduated from college, when they travelled to New York and on to Liverpool; in all they travelled 15,044 miles by bicycle, 'the longest continuous land journey ever made around the world' as reported in their book Across Asia on a bicycle (1895). Sachtleben documented his travels with photographs and diaries, the latter of which he numbered sequentially. The diary of notebook 'No. 10' covers a portion of their journey through the Armenian area of Turkey from April 12 to May 9 (there is a 2-page reading list at the end). During this time they rode from Ankara (Angora in the diary) to Sivas, where they stayed for ten days while Allen had a bout of typhoid fever, and the first half of a ten-day excursion to Merzifon (Mersovan in the diary), taken by Sachtleben to give Allen additional time to recover.")); manifest.setViewingDirection(TOP_TO_BOTTOM); - manifest.addCanvases(canvases); + manifest.setCanvases(canvases); System.out.println(manifest); @@ -972,7 +972,7 @@ public final void test0010WithMinterRTL() throws IOException { imageContent5.setWidthHeight(3510, 4808).setFormat(IMAGE_JPEG).setServices(service5); canvas5.setWidthHeight(3510, 4808).paintWith(imageContent5); - manifest.addCanvases(canvas1, canvas2, canvas3, canvas4, canvas5); + manifest.setCanvases(canvas1, canvas2, canvas3, canvas4, canvas5); System.out.println(manifest); @@ -1035,7 +1035,7 @@ public final void test0010WithMinterTTB() throws IOException { imageContent4.setWidthHeight(2268, 3135).setFormat(IMAGE_JPEG).setServices(service4); canvas4.setWidthHeight(2268, 3135).paintWith(imageContent4); - manifest.addCanvases(canvas1, canvas2, canvas3, canvas4); + manifest.setCanvases(canvas1, canvas2, canvas3, canvas4); System.out.println(manifest); @@ -1101,7 +1101,7 @@ public final void test0010WithoutMinterLoopedRTL() throws IOException { manifest.setSummary(new Summary("en", "Playbill for \"Akiba gongen kaisen-banashi,\" \"Futatsu chōchō kuruwa nikki\" and \"Godairiki koi no fūjime\" performed at the Chikugo Theater in Osaka from the fifth month of Kaei 2 (May, 1849); main actors: Gadō Kataoka II, Ebizō Ichikawa VI, Kitō Sawamura II, Daigorō Mimasu IV and Karoku Nakamura I; on front cover: producer Mominosuke Ichikawa's crest.")); manifest.setViewingDirection(RIGHT_TO_LEFT); - manifest.addCanvases(canvases); + manifest.setCanvases(canvases); System.out.println(manifest); @@ -1162,7 +1162,7 @@ public final void test0010WithoutMinterLoopedTTB() throws IOException { manifest.setSummary(new Summary("en", "William Lewis Sachtleben was an American long-distance cyclist who rode across Asia from Istanbul to Peking in 1891 to 1892 with Thomas Gaskell Allen Jr., his classmate from Washington University. This was part of a longer journey that began the day after they had graduated from college, when they travelled to New York and on to Liverpool; in all they travelled 15,044 miles by bicycle, 'the longest continuous land journey ever made around the world' as reported in their book Across Asia on a bicycle (1895). Sachtleben documented his travels with photographs and diaries, the latter of which he numbered sequentially. The diary of notebook 'No. 10' covers a portion of their journey through the Armenian area of Turkey from April 12 to May 9 (there is a 2-page reading list at the end). During this time they rode from Ankara (Angora in the diary) to Sivas, where they stayed for ten days while Allen had a bout of typhoid fever, and the first half of a ten-day excursion to Merzifon (Mersovan in the diary), taken by Sachtleben to give Allen additional time to recover.")); manifest.setViewingDirection(TOP_TO_BOTTOM); - manifest.addCanvases(canvases); + manifest.setCanvases(canvases); System.out.println(manifest); diff --git a/src/test/java/info/freelibrary/iiif/presentation/v3/ids/DefaultMinterTest.java b/src/test/java/info/freelibrary/iiif/presentation/v3/ids/DefaultMinterTest.java index 27704e0c..a760e9f0 100644 --- a/src/test/java/info/freelibrary/iiif/presentation/v3/ids/DefaultMinterTest.java +++ b/src/test/java/info/freelibrary/iiif/presentation/v3/ids/DefaultMinterTest.java @@ -135,7 +135,7 @@ public final void testIteratorHasNext() { public final void testManifestConstructor() { final String id = myManifestID + "/canvas-kfb9"; final Manifest manifest = new Manifest(myManifestID, new Label("Label")); - final Minter minter = MinterFactory.getMinter(manifest.addCanvases(new Canvas(id))); + final Minter minter = MinterFactory.getMinter(manifest.setCanvases(new Canvas(id))); int counter = 0; diff --git a/src/test/java/info/freelibrary/iiif/presentation/v3/ids/SkolemIriFactoryTest.java b/src/test/java/info/freelibrary/iiif/presentation/v3/ids/SkolemIriFactoryTest.java index da8ac363..fd4c8ba1 100644 --- a/src/test/java/info/freelibrary/iiif/presentation/v3/ids/SkolemIriFactoryTest.java +++ b/src/test/java/info/freelibrary/iiif/presentation/v3/ids/SkolemIriFactoryTest.java @@ -1,6 +1,7 @@ package info.freelibrary.iiif.presentation.v3.ids; +import static info.freelibrary.util.Constants.EMPTY; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertNotEquals; @@ -68,7 +69,7 @@ public final void testGetSkolemIRI() { */ @Test public final void testHasNonSerializableIDs() { - assertEquals(null, new TextualBody(SkolemIriFactory.getFactory().createSerializableIDs(false)).getID()); + assertEquals(EMPTY, new TextualBody(SkolemIriFactory.getFactory().createSerializableIDs(false)).getID()); } /** @@ -76,7 +77,7 @@ public final void testHasNonSerializableIDs() { */ @Test public final void testHasNonSerializableIDsDefault() { - assertEquals(null, + assertEquals(EMPTY, new TextualBody(SkolemIriFactory.getFactory().createSerializableIDs(false).setWellKnownBase(null)) .getID()); } @@ -86,7 +87,7 @@ public final void testHasNonSerializableIDsDefault() { */ @Test public final void testHasSerializableIDs() { - assertNotEquals(null, new TextualBody(SkolemIriFactory.getFactory().createSerializableIDs(true)).getID()); + assertNotEquals(EMPTY, new TextualBody(SkolemIriFactory.getFactory().createSerializableIDs(true)).getID()); } /**