diff --git a/src/main/asciidoc/index.adoc b/src/main/asciidoc/index.adoc index ba7e2f18..99170bf4 100644 --- a/src/main/asciidoc/index.adoc +++ b/src/main/asciidoc/index.adoc @@ -30,7 +30,7 @@ The `Link` value object follows the Atom link definition and consists of a `rel` ---- Link link = new Link("http://localhost:8080/something"); assertThat(link.getHref(), is("http://localhost:8080/something")); -assertThat(link.getRel(), is(Link.REL_SELF)); +assertThat(link.getRel(), is(IanaLinkRelation.SELF.value())); Link link = new Link("http://localhost:8080/something", "my-rel"); assertThat(link.getHref(), is("http://localhost:8080/something")); @@ -95,7 +95,7 @@ You can also easily access links contained in that resource: ---- Link selfLink = new Link("http://myhost/people"); assertThat(resource.getId(), is(selfLink)); -assertThat(resource.getLink(Link.REL_SELF), is(selfLink)); +assertThat(resource.getLink(IanaLinkRelation.SELF.value()), is(selfLink)); ---- [[fundamentals.obtaining-links]] === Obtaining links @@ -143,7 +143,7 @@ The `ControllerLinkBuilder` uses Spring's `ServletUriComponentsBuilder` under th Person person = new Person(1L, "Dave", "Matthews"); // /person / 1 Link link = linkTo(PersonController.class).slash(person.getId()).withSelfRel(); -assertThat(link.getRel(), is(Link.REL_SELF)); +assertThat(link.getRel(), is(IanaLinkRelation.SELF.value())); assertThat(link.getHref(), endsWith("/people/1")); ---- diff --git a/src/main/java/org/springframework/hateoas/EntityLinks.java b/src/main/java/org/springframework/hateoas/EntityLinks.java index f66ad069..26d31363 100644 --- a/src/main/java/org/springframework/hateoas/EntityLinks.java +++ b/src/main/java/org/springframework/hateoas/EntityLinks.java @@ -71,7 +71,7 @@ public interface EntityLinks extends Plugin> { /** * Creates a {@link Link} pointing to the collection resource of the given type. The relation type of the link will be - * determined by the implementation class and should be defaulted to {@link Link#REL_SELF}. + * determined by the implementation class and should be defaulted to {@link IanaLinkRelation#SELF}. * * @param type the entity type to point to, must not be {@literal null}. * @return the {@link Link} pointing to the collection resource exposed for the given entity. Will never be @@ -82,7 +82,7 @@ public interface EntityLinks extends Plugin> { /** * Creates a {@link Link} pointing to single resource backing the given entity type and id. The relation type of the - * link will be determined by the implementation class and should be defaulted to {@link Link#REL_SELF}. + * link will be determined by the implementation class and should be defaulted to {@link IanaLinkRelation#SELF}. * * @param type the entity type to point to, must not be {@literal null}. * @param id the identifier of the entity of the given type @@ -94,7 +94,7 @@ public interface EntityLinks extends Plugin> { /** * Creates a {@link Link} pointing to single resource backing the given entity. The relation type of the link will be - * determined by the implementation class and should be defaulted to {@link Link#REL_SELF}. + * determined by the implementation class and should be defaulted to {@link IanaLinkRelation#SELF}. * * @param entity the entity type to point to, must not be {@literal null}. * @return the {@link Link} pointing to the resource exposed for the given entity. Will never be {@literal null}. diff --git a/src/main/java/org/springframework/hateoas/Link.java b/src/main/java/org/springframework/hateoas/Link.java index 2e198e00..7ec69d76 100755 --- a/src/main/java/org/springframework/hateoas/Link.java +++ b/src/main/java/org/springframework/hateoas/Link.java @@ -106,11 +106,11 @@ public class Link implements Serializable { /** * Creates a new link to the given URI with the self rel. * - * @see #REL_SELF + * @see IanaLinkRelation#SELF * @param href must not be {@literal null} or empty. */ public Link(String href) { - this(href, REL_SELF); + this(href, IanaLinkRelation.SELF.value()); } /** @@ -171,7 +171,7 @@ public class Link implements Serializable { * @return */ public Link withSelfRel() { - return withRel(Link.REL_SELF); + return withRel(IanaLinkRelation.SELF.value()); } /** diff --git a/src/main/java/org/springframework/hateoas/LinkBuilder.java b/src/main/java/org/springframework/hateoas/LinkBuilder.java index 88b72e3e..f1431ce2 100644 --- a/src/main/java/org/springframework/hateoas/LinkBuilder.java +++ b/src/main/java/org/springframework/hateoas/LinkBuilder.java @@ -60,7 +60,7 @@ public interface LinkBuilder { /** * Creates the {@link Link} built by the current builder instance with the default self rel. * - * @see Link#REL_SELF + * @see IanaLinkRelation#SELF * @return */ Link withSelfRel(); diff --git a/src/main/java/org/springframework/hateoas/PagedResources.java b/src/main/java/org/springframework/hateoas/PagedResources.java index 96d7feb6..7062f11f 100644 --- a/src/main/java/org/springframework/hateoas/PagedResources.java +++ b/src/main/java/org/springframework/hateoas/PagedResources.java @@ -104,7 +104,7 @@ public class PagedResources extends Resources { */ @JsonIgnore public Optional getNextLink() { - return getLink(Link.REL_NEXT); + return getLink(IanaLinkRelation.NEXT.value()); } /** @@ -114,7 +114,7 @@ public class PagedResources extends Resources { */ @JsonIgnore public Optional getPreviousLink() { - return getLink(Link.REL_PREVIOUS); + return getLink(IanaLinkRelation.PREV.value()); } /* diff --git a/src/main/java/org/springframework/hateoas/ResourceSupport.java b/src/main/java/org/springframework/hateoas/ResourceSupport.java index c81b1430..c11659b1 100755 --- a/src/main/java/org/springframework/hateoas/ResourceSupport.java +++ b/src/main/java/org/springframework/hateoas/ResourceSupport.java @@ -42,11 +42,11 @@ public class ResourceSupport implements Identifiable { } /** - * Returns the {@link Link} with a rel of {@link Link#REL_SELF}. + * Returns the {@link Link} with a rel of {@link IanaLinkRelation#SELF}. */ @JsonIgnore public Optional getId() { - return getLink(Link.REL_SELF); + return getLink(IanaLinkRelation.SELF.value()); } /** diff --git a/src/main/java/org/springframework/hateoas/collectionjson/CollectionJsonLinkDiscoverer.java b/src/main/java/org/springframework/hateoas/collectionjson/CollectionJsonLinkDiscoverer.java index 5b6141db..451a977d 100644 --- a/src/main/java/org/springframework/hateoas/collectionjson/CollectionJsonLinkDiscoverer.java +++ b/src/main/java/org/springframework/hateoas/collectionjson/CollectionJsonLinkDiscoverer.java @@ -20,6 +20,7 @@ import java.util.List; import java.util.stream.Collectors; import java.util.stream.Stream; +import org.springframework.hateoas.IanaLinkRelation; import org.springframework.hateoas.Link; import org.springframework.hateoas.LinkDiscoverer; import org.springframework.hateoas.MediaTypes; @@ -45,7 +46,7 @@ public class CollectionJsonLinkDiscoverer extends JsonPathLinkDiscoverer { @Override public Link findLinkWithRel(String rel, String representation) { - if (rel.equals(Link.REL_SELF)) { + if (rel.equals(IanaLinkRelation.SELF.value())) { return findSelfLink(representation); } else { return super.findLinkWithRel(rel, representation); @@ -55,7 +56,7 @@ public class CollectionJsonLinkDiscoverer extends JsonPathLinkDiscoverer { @Override public Link findLinkWithRel(String rel, InputStream representation) { - if (rel.equals(Link.REL_SELF)) { + if (rel.equals(IanaLinkRelation.SELF.value())) { return findSelfLink(representation); } else { return super.findLinkWithRel(rel, representation); @@ -65,7 +66,7 @@ public class CollectionJsonLinkDiscoverer extends JsonPathLinkDiscoverer { @Override public List findLinksWithRel(String rel, String representation) { - if (rel.equals(Link.REL_SELF)) { + if (rel.equals(IanaLinkRelation.SELF.value())) { return addSelfLink(super.findLinksWithRel(rel, representation), representation); } else { return super.findLinksWithRel(rel, representation); @@ -75,7 +76,7 @@ public class CollectionJsonLinkDiscoverer extends JsonPathLinkDiscoverer { @Override public List findLinksWithRel(String rel, InputStream representation) { - if (rel.equals(Link.REL_SELF)) { + if (rel.equals(IanaLinkRelation.SELF.value())) { return addSelfLink(super.findLinksWithRel(rel, representation), representation); } else { return super.findLinksWithRel(rel, representation); @@ -87,11 +88,11 @@ public class CollectionJsonLinkDiscoverer extends JsonPathLinkDiscoverer { // private Link findSelfLink(String representation) { - return this.selfLinkDiscoverer.findLinkWithRel(Link.REL_SELF, representation); + return this.selfLinkDiscoverer.findLinkWithRel(IanaLinkRelation.SELF.value(), representation); } private Link findSelfLink(InputStream representation) { - return this.selfLinkDiscoverer.findLinkWithRel(Link.REL_SELF, representation); + return this.selfLinkDiscoverer.findLinkWithRel(IanaLinkRelation.SELF.value(), representation); } private List addSelfLink(List links, String representation) { diff --git a/src/main/java/org/springframework/hateoas/collectionjson/Jackson2CollectionJsonModule.java b/src/main/java/org/springframework/hateoas/collectionjson/Jackson2CollectionJsonModule.java index 01ee6837..1bfbaaab 100644 --- a/src/main/java/org/springframework/hateoas/collectionjson/Jackson2CollectionJsonModule.java +++ b/src/main/java/org/springframework/hateoas/collectionjson/Jackson2CollectionJsonModule.java @@ -29,6 +29,7 @@ import java.util.stream.Stream; import org.springframework.beans.BeanUtils; import org.springframework.context.support.MessageSourceAccessor; import org.springframework.hateoas.Affordance; +import org.springframework.hateoas.IanaLinkRelation; import org.springframework.hateoas.Link; import org.springframework.hateoas.MediaTypes; import org.springframework.hateoas.PagedResources; @@ -111,7 +112,7 @@ public class Jackson2CollectionJsonModule extends SimpleModule { CollectionJson collectionJson = new CollectionJson() .withVersion("1.0") - .withHref(resource.getRequiredLink(Link.REL_SELF).expand().getHref()) + .withHref(resource.getRequiredLink(IanaLinkRelation.SELF.value()).expand().getHref()) .withLinks(withoutSelfLink(value)) .withItems(Collections.EMPTY_LIST); @@ -168,7 +169,7 @@ public class Jackson2CollectionJsonModule extends SimpleModule { @Override public void serialize(ResourceSupport value, JsonGenerator jgen, SerializerProvider provider) throws IOException { - String href = value.getRequiredLink(Link.REL_SELF).getHref(); + String href = value.getRequiredLink(IanaLinkRelation.SELF.value()).getHref(); CollectionJson collectionJson = new CollectionJson() .withVersion("1.0") @@ -236,7 +237,7 @@ public class Jackson2CollectionJsonModule extends SimpleModule { @Override public void serialize(Resource value, JsonGenerator jgen, SerializerProvider provider) throws IOException { - String href = value.getRequiredLink(Link.REL_SELF).getHref(); + String href = value.getRequiredLink(IanaLinkRelation.SELF.value()).getHref(); CollectionJson collectionJson = new CollectionJson() .withVersion("1.0") @@ -301,7 +302,7 @@ public class Jackson2CollectionJsonModule extends SimpleModule { CollectionJson collectionJson = new CollectionJson() .withVersion("1.0") - .withHref(value.getRequiredLink(Link.REL_SELF).getHref()) + .withHref(value.getRequiredLink(IanaLinkRelation.SELF.value()).getHref()) .withLinks(withoutSelfLink(value.getLinks())) .withItems(resourcesToCollectionJsonItems(value)) .withQueries(findQueries(value)) @@ -364,7 +365,7 @@ public class Jackson2CollectionJsonModule extends SimpleModule { CollectionJson collectionJson = new CollectionJson() .withVersion("1.0") - .withHref(value.getRequiredLink(Link.REL_SELF).getHref()) + .withHref(value.getRequiredLink(IanaLinkRelation.SELF.value()).getHref()) .withLinks(withoutSelfLink(value.getLinks())) .withItems(resourcesToCollectionJsonItems(value)) .withQueries(findQueries(value)) @@ -797,7 +798,7 @@ public class Jackson2CollectionJsonModule extends SimpleModule { return Collections.singletonList(new Link(href)); } - if (href == null || links.stream().map(Link::getRel).anyMatch(s -> s.equals(Link.REL_SELF))) { + if (href == null || links.stream().map(Link::getRel).anyMatch(s -> s.equals(IanaLinkRelation.SELF.value()))) { return links; } @@ -813,7 +814,7 @@ public class Jackson2CollectionJsonModule extends SimpleModule { private static List withoutSelfLink(List links) { return links.stream() - .filter(link -> !link.getRel().equals(Link.REL_SELF)) + .filter(link -> !link.getRel().equals(IanaLinkRelation.SELF.value())) .collect(Collectors.toList()); } @@ -826,7 +827,7 @@ public class Jackson2CollectionJsonModule extends SimpleModule { Resource resource = (Resource) content; return new CollectionJsonItem<>() - .withHref(resource.getRequiredLink(Link.REL_SELF).getHref()) + .withHref(resource.getRequiredLink(IanaLinkRelation.SELF.value()).getHref()) .withLinks(withoutSelfLink(resource.getLinks())) .withRawData(resource.getContent()); } else { @@ -846,8 +847,8 @@ public class Jackson2CollectionJsonModule extends SimpleModule { List queries = new ArrayList<>(); - if (resource.hasLink(Link.REL_SELF)) { - Link selfLink = resource.getRequiredLink(Link.REL_SELF); + if (resource.hasLink(IanaLinkRelation.SELF.value())) { + Link selfLink = resource.getRequiredLink(IanaLinkRelation.SELF.value()); selfLink.getAffordances().forEach(affordance -> { @@ -879,8 +880,8 @@ public class Jackson2CollectionJsonModule extends SimpleModule { List templates = new ArrayList<>(); - if (resource.hasLink(Link.REL_SELF)) { - resource.getRequiredLink(Link.REL_SELF).getAffordances().forEach(affordance -> { + if (resource.hasLink(IanaLinkRelation.SELF.value())) { + resource.getRequiredLink(IanaLinkRelation.SELF.value()).getAffordances().forEach(affordance -> { CollectionJsonAffordanceModel model = affordance.getAffordanceModel(MediaTypes.COLLECTION_JSON); diff --git a/src/main/java/org/springframework/hateoas/core/LinkBuilderSupport.java b/src/main/java/org/springframework/hateoas/core/LinkBuilderSupport.java index fe4e7d40..6f6e177e 100644 --- a/src/main/java/org/springframework/hateoas/core/LinkBuilderSupport.java +++ b/src/main/java/org/springframework/hateoas/core/LinkBuilderSupport.java @@ -27,6 +27,7 @@ import java.util.List; import java.util.Optional; import org.springframework.hateoas.Affordance; +import org.springframework.hateoas.IanaLinkRelation; import org.springframework.hateoas.Identifiable; import org.springframework.hateoas.Link; import org.springframework.hateoas.LinkBuilder; @@ -163,7 +164,7 @@ public abstract class LinkBuilderSupport implements LinkB * @see org.springframework.hateoas.LinkBuilder#withSelfRel() */ public Link withSelfRel() { - return withRel(Link.REL_SELF); + return withRel(IanaLinkRelation.SELF.value()); } /* diff --git a/src/main/java/org/springframework/hateoas/hal/forms/HalFormsSerializers.java b/src/main/java/org/springframework/hateoas/hal/forms/HalFormsSerializers.java index 5b40fac1..9c469673 100644 --- a/src/main/java/org/springframework/hateoas/hal/forms/HalFormsSerializers.java +++ b/src/main/java/org/springframework/hateoas/hal/forms/HalFormsSerializers.java @@ -21,6 +21,7 @@ import java.util.HashMap; import java.util.Map; import org.springframework.hateoas.Affordance; +import org.springframework.hateoas.IanaLinkRelation; import org.springframework.hateoas.Link; import org.springframework.hateoas.MediaTypes; import org.springframework.hateoas.PagedResources; @@ -192,10 +193,10 @@ class HalFormsSerializers { Map templates = new HashMap<>(); - if (resource.hasLink(Link.REL_SELF)) { + if (resource.hasLink(IanaLinkRelation.SELF.value())) { - for (Affordance affordance : resource.getLink(Link.REL_SELF).map(Link::getAffordances) + for (Affordance affordance : resource.getLink(IanaLinkRelation.SELF.value()).map(Link::getAffordances) .orElse(Collections.emptyList())) { HalFormsAffordanceModel model = affordance.getAffordanceModel(MediaTypes.HAL_FORMS_JSON); @@ -228,7 +229,7 @@ class HalFormsSerializers { private static void validate(ResourceSupport resource, Affordance affordance, HalFormsAffordanceModel model) { String affordanceUri = model.getURI(); - String selfLinkUri = resource.getRequiredLink(Link.REL_SELF).expand().getHref(); + String selfLinkUri = resource.getRequiredLink(IanaLinkRelation.SELF.value()).expand().getHref(); if (!affordanceUri.equals(selfLinkUri)) { throw new IllegalStateException("Affordance's URI " + affordanceUri + " doesn't match self link " diff --git a/src/test/java/org/springframework/hateoas/LinkUnitTest.java b/src/test/java/org/springframework/hateoas/LinkUnitTest.java index 1dec12cf..be4ac57e 100755 --- a/src/test/java/org/springframework/hateoas/LinkUnitTest.java +++ b/src/test/java/org/springframework/hateoas/LinkUnitTest.java @@ -47,18 +47,18 @@ public class LinkUnitTest { public void linkWithHrefOnlyBecomesSelfLink() { Link link = new Link("foo"); - assertThat(link.getRel()).isEqualTo(Link.REL_SELF); + assertThat(link.getRel()).isEqualTo(IanaLinkRelation.SELF.value()); } @Test public void createsLinkFromRelAndHref() { - Link link = new Link("foo", Link.REL_SELF); + Link link = new Link("foo", IanaLinkRelation.SELF.value()); assertSoftly(softly -> { softly.assertThat(link.getHref()).isEqualTo("foo"); - softly.assertThat(link.getRel()).isEqualTo(Link.REL_SELF); + softly.assertThat(link.getRel()).isEqualTo(IanaLinkRelation.SELF.value()); }); } @@ -85,8 +85,8 @@ public class LinkUnitTest { @Test public void sameRelAndHrefMakeSameLink() { - Link left = new Link("foo", Link.REL_SELF); - Link right = new Link("foo", Link.REL_SELF); + Link left = new Link("foo", IanaLinkRelation.SELF.value()); + Link right = new Link("foo", IanaLinkRelation.SELF.value()); TestUtils.assertEqualAndSameHashCode(left, right); } @@ -94,8 +94,8 @@ public class LinkUnitTest { @Test public void differentRelMakesDifferentLink() { - Link left = new Link("foo", Link.REL_PREVIOUS); - Link right = new Link("foo", Link.REL_NEXT); + Link left = new Link("foo", IanaLinkRelation.PREV.value()); + Link right = new Link("foo", IanaLinkRelation.NEXT.value()); TestUtils.assertNotEqualAndDifferentHashCode(left, right); } @@ -103,8 +103,8 @@ public class LinkUnitTest { @Test public void differentHrefMakesDifferentLink() { - Link left = new Link("foo", Link.REL_SELF); - Link right = new Link("bar", Link.REL_SELF); + Link left = new Link("foo", IanaLinkRelation.SELF.value()); + Link right = new Link("bar", IanaLinkRelation.SELF.value()); TestUtils.assertNotEqualAndDifferentHashCode(left, right); } @@ -312,7 +312,7 @@ public class LinkUnitTest { Link link = new Link("/").andAffordance("name", HttpMethod.POST, ResolvableType.forClass(Employee.class), Collections.emptyList(), ResolvableType.forClass(Employee.class)); assertThat(link.getHref()).isEqualTo("/"); - assertThat(link.getRel()).isEqualTo(Link.REL_SELF); + assertThat(link.getRel()).isEqualTo(IanaLinkRelation.SELF.value()); assertThat(link.getAffordances()).hasSize(1); assertThat(link.getAffordances().get(0).getAffordanceModels()).hasSize(3); @@ -341,7 +341,7 @@ public class LinkUnitTest { Link link = new Link("/").andAffordance(HttpMethod.POST, ResolvableType.forClass(Employee.class), Collections.emptyList(), ResolvableType.forClass(Employee.class)); assertThat(link.getHref()).isEqualTo("/"); - assertThat(link.getRel()).isEqualTo(Link.REL_SELF); + assertThat(link.getRel()).isEqualTo(IanaLinkRelation.SELF.value()); assertThat(link.getAffordances()).hasSize(1); assertThat(link.getAffordances().get(0).getAffordanceModels()).hasSize(3); @@ -370,7 +370,7 @@ public class LinkUnitTest { Link link = new Link("/").andAffordance(HttpMethod.POST, Employee.class, Collections.emptyList(), Employee.class); assertThat(link.getHref()).isEqualTo("/"); - assertThat(link.getRel()).isEqualTo(Link.REL_SELF); + assertThat(link.getRel()).isEqualTo(IanaLinkRelation.SELF.value()); assertThat(link.getAffordances()).hasSize(1); assertThat(link.getAffordances().get(0).getAffordanceModels()).hasSize(3); assertThat(link.getAffordances().get(0).getAffordanceModel(MediaTypes.COLLECTION_JSON).getName()).isEqualTo("postEmployee"); diff --git a/src/test/java/org/springframework/hateoas/PagedResourcesUnitTest.java b/src/test/java/org/springframework/hateoas/PagedResourcesUnitTest.java index 87ce1825..f3ad9786 100755 --- a/src/test/java/org/springframework/hateoas/PagedResourcesUnitTest.java +++ b/src/test/java/org/springframework/hateoas/PagedResourcesUnitTest.java @@ -42,7 +42,7 @@ public class PagedResourcesUnitTest { @Test public void discoversNextLink() { - resources.add(new Link("foo", Link.REL_NEXT)); + resources.add(new Link("foo", IanaLinkRelation.NEXT.value())); assertThat(resources.getNextLink()).isNotNull(); } @@ -50,7 +50,7 @@ public class PagedResourcesUnitTest { @Test public void discoversPreviousLink() { - resources.add(new Link("custom", Link.REL_PREVIOUS)); + resources.add(new Link("custom", IanaLinkRelation.PREV.value())); assertThat(resources.getPreviousLink()).isNotNull(); } diff --git a/src/test/java/org/springframework/hateoas/ResourceSupportUnitTest.java b/src/test/java/org/springframework/hateoas/ResourceSupportUnitTest.java index a29cc8e8..35c8d011 100755 --- a/src/test/java/org/springframework/hateoas/ResourceSupportUnitTest.java +++ b/src/test/java/org/springframework/hateoas/ResourceSupportUnitTest.java @@ -33,15 +33,15 @@ public class ResourceSupportUnitTest { ResourceSupport support = new ResourceSupport(); assertThat(support.hasLinks()).isFalse(); - assertThat(support.hasLink(Link.REL_SELF)).isFalse(); + assertThat(support.hasLink(IanaLinkRelation.SELF.value())).isFalse(); assertThat(support.getLinks().isEmpty()).isTrue(); - assertThat(support.getLinks(Link.REL_SELF).isEmpty()).isTrue(); + assertThat(support.getLinks(IanaLinkRelation.SELF.value()).isEmpty()).isTrue(); } @Test public void addsLinkCorrectly() { - Link link = new Link("foo", Link.REL_NEXT); + Link link = new Link("foo", IanaLinkRelation.NEXT.value()); ResourceSupport support = new ResourceSupport(); support.add(link); @@ -49,7 +49,7 @@ public class ResourceSupportUnitTest { assertThat(support.hasLinks()).isTrue(); assertThat(support.hasLink(link.getRel())).isTrue(); assertThat(support.getLink(link.getRel())).hasValue(link); - assertThat(support.getLinks(Link.REL_NEXT)).contains(link); + assertThat(support.getLinks(IanaLinkRelation.NEXT.value())).contains(link); } @Test @@ -69,8 +69,8 @@ public class ResourceSupportUnitTest { @Test public void addsLinksCorrectly() { - Link first = new Link("foo", Link.REL_PREVIOUS); - Link second = new Link("bar", Link.REL_NEXT); + Link first = new Link("foo", IanaLinkRelation.PREV.value()); + Link second = new Link("bar", IanaLinkRelation.NEXT.value()); ResourceSupport support = new ResourceSupport(); support.add(Arrays.asList(first, second)); @@ -79,8 +79,8 @@ public class ResourceSupportUnitTest { assertThat(support.hasLinks()).isTrue(); assertThat(support.getLinks()).contains(first, second); assertThat(support.getLinks()).hasSize(2); - assertThat(support.getLinks(Link.REL_PREVIOUS)).contains(first); - assertThat(support.getLinks(Link.REL_NEXT)).contains(second); + assertThat(support.getLinks(IanaLinkRelation.PREV.value())).contains(first); + assertThat(support.getLinks(IanaLinkRelation.NEXT.value())).contains(second); } @Test diff --git a/src/test/java/org/springframework/hateoas/collectionjson/CollectionJsonSpecTest.java b/src/test/java/org/springframework/hateoas/collectionjson/CollectionJsonSpecTest.java index b9ad5fa9..700c5d88 100644 --- a/src/test/java/org/springframework/hateoas/collectionjson/CollectionJsonSpecTest.java +++ b/src/test/java/org/springframework/hateoas/collectionjson/CollectionJsonSpecTest.java @@ -26,6 +26,7 @@ import java.util.List; import org.junit.Before; import org.junit.Test; import org.springframework.core.io.ClassPathResource; +import org.springframework.hateoas.IanaLinkRelation; import org.springframework.hateoas.Link; import org.springframework.hateoas.Resource; import org.springframework.hateoas.ResourceSupport; @@ -68,7 +69,7 @@ public class CollectionJsonSpecTest { ResourceSupport resource = mapper.readValue(specBasedJson, ResourceSupport.class); assertThat(resource.getLinks()).hasSize(1); - assertThat(resource.getRequiredLink(Link.REL_SELF)).isEqualTo(new Link("http://example.org/friends/")); + assertThat(resource.getRequiredLink(IanaLinkRelation.SELF.value())).isEqualTo(new Link("http://example.org/friends/")); } /** @@ -85,7 +86,7 @@ public class CollectionJsonSpecTest { mapper.getTypeFactory().constructParametricType(Resource.class, Friend.class))); assertThat(resources.getLinks()).hasSize(2); - assertThat(resources.getRequiredLink(Link.REL_SELF)).isEqualTo(new Link("http://example.org/friends/")); + assertThat(resources.getRequiredLink(IanaLinkRelation.SELF.value())).isEqualTo(new Link("http://example.org/friends/")); assertThat(resources.getRequiredLink("feed")).isEqualTo(new Link("http://example.org/friends/rss", "feed")); assertThat(resources.getContent()).hasSize(3); @@ -93,19 +94,19 @@ public class CollectionJsonSpecTest { assertThat(friends.get(0).getContent().getEmail()).isEqualTo("jdoe@example.org"); assertThat(friends.get(0).getContent().getFullname()).isEqualTo("J. Doe"); - assertThat(friends.get(0).getRequiredLink(Link.REL_SELF)).isEqualTo(new Link("http://example.org/friends/jdoe")); + assertThat(friends.get(0).getRequiredLink(IanaLinkRelation.SELF.value())).isEqualTo(new Link("http://example.org/friends/jdoe")); assertThat(friends.get(0).getRequiredLink("blog")).isEqualTo(new Link("http://examples.org/blogs/jdoe", "blog")); assertThat(friends.get(0).getRequiredLink("avatar")).isEqualTo(new Link("http://examples.org/images/jdoe", "avatar")); assertThat(friends.get(1).getContent().getEmail()).isEqualTo("msmith@example.org"); assertThat(friends.get(1).getContent().getFullname()).isEqualTo("M. Smith"); - assertThat(friends.get(1).getRequiredLink(Link.REL_SELF)).isEqualTo(new Link("http://example.org/friends/msmith")); + assertThat(friends.get(1).getRequiredLink(IanaLinkRelation.SELF.value())).isEqualTo(new Link("http://example.org/friends/msmith")); assertThat(friends.get(1).getRequiredLink("blog")).isEqualTo(new Link("http://examples.org/blogs/msmith", "blog")); assertThat(friends.get(1).getRequiredLink("avatar")).isEqualTo(new Link("http://examples.org/images/msmith", "avatar")); assertThat(friends.get(2).getContent().getEmail()).isEqualTo("rwilliams@example.org"); assertThat(friends.get(2).getContent().getFullname()).isEqualTo("R. Williams"); - assertThat(friends.get(2).getRequiredLink(Link.REL_SELF)).isEqualTo(new Link("http://example.org/friends/rwilliams")); + assertThat(friends.get(2).getRequiredLink(IanaLinkRelation.SELF.value())).isEqualTo(new Link("http://example.org/friends/rwilliams")); assertThat(friends.get(2).getRequiredLink("blog")).isEqualTo(new Link("http://examples.org/blogs/rwilliams", "blog")); assertThat(friends.get(2).getRequiredLink("avatar")).isEqualTo(new Link("http://examples.org/images/rwilliams", "avatar")); } @@ -123,7 +124,7 @@ public class CollectionJsonSpecTest { mapper.getTypeFactory().constructParametricType(Resource.class, Friend.class)); assertThat(resource.getLinks()).hasSize(6); - assertThat(resource.getRequiredLink(Link.REL_SELF)).isEqualTo(new Link("http://example.org/friends/jdoe")); + assertThat(resource.getRequiredLink(IanaLinkRelation.SELF.value())).isEqualTo(new Link("http://example.org/friends/jdoe")); assertThat(resource.getRequiredLink("feed")).isEqualTo(new Link("http://example.org/friends/rss", "feed")); assertThat(resource.getRequiredLink("queries")).isEqualTo(new Link("http://example.org/friends/?queries", "queries")); assertThat(resource.getRequiredLink("template")).isEqualTo(new Link("http://example.org/friends/?template", "template")); @@ -148,7 +149,7 @@ public class CollectionJsonSpecTest { mapper.getTypeFactory().constructParametricType(Resource.class, Friend.class))); assertThat(resources.getContent()).hasSize(0); - assertThat(resources.getRequiredLink(Link.REL_SELF)).isEqualTo(new Link("http://example.org/friends/")); + assertThat(resources.getRequiredLink(IanaLinkRelation.SELF.value())).isEqualTo(new Link("http://example.org/friends/")); } /** * @see http://amundsen.com/media-types/collection/examples/ - Section 5. Template Representation @@ -164,7 +165,7 @@ public class CollectionJsonSpecTest { mapper.getTypeFactory().constructParametricType(Resource.class, Friend.class))); assertThat(resources.getContent()).hasSize(0); - assertThat(resources.getRequiredLink(Link.REL_SELF)).isEqualTo(new Link("http://example.org/friends/")); + assertThat(resources.getRequiredLink(IanaLinkRelation.SELF.value())).isEqualTo(new Link("http://example.org/friends/")); } /** * @see http://amundsen.com/media-types/collection/examples/ - Section 6. Error Representation @@ -180,7 +181,7 @@ public class CollectionJsonSpecTest { mapper.getTypeFactory().constructParametricType(Resource.class, Friend.class))); assertThat(resources.getContent()).hasSize(0); - assertThat(resources.getRequiredLink(Link.REL_SELF)).isEqualTo(new Link("http://example.org/friends/")); + assertThat(resources.getRequiredLink(IanaLinkRelation.SELF.value())).isEqualTo(new Link("http://example.org/friends/")); } /** * @see http://amundsen.com/media-types/collection/examples/ - Section 7. Write Representation diff --git a/src/test/java/org/springframework/hateoas/collectionjson/CollectionJsonWebMvcIntegrationTest.java b/src/test/java/org/springframework/hateoas/collectionjson/CollectionJsonWebMvcIntegrationTest.java index eda1d68f..b96e3446 100644 --- a/src/test/java/org/springframework/hateoas/collectionjson/CollectionJsonWebMvcIntegrationTest.java +++ b/src/test/java/org/springframework/hateoas/collectionjson/CollectionJsonWebMvcIntegrationTest.java @@ -37,6 +37,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.io.ClassPathResource; +import org.springframework.hateoas.IanaLinkRelation; import org.springframework.hateoas.Link; import org.springframework.hateoas.MediaTypes; import org.springframework.hateoas.Resource; @@ -271,7 +272,7 @@ public class CollectionJsonWebMvcIntegrationTest { try { return ResponseEntity .created( - new URI(findOne(newEmployeeId).getLink(Link.REL_SELF).map(link -> link.expand().getHref()).orElse(""))) + new URI(findOne(newEmployeeId).getLink(IanaLinkRelation.SELF.value()).map(link -> link.expand().getHref()).orElse(""))) .build(); } catch (URISyntaxException e) { return ResponseEntity.badRequest().body(e.getMessage()); @@ -285,7 +286,7 @@ public class CollectionJsonWebMvcIntegrationTest { try { return ResponseEntity.noContent() - .location(new URI(findOne(id).getLink(Link.REL_SELF).map(link -> link.expand().getHref()).orElse(""))) + .location(new URI(findOne(id).getLink(IanaLinkRelation.SELF.value()).map(link -> link.expand().getHref()).orElse(""))) .build(); } catch (URISyntaxException e) { return ResponseEntity.badRequest().body(e.getMessage()); @@ -311,7 +312,7 @@ public class CollectionJsonWebMvcIntegrationTest { try { return ResponseEntity.noContent() - .location(new URI(findOne(id).getLink(Link.REL_SELF).map(link -> link.expand().getHref()).orElse(""))) + .location(new URI(findOne(id).getLink(IanaLinkRelation.SELF.value()).map(link -> link.expand().getHref()).orElse(""))) .build(); } catch (URISyntaxException e) { return ResponseEntity.badRequest().body(e.getMessage()); diff --git a/src/test/java/org/springframework/hateoas/collectionjson/Jackson2CollectionJsonIntegrationTest.java b/src/test/java/org/springframework/hateoas/collectionjson/Jackson2CollectionJsonIntegrationTest.java index 178b0a5c..675f8b99 100644 --- a/src/test/java/org/springframework/hateoas/collectionjson/Jackson2CollectionJsonIntegrationTest.java +++ b/src/test/java/org/springframework/hateoas/collectionjson/Jackson2CollectionJsonIntegrationTest.java @@ -28,6 +28,7 @@ import org.junit.Before; import org.junit.Test; import org.springframework.core.io.ClassPathResource; import org.springframework.hateoas.AbstractJackson2MarshallingIntegrationTest; +import org.springframework.hateoas.IanaLinkRelation; import org.springframework.hateoas.Link; import org.springframework.hateoas.Links; import org.springframework.hateoas.PagedResources; @@ -47,9 +48,9 @@ import com.fasterxml.jackson.databind.SerializationFeature; public class Jackson2CollectionJsonIntegrationTest extends AbstractJackson2MarshallingIntegrationTest { static final Links PAGINATION_LINKS = new Links( - new Link("localhost", Link.REL_SELF), - new Link("foo", Link.REL_NEXT), - new Link("bar", Link.REL_PREVIOUS)); + new Link("localhost", IanaLinkRelation.SELF.value()), + new Link("foo", IanaLinkRelation.NEXT.value()), + new Link("bar", IanaLinkRelation.PREV.value())); @Before public void setUpModule() { diff --git a/src/test/java/org/springframework/hateoas/hal/Jackson2HalIntegrationTest.java b/src/test/java/org/springframework/hateoas/hal/Jackson2HalIntegrationTest.java index 0e82e16a..d21a2cb2 100755 --- a/src/test/java/org/springframework/hateoas/hal/Jackson2HalIntegrationTest.java +++ b/src/test/java/org/springframework/hateoas/hal/Jackson2HalIntegrationTest.java @@ -32,6 +32,7 @@ import org.springframework.context.i18n.LocaleContextHolder; import org.springframework.context.support.MessageSourceAccessor; import org.springframework.context.support.StaticMessageSource; import org.springframework.hateoas.AbstractJackson2MarshallingIntegrationTest; +import org.springframework.hateoas.IanaLinkRelation; import org.springframework.hateoas.Link; import org.springframework.hateoas.Links; import org.springframework.hateoas.PagedResources; @@ -69,7 +70,7 @@ public class Jackson2HalIntegrationTest extends AbstractJackson2MarshallingInteg static final String ANNOTATED_PAGED_RESOURCES = "{\"_embedded\":{\"pojos\":[{\"text\":\"test1\",\"number\":1,\"_links\":{\"self\":{\"href\":\"localhost\"}}},{\"text\":\"test2\",\"number\":2,\"_links\":{\"self\":{\"href\":\"localhost\"}}}]},\"_links\":{\"next\":{\"href\":\"foo\"},\"prev\":{\"href\":\"bar\"}},\"page\":{\"size\":2,\"totalElements\":4,\"totalPages\":2,\"number\":0}}"; - static final Links PAGINATION_LINKS = new Links(new Link("foo", Link.REL_NEXT), new Link("bar", Link.REL_PREVIOUS)); + static final Links PAGINATION_LINKS = new Links(new Link("foo", IanaLinkRelation.NEXT.value()), new Link("bar", IanaLinkRelation.PREV.value())); static final String CURIED_DOCUMENT = "{\"_links\":{\"self\":{\"href\":\"foo\"},\"foo:myrel\":{\"href\":\"bar\"},\"curies\":[{\"href\":\"http://localhost:8080/rels/{rel}\",\"name\":\"foo\",\"templated\":true}]}}"; static final String MULTIPLE_CURIES_DOCUMENT = "{\"_links\":{\"default:myrel\":{\"href\":\"foo\"},\"curies\":[{\"href\":\"bar\",\"name\":\"foo\"},{\"href\":\"foo\",\"name\":\"bar\"}]}}"; diff --git a/src/test/java/org/springframework/hateoas/hal/forms/HalFormsValidationIntegrationTest.java b/src/test/java/org/springframework/hateoas/hal/forms/HalFormsValidationIntegrationTest.java index e3fbc149..4a41f220 100644 --- a/src/test/java/org/springframework/hateoas/hal/forms/HalFormsValidationIntegrationTest.java +++ b/src/test/java/org/springframework/hateoas/hal/forms/HalFormsValidationIntegrationTest.java @@ -35,6 +35,7 @@ import org.junit.runner.RunWith; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; +import org.springframework.hateoas.IanaLinkRelation; import org.springframework.hateoas.Link; import org.springframework.hateoas.MediaTypes; import org.springframework.hateoas.Resource; @@ -157,7 +158,7 @@ public class HalFormsValidationIntegrationTest { try { return ResponseEntity.noContent() .location( - new URI(findOne(newEmployeeId).getLink(Link.REL_SELF).map(link -> link.expand().getHref()).orElse(""))) + new URI(findOne(newEmployeeId).getLink(IanaLinkRelation.SELF.value()).map(link -> link.expand().getHref()).orElse(""))) .build(); } catch (URISyntaxException e) { return ResponseEntity.badRequest().body(e.getMessage()); @@ -171,7 +172,7 @@ public class HalFormsValidationIntegrationTest { try { return ResponseEntity.noContent() - .location(new URI(findOne(id).getLink(Link.REL_SELF).map(link -> link.expand().getHref()).orElse(""))) + .location(new URI(findOne(id).getLink(IanaLinkRelation.SELF.value()).map(link -> link.expand().getHref()).orElse(""))) .build(); } catch (URISyntaxException e) { return ResponseEntity.badRequest().body(e.getMessage()); @@ -197,7 +198,7 @@ public class HalFormsValidationIntegrationTest { try { return ResponseEntity.noContent() - .location(new URI(findOne(id).getLink(Link.REL_SELF).map(link -> link.expand().getHref()).orElse(""))) + .location(new URI(findOne(id).getLink(IanaLinkRelation.SELF.value()).map(link -> link.expand().getHref()).orElse(""))) .build(); } catch (URISyntaxException e) { return ResponseEntity.badRequest().body(e.getMessage()); diff --git a/src/test/java/org/springframework/hateoas/hal/forms/HalFormsWebMvcIntegrationTest.java b/src/test/java/org/springframework/hateoas/hal/forms/HalFormsWebMvcIntegrationTest.java index c08abf92..b199b08e 100644 --- a/src/test/java/org/springframework/hateoas/hal/forms/HalFormsWebMvcIntegrationTest.java +++ b/src/test/java/org/springframework/hateoas/hal/forms/HalFormsWebMvcIntegrationTest.java @@ -36,6 +36,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.io.ClassPathResource; +import org.springframework.hateoas.IanaLinkRelation; import org.springframework.hateoas.Link; import org.springframework.hateoas.MediaTypes; import org.springframework.hateoas.Resource; @@ -233,7 +234,7 @@ public class HalFormsWebMvcIntegrationTest { private URI toUri(Integer id) throws URISyntaxException { - String uri = findOne(id).getLink(Link.REL_SELF) // + String uri = findOne(id).getLink(IanaLinkRelation.SELF.value()) // .map(link -> link.expand().getHref()) // .orElse(""); diff --git a/src/test/java/org/springframework/hateoas/hal/forms/Jackson2HalFormsIntegrationTest.java b/src/test/java/org/springframework/hateoas/hal/forms/Jackson2HalFormsIntegrationTest.java index 18ddd869..38a02d03 100644 --- a/src/test/java/org/springframework/hateoas/hal/forms/Jackson2HalFormsIntegrationTest.java +++ b/src/test/java/org/springframework/hateoas/hal/forms/Jackson2HalFormsIntegrationTest.java @@ -33,6 +33,7 @@ import org.springframework.context.support.MessageSourceAccessor; import org.springframework.context.support.StaticMessageSource; import org.springframework.core.io.ClassPathResource; import org.springframework.hateoas.AbstractJackson2MarshallingIntegrationTest; +import org.springframework.hateoas.IanaLinkRelation; import org.springframework.hateoas.Link; import org.springframework.hateoas.Links; import org.springframework.hateoas.PagedResources; @@ -58,7 +59,7 @@ import com.fasterxml.jackson.databind.SerializationFeature; */ public class Jackson2HalFormsIntegrationTest extends AbstractJackson2MarshallingIntegrationTest { - static final Links PAGINATION_LINKS = new Links(new Link("foo", Link.REL_NEXT), new Link("bar", Link.REL_PREVIOUS)); + static final Links PAGINATION_LINKS = new Links(new Link("foo", IanaLinkRelation.NEXT.value()), new Link("bar", IanaLinkRelation.PREV.value())); @Before public void setUpModule() { diff --git a/src/test/java/org/springframework/hateoas/mvc/ControllerLinkBuilderFactoryUnitTest.java b/src/test/java/org/springframework/hateoas/mvc/ControllerLinkBuilderFactoryUnitTest.java index b86c8368..3bdf5b0d 100755 --- a/src/test/java/org/springframework/hateoas/mvc/ControllerLinkBuilderFactoryUnitTest.java +++ b/src/test/java/org/springframework/hateoas/mvc/ControllerLinkBuilderFactoryUnitTest.java @@ -29,6 +29,7 @@ import org.junit.Test; import org.springframework.core.MethodParameter; import org.springframework.format.annotation.DateTimeFormat; import org.springframework.format.annotation.DateTimeFormat.ISO; +import org.springframework.hateoas.IanaLinkRelation; import org.springframework.hateoas.Link; import org.springframework.hateoas.TestUtils; import org.springframework.hateoas.mvc.ControllerLinkBuilderUnitTest.ControllerWithMethods; @@ -60,7 +61,7 @@ public class ControllerLinkBuilderFactoryUnitTest extends TestUtils { Link link = factory.linkTo(PersonControllerImpl.class).withSelfRel(); assertPointsToMockServer(link); - assertThat(link.getRel()).isEqualTo(Link.REL_SELF); + assertThat(link.getRel()).isEqualTo(IanaLinkRelation.SELF.value()); assertThat(link.getHref()).endsWith("/people"); } @@ -70,7 +71,7 @@ public class ControllerLinkBuilderFactoryUnitTest extends TestUtils { Link link = factory.linkTo(PersonsAddressesController.class, 15).withSelfRel(); assertPointsToMockServer(link); - assertThat(link.getRel()).isEqualTo(Link.REL_SELF); + assertThat(link.getRel()).isEqualTo(IanaLinkRelation.SELF.value()); assertThat(link.getHref()).endsWith("/people/15/addresses"); } @@ -108,7 +109,7 @@ public class ControllerLinkBuilderFactoryUnitTest extends TestUtils { public void linksToMethodWithPathVariableContainingBlank() { Link link = linkTo(methodOn(ControllerWithMethods.class).methodWithPathVariable("with blank")).withSelfRel(); - assertThat(link.getRel()).isEqualTo(Link.REL_SELF); + assertThat(link.getRel()).isEqualTo(IanaLinkRelation.SELF.value()); assertThat(link.getHref()).endsWith("/something/with%20blank/foo"); } @@ -121,7 +122,7 @@ public class ControllerLinkBuilderFactoryUnitTest extends TestUtils { Link link = factory.linkTo(PersonsAddressesController.class, "with blank").withSelfRel(); assertPointsToMockServer(link); - assertThat(link.getRel()).isEqualTo(Link.REL_SELF); + assertThat(link.getRel()).isEqualTo(IanaLinkRelation.SELF.value()); assertThat(link.getHref()).endsWith("/people/with%20blank/addresses"); } @@ -138,7 +139,7 @@ public class ControllerLinkBuilderFactoryUnitTest extends TestUtils { Link link = factory.linkTo(methodOn(SampleController.class).sampleMethodWithMap(queryParams)).withSelfRel(); assertPointsToMockServer(link); - assertThat(link.getRel()).isEqualTo(Link.REL_SELF); + assertThat(link.getRel()).isEqualTo(IanaLinkRelation.SELF.value()); assertThat(link.getHref()).endsWith("/sample/mapsupport?firstKey=firstValue&secondKey=secondValue"); } @@ -155,7 +156,7 @@ public class ControllerLinkBuilderFactoryUnitTest extends TestUtils { Link link = factory.linkTo(methodOn(SampleController.class).sampleMethodWithMap(queryParams)).withSelfRel(); assertPointsToMockServer(link); - assertThat(link.getRel()).isEqualTo(Link.REL_SELF); + assertThat(link.getRel()).isEqualTo(IanaLinkRelation.SELF.value()); assertThat(link.getHref()) // .endsWith("/sample/multivaluemapsupport?key1=value1a&key1=value1b&key2=value2a&key2=value2b"); } @@ -169,7 +170,7 @@ public class ControllerLinkBuilderFactoryUnitTest extends TestUtils { Link link = factory.linkTo(PersonsAddressesController.class, Collections.singletonMap("id", "17")).withSelfRel(); assertPointsToMockServer(link); - assertThat(link.getRel()).isEqualTo(Link.REL_SELF); + assertThat(link.getRel()).isEqualTo(IanaLinkRelation.SELF.value()); assertThat(link.getHref()).endsWith("/people/17/addresses"); } diff --git a/src/test/java/org/springframework/hateoas/mvc/ControllerLinkBuilderUnitTest.java b/src/test/java/org/springframework/hateoas/mvc/ControllerLinkBuilderUnitTest.java index ce172a1b..083b437e 100755 --- a/src/test/java/org/springframework/hateoas/mvc/ControllerLinkBuilderUnitTest.java +++ b/src/test/java/org/springframework/hateoas/mvc/ControllerLinkBuilderUnitTest.java @@ -32,6 +32,7 @@ import org.junit.Rule; import org.junit.Test; import org.junit.rules.ExpectedException; import org.mockito.Mockito; +import org.springframework.hateoas.IanaLinkRelation; import org.springframework.hateoas.Identifiable; import org.springframework.hateoas.Link; import org.springframework.hateoas.TemplateVariable; @@ -66,7 +67,7 @@ public class ControllerLinkBuilderUnitTest extends TestUtils { public void createsLinkToControllerRoot() { Link link = linkTo(PersonControllerImpl.class).withSelfRel(); - assertThat(link.getRel()).isEqualTo(Link.REL_SELF); + assertThat(link.getRel()).isEqualTo(IanaLinkRelation.SELF.value()); assertThat(link.getHref()).endsWith("/people"); } @@ -74,7 +75,7 @@ public class ControllerLinkBuilderUnitTest extends TestUtils { public void createsLinkToParameterizedControllerRoot() { Link link = linkTo(PersonsAddressesController.class, 15).withSelfRel(); - assertThat(link.getRel()).isEqualTo(Link.REL_SELF); + assertThat(link.getRel()).isEqualTo(IanaLinkRelation.SELF.value()); assertThat(link.getHref()).endsWith("/people/15/addresses"); } @@ -85,7 +86,7 @@ public class ControllerLinkBuilderUnitTest extends TestUtils { public void createsLinkToMethodOnParameterizedControllerRoot() { Link link = linkTo(methodOn(PersonsAddressesController.class, 15).getAddressesForCountry("DE")).withSelfRel(); - assertThat(link.getRel()).isEqualTo(Link.REL_SELF); + assertThat(link.getRel()).isEqualTo(IanaLinkRelation.SELF.value()); assertThat(link.getHref()).endsWith("/people/15/addresses/DE"); } @@ -93,15 +94,15 @@ public class ControllerLinkBuilderUnitTest extends TestUtils { public void createsLinkToSubResource() { Link link = linkTo(PersonControllerImpl.class).slash("something").withSelfRel(); - assertThat(link.getRel()).isEqualTo(Link.REL_SELF); + assertThat(link.getRel()).isEqualTo(IanaLinkRelation.SELF.value()); assertThat(link.getHref()).endsWith("/people/something"); } @Test public void createsLinkWithCustomRel() { - Link link = linkTo(PersonControllerImpl.class).withRel(Link.REL_NEXT); - assertThat(link.getRel()).isEqualTo(Link.REL_NEXT); + Link link = linkTo(PersonControllerImpl.class).withRel(IanaLinkRelation.NEXT.value()); + assertThat(link.getRel()).isEqualTo(IanaLinkRelation.NEXT.value()); assertThat(link.getHref()).endsWith("/people"); } @@ -399,7 +400,7 @@ public class ControllerLinkBuilderUnitTest extends TestUtils { public void linksToMethodWithPathVariableContainingBlank() { Link link = linkTo(methodOn(ControllerWithMethods.class).methodWithPathVariable("with blank")).withSelfRel(); - assertThat(link.getRel()).isEqualTo(Link.REL_SELF); + assertThat(link.getRel()).isEqualTo(IanaLinkRelation.SELF.value()); assertThat(link.getHref()).endsWith("/something/with%20blank/foo"); } @@ -495,7 +496,7 @@ public class ControllerLinkBuilderUnitTest extends TestUtils { Link link = linkTo(methodOn(ControllerWithMethods.class).methodWithRequestParam("Spring#\n")).withSelfRel(); - assertThat(link.getRel()).isEqualTo(Link.REL_SELF); + assertThat(link.getRel()).isEqualTo(IanaLinkRelation.SELF.value()); assertThat(link.getHref()).endsWith("/something/foo?id=Spring%23%0A"); } diff --git a/src/test/java/org/springframework/hateoas/mvc/IdentifiableResourceAssemblerSupportUnitTest.java b/src/test/java/org/springframework/hateoas/mvc/IdentifiableResourceAssemblerSupportUnitTest.java index 6466e5fd..0c1d3dd8 100755 --- a/src/test/java/org/springframework/hateoas/mvc/IdentifiableResourceAssemblerSupportUnitTest.java +++ b/src/test/java/org/springframework/hateoas/mvc/IdentifiableResourceAssemblerSupportUnitTest.java @@ -24,6 +24,7 @@ import java.util.Optional; import org.junit.Before; import org.junit.Test; +import org.springframework.hateoas.IanaLinkRelation; import org.springframework.hateoas.Identifiable; import org.springframework.hateoas.Link; import org.springframework.hateoas.LinkBuilder; @@ -56,7 +57,7 @@ public class IdentifiableResourceAssemblerSupportUnitTest extends TestUtils { public void createsInstanceWithSelfLinkToController() { PersonResource resource = assembler.createResource(person); - Link link = resource.getRequiredLink(Link.REL_SELF); + Link link = resource.getRequiredLink(IanaLinkRelation.SELF.value()); assertThat(link).isNotNull(); assertThat(resource.getLinks()).hasSize(1); diff --git a/src/test/java/org/springframework/hateoas/mvc/MultiMediatypeWebMvcIntegrationTest.java b/src/test/java/org/springframework/hateoas/mvc/MultiMediatypeWebMvcIntegrationTest.java index 90bd9fe0..b3cabac5 100644 --- a/src/test/java/org/springframework/hateoas/mvc/MultiMediatypeWebMvcIntegrationTest.java +++ b/src/test/java/org/springframework/hateoas/mvc/MultiMediatypeWebMvcIntegrationTest.java @@ -38,6 +38,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.io.ClassPathResource; +import org.springframework.hateoas.IanaLinkRelation; import org.springframework.hateoas.Link; import org.springframework.hateoas.MediaTypes; import org.springframework.hateoas.Resource; @@ -563,7 +564,7 @@ public class MultiMediatypeWebMvcIntegrationTest { private URI toUri(Integer id) throws URISyntaxException { String uri = findOne(id) // - .getLink(Link.REL_SELF) // + .getLink(IanaLinkRelation.SELF.value()) // .map(link -> link.expand().getHref()) // .orElse(""); diff --git a/src/test/java/org/springframework/hateoas/uber/UberWebMvcIntegrationTest.java b/src/test/java/org/springframework/hateoas/uber/UberWebMvcIntegrationTest.java index d94c458d..06e84771 100644 --- a/src/test/java/org/springframework/hateoas/uber/UberWebMvcIntegrationTest.java +++ b/src/test/java/org/springframework/hateoas/uber/UberWebMvcIntegrationTest.java @@ -39,6 +39,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.core.io.ClassPathResource; +import org.springframework.hateoas.IanaLinkRelation; import org.springframework.hateoas.Link; import org.springframework.hateoas.MediaTypes; import org.springframework.hateoas.Resource; @@ -347,7 +348,7 @@ public class UberWebMvcIntegrationTest { EMPLOYEES.put(newEmployeeId, employee.getContent()); try { - return ResponseEntity.created(new URI(findOne(newEmployeeId).getLink(Link.REL_SELF).map(link -> link.expand().getHref()).orElse(""))) + return ResponseEntity.created(new URI(findOne(newEmployeeId).getLink(IanaLinkRelation.SELF.value()).map(link -> link.expand().getHref()).orElse(""))) .build(); } catch (URISyntaxException e) { return ResponseEntity.badRequest().body(e.getMessage()); @@ -360,7 +361,7 @@ public class UberWebMvcIntegrationTest { EMPLOYEES.put(id, employee.getContent()); try { - return ResponseEntity.noContent().location(new URI(findOne(id).getLink(Link.REL_SELF).map(link -> link.expand().getHref()).orElse(""))) + return ResponseEntity.noContent().location(new URI(findOne(id).getLink(IanaLinkRelation.SELF.value()).map(link -> link.expand().getHref()).orElse(""))) .build(); } catch (URISyntaxException e) { return ResponseEntity.badRequest().body(e.getMessage()); @@ -384,7 +385,7 @@ public class UberWebMvcIntegrationTest { EMPLOYEES.put(id, newEmployee); try { - return ResponseEntity.noContent().location(new URI(findOne(id).getLink(Link.REL_SELF).map(link -> link.expand().getHref()).orElse(""))) + return ResponseEntity.noContent().location(new URI(findOne(id).getLink(IanaLinkRelation.SELF.value()).map(link -> link.expand().getHref()).orElse(""))) .build(); } catch (URISyntaxException e) { return ResponseEntity.badRequest().body(e.getMessage());