Skip to content

Commit

Permalink
[WIP] Add more tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ksclarke committed Jul 20, 2024
1 parent 64212b4 commit a490f2d
Show file tree
Hide file tree
Showing 4 changed files with 582 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

import info.freelibrary.util.Logger;
import info.freelibrary.util.LoggerFactory;
import info.freelibrary.util.StringUtils;
import info.freelibrary.util.warnings.JDK;
import info.freelibrary.util.warnings.PMD;
import info.freelibrary.util.warnings.Sonar;
Expand Down Expand Up @@ -281,7 +282,14 @@ private Service deserializeServiceNode(final JsonParser aParser, final JsonNode
final Optional<String> id = getServiceID(aNode);

if (profileNode != null) {
final Optional<Service.Profile> optProfile = Service.Profile.fromLabel(profileNode.asText());
final Optional<Service.Profile> optProfile;

if (profileNode.isArray()) {
// Spec: "The first entry in the list must be a compliance level URI"
optProfile = Service.Profile.fromLabel(profileNode.get(0).asText());
} else {
optProfile = Service.Profile.fromLabel(profileNode.asText());
}

if (optProfile.isPresent()) {
final Service.Profile serviceProfile = optProfile.get();
Expand Down Expand Up @@ -491,7 +499,7 @@ private Optional<String> getServiceID(final JsonNode aNode) {
*/
private Optional<String> getValue(final JsonNode aNode) {
if (aNode != null) {
return Optional.ofNullable(aNode.asText(null));
return Optional.ofNullable(StringUtils.trimToNull(aNode.asText(null)));
}

return Optional.empty();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

package info.freelibrary.iiif.presentation.v3.services;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
Expand All @@ -9,7 +10,6 @@
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonInclude;
import com.fasterxml.jackson.annotation.JsonInclude.Include;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
import com.fasterxml.jackson.annotation.JsonSetter;

Expand All @@ -32,7 +32,6 @@
abstract class AbstractImageService<T extends AbstractImageService<T>> extends AbstractService<T> {

/** The image service's formats. */
@JsonProperty(ImageAPI.EXTRA_FORMATS)
private List<Format> myFormats;

/** My height. */
Expand All @@ -42,15 +41,12 @@ abstract class AbstractImageService<T extends AbstractImageService<T>> extends A
private boolean myProtocolIsSet;

/** The image service's qualities. */
@JsonProperty(ImageAPI.EXTRA_QUALITIES)
private List<Quality> myQualities;

/** The image service's sizes. */
@JsonProperty(ImageAPI.SIZES)
private List<Size> mySizes;

/** The image service's tiles. */
@JsonProperty(ImageAPI.TILES)
private List<Tile> myTiles;

/** My width. */
Expand Down Expand Up @@ -81,6 +77,10 @@ protected AbstractImageService(final String aID, final String aType, final Image
*/
@JsonGetter(ImageAPI.EXTRA_FORMATS)
public List<Format> getExtraFormats() {
if (myFormats == null) {
myFormats = new ArrayList<>();
}

return myFormats;
}

Expand All @@ -91,6 +91,10 @@ public List<Format> getExtraFormats() {
*/
@JsonGetter(ImageAPI.EXTRA_QUALITIES)
public List<Quality> getExtraQualities() {
if (myQualities == null) {
myQualities = new ArrayList<>();
}

return myQualities;
}

Expand Down Expand Up @@ -122,6 +126,10 @@ public Optional<String> getProtocol() {
*/
@JsonGetter(ImageAPI.SIZES)
public List<Size> getSizes() {
if (mySizes == null) {
mySizes = new ArrayList<>();
}

return mySizes;
}

Expand All @@ -132,6 +140,10 @@ public List<Size> getSizes() {
*/
@JsonGetter(ImageAPI.TILES)
public List<Tile> getTiles() {
if (myTiles == null) {
myTiles = new ArrayList<>();
}

return myTiles;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
import java.util.Objects;
import java.util.Optional;

import info.freelibrary.util.StringUtils;

import info.freelibrary.iiif.presentation.v3.Service;
import info.freelibrary.iiif.presentation.v3.properties.MediaType;

Expand Down Expand Up @@ -81,7 +83,7 @@ public URI uri() {
* @return An {@code ImageService.Profile} optional if found; or, an empty optional if not
*/
public static Optional<Profile> fromLabel(final String aLabel) {
return Optional.ofNullable(new Profile(aLabel));
return StringUtils.trimToNull(aLabel) == null ? Optional.empty() : Optional.of(new Profile(aLabel));
}
}
}
Loading

0 comments on commit a490f2d

Please sign in to comment.