Skip to content

Commit

Permalink
Update tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ksclarke committed Aug 2, 2024
1 parent 84035e8 commit 4301faa
Show file tree
Hide file tree
Showing 29 changed files with 1,193 additions and 79 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,23 +4,18 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;

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.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonSetter;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ser.impl.SimpleBeanPropertyFilter;
import com.fasterxml.jackson.databind.ser.impl.SimpleFilterProvider;
import com.fasterxml.jackson.databind.type.TypeFactory;

import info.freelibrary.util.Constants;
Expand All @@ -44,7 +39,6 @@
import info.freelibrary.iiif.presentation.v3.utils.JSON;
import info.freelibrary.iiif.presentation.v3.utils.JsonKeys;
import info.freelibrary.iiif.presentation.v3.utils.MessageCodes;
import info.freelibrary.iiif.presentation.v3.utils.json.JsonParsingException;

/**
* A virtual container that represents a page or view and has content resources associated with it or with parts of it.
Expand All @@ -68,9 +62,6 @@ abstract class AbstractCanvas<T extends AbstractCanvas<T>> extends NavigableReso
/** A temporal constant. */
private static final String TEMPORAL = "temporal";

/** A Jackson serialization filter name for width and height. */
private static final String WIDTH_HEIGHT_FILTER = "JPv3WidthHeightFilter";

/** A zero (non-existent) duration. */
private static final float ZERO_DURATION = 0.0f;

Expand Down Expand Up @@ -142,6 +133,27 @@ protected AbstractCanvas(final String aID, final Label aLabel) {
super(ResourceTypes.CANVAS, aID, aLabel, CanvasBehavior.class);
}

@Override
public boolean equals(final Object aObject) {
if (this == aObject) {
return true;
}

if (aObject == null || getClass() != aObject.getClass()) {
return false;
}

if (aObject instanceof final AbstractCanvas<?> other) {
return Objects.equals(myDuration, other.myDuration) && Objects.equals(myHeight, other.myHeight) &&
Objects.equals(myWidth, other.myWidth) &&
Objects.equals(myOtherAnnotations, other.myOtherAnnotations) &&
Objects.equals(myPaintingPageList, other.myPaintingPageList) &&
Objects.equals(mySupplementingPageList, other.mySupplementingPageList) && super.equals(other);
}

return false;
}

/**
* Gets the duration of the canvas.
*
Expand Down Expand Up @@ -228,6 +240,12 @@ public int getWidth() {
return myWidth;
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), myDuration, myHeight, myWidth, myOtherAnnotations, myPaintingPageList,
mySupplementingPageList);
}

/**
* Sets the canvas' behaviors.
*
Expand Down Expand Up @@ -411,37 +429,6 @@ public T setWidthHeight(final int aWidth, final int aHeight) {
return (T) this;
}

/**
* Converts the canvas to its string/JSON representation.
*
* @return A string representation of the canvas
*/
@Override
public String toString() {
final SimpleFilterProvider filterProvider = new SimpleFilterProvider();
final Set<String> filtered = new HashSet<>();

// Don't write duration if it's zero
if (myDuration == ZERO_DURATION) {
filtered.add(JsonKeys.DURATION);
}

// Don't write width and height if they're both zero
if (myHeight == 0 && myWidth == 0) {
filtered.add(JsonKeys.HEIGHT);
filtered.add(JsonKeys.WIDTH);
}

// These are the things we filter when we serialize to JSON
filterProvider.addFilter(WIDTH_HEIGHT_FILTER, SimpleBeanPropertyFilter.serializeAllExcept(filtered));

try {
return JSON.getWriter(filterProvider).writeValueAsString(this);
} catch (final JsonProcessingException details) {
throw new JsonParsingException(details);
}
}

/**
* 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)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonSetter;

import info.freelibrary.util.ListUtils;
import info.freelibrary.util.Logger;
import info.freelibrary.util.LoggerFactory;
import info.freelibrary.util.warnings.JDK;
Expand Down Expand Up @@ -129,6 +130,26 @@ public boolean bodyHasChoice() {
return myBodyHasChoice;
}

@Override
public boolean equals(final Object aObject) {
if (this == aObject) {
return true;
}

if (aObject == null || getClass() != aObject.getClass()) {
return false;
}

if (aObject instanceof final AbstractCanvasAnnotation<?> other) {
return Objects.equals(myBodyHasChoice, other.myBodyHasChoice) &&
Objects.equals(myMotivation, other.myMotivation) &&
ListUtils.equals(myResources, other.myResources) && Objects.equals(myTarget, other.myTarget) &&
Objects.equals(myTimeMode, other.myTimeMode) && super.equals(other);
}

return false;
}

/**
* Gets the content resources associated with this annotation.
*
Expand Down Expand Up @@ -171,6 +192,11 @@ public Optional<TimeMode> getTimeMode() {
return Optional.ofNullable(myTimeMode);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), myBodyHasChoice, myMotivation, myResources, myTarget, myTimeMode);
}

/**
* Sets the annotation resource's behaviors. The supplied behaviors are checked for compatibility with the resource.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;

import info.freelibrary.util.ListUtils;
import info.freelibrary.util.warnings.JDK;

import info.freelibrary.iiif.presentation.v3.annotations.WebAnnotation;
Expand Down Expand Up @@ -73,6 +74,24 @@ protected AbstractContentResource(final String aType, final String aID,
: MediaType.parse(aID).orElse(null);
}

@Override
public boolean equals(final Object aObject) {
if (this == aObject) {
return true;
}

if (aObject == null || getClass() != aObject.getClass()) {
return false;
}

if (aObject instanceof final AbstractContentResource<?> other) {
return Objects.equals(myFormat, other.myFormat) && ListUtils.equals(myAnnotations, other.myAnnotations) &&
ListUtils.equals(myLanguages, other.myLanguages) && super.equals(other);
}

return false;
}

/**
* Gets the content resource's annotations.
*
Expand Down Expand Up @@ -113,6 +132,11 @@ public List<String> getLanguages() {
return myLanguages;
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), myFormat, myAnnotations, myLanguages);
}

/**
* Sets the content resource's annotation pages from an array.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import com.fasterxml.jackson.databind.annotation.JsonDeserialize;

import info.freelibrary.util.I18nRuntimeException;
import info.freelibrary.util.ListUtils;
import info.freelibrary.util.Logger;
import info.freelibrary.util.LoggerFactory;
import info.freelibrary.util.warnings.JDK;
Expand Down Expand Up @@ -154,6 +155,32 @@ protected AbstractResource(final String aType, final String aID, final Label aLa
myLabel = Objects.requireNonNull(aLabel);
}

@Override
public boolean equals(final Object aObject) {
if (this == aObject) {
return true;
}

if (aObject == null || getClass() != aObject.getClass()) {
return false;
}

if (aObject instanceof final AbstractResource<?> other) {
return Objects.equals(myType, other.myType) && Objects.equals(myBehaviorClass, other.myBehaviorClass) &&
ListUtils.equals(myBehaviors, other.myBehaviors) &&
ListUtils.equals(myHomepages, other.myHomepages) && Objects.equals(myID, other.myID) &&
Objects.equals(myLabel, other.myLabel) && ListUtils.equals(myMetadata, other.myMetadata) &&
ListUtils.equals(myPartOfs, other.myPartOfs) && ListUtils.equals(myProviders, other.myProviders) &&
ListUtils.equals(myRenderings, other.myRenderings) &&
Objects.equals(myRequiredStatement, other.myRequiredStatement) &&
Objects.equals(myRights, other.myRights) && Objects.equals(mySeeAlsoRefs, other.mySeeAlsoRefs) &&
ListUtils.equals(myServices, other.myServices) && Objects.equals(mySummary, other.mySummary) &&
ListUtils.equals(myThumbnails, other.myThumbnails);
}

return false;
}

/**
* Gets the resource's behaviors.
*
Expand Down Expand Up @@ -347,6 +374,13 @@ public String getType() {
return myType;
}

@Override
public int hashCode() {
return Objects.hash(myType, myBehaviorClass, myBehaviors, myHomepages, myID, myLabel, myMetadata, myPartOfs,
myProviders, myRenderings, myRequiredStatement, myRights, mySeeAlsoRefs, myServices, mySummary,
myThumbnails);
}

@Override
@JsonIgnore
public T setBehaviors(final Behavior... aBehaviorArray) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package info.freelibrary.iiif.presentation.v3;

import java.util.List;
import java.util.Objects;
import java.util.Optional;

import com.fasterxml.jackson.annotation.JsonGetter;
Expand Down Expand Up @@ -44,6 +45,25 @@ public AnnotationCollection(final String aID, final Label aLabel) {
super(ResourceTypes.ANNOTATION_COLLECTION, aID, aLabel, ResourceBehavior.class);
}

@Override
public boolean equals(final Object aObject) {
if (this == aObject) {
return true;
}

if (aObject == null || getClass() != aObject.getClass()) {
return false;
}

if (aObject instanceof final AnnotationCollection other) {
return Objects.equals(myFirstAnnotationPage, other.myFirstAnnotationPage) &&
Objects.equals(myLastAnnotationPage, other.myLastAnnotationPage) &&
Objects.equals(myViewingDirection, other.myViewingDirection);
}

return false;
}

/**
* Gets the collection's first annotation page.
*
Expand Down Expand Up @@ -76,6 +96,11 @@ public ViewingDirection getViewingDirection() {
return myViewingDirection;
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), myFirstAnnotationPage, myLastAnnotationPage, this.myViewingDirection);
}

@Override
@JsonIgnore
public AnnotationCollection setBehaviors(final Behavior... aBehaviorArray) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,24 @@ public final AnnotationPage<A> addAnnotations(final List<A> aAnnotationList) {
return this;
}

@Override
public boolean equals(final Object aObject) {
if (this == aObject) {
return true;
}

if (aObject == null || getClass() != aObject.getClass()) {
return false;
}

if (aObject instanceof final AnnotationPage<?> other) {
return Objects.equals(myAnnotations, other.myAnnotations) &&
Objects.equals(myNextAnnotationPage, other.myNextAnnotationPage) && super.equals(other);
}

return false;
}

/**
* Gets the annotation page's annotations.
*
Expand Down Expand Up @@ -140,6 +158,11 @@ public <T extends Annotation<T>> Optional<AnnotationPage<T>> getNextPage() {
return Optional.ofNullable((AnnotationPage<T>) myNextAnnotationPage);
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), myAnnotations, myNextAnnotationPage);
}

/**
* Removes the external context from an annotation page so that it can be used inside a manifest.
*
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/info/freelibrary/iiif/presentation/v3/Canvas.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
package info.freelibrary.iiif.presentation.v3;

import java.util.List;
import java.util.Objects;
import java.util.Optional;

import com.fasterxml.jackson.annotation.JsonGetter;
Expand Down Expand Up @@ -77,6 +78,24 @@ private Canvas() {
super();
}

@Override
public boolean equals(final Object aObject) {
if (this == aObject) {
return true;
}

if (aObject == null || getClass() != aObject.getClass()) {
return false;
}

if (aObject instanceof final Canvas other) {
return Objects.equals(myAccompanyingCanvas, other.myAccompanyingCanvas) &&
Objects.equals(myPlaceholderCanvas, other.myPlaceholderCanvas) && super.equals(other);
}

return false;
}

/**
* Gets canvas' accompanying canvas.
*
Expand Down Expand Up @@ -108,6 +127,11 @@ public Optional<PlaceholderCanvas> getPlaceholderCanvas() {
return myPlaceholderCanvas;
}

@Override
public int hashCode() {
return Objects.hash(super.hashCode(), myPlaceholderCanvas, myAccompanyingCanvas);
}

@Override
public final Canvas paintWith(final boolean aChoice, final ContentResource... aContentArray) {
return super.paint(this, aChoice, aContentArray);
Expand Down
Loading

0 comments on commit 4301faa

Please sign in to comment.