diff --git a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/support/DefaultSelfLinkProviderUnitTests.java b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/support/DefaultSelfLinkProviderUnitTests.java index 07c98a347..4c1906a33 100755 --- a/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/support/DefaultSelfLinkProviderUnitTests.java +++ b/spring-data-rest-core/src/test/java/org/springframework/data/rest/core/support/DefaultSelfLinkProviderUnitTests.java @@ -58,7 +58,7 @@ public class DefaultSelfLinkProviderUnitTests { Class type = invocation.getArgument(0); Object id = invocation.getArgument(1); - return new Link("/".concat(type.getName()).concat("/").concat(id.toString())); + return Link.of("/".concat(type.getName()).concat("/").concat(id.toString())); }); KeyValueMappingContext context = new KeyValueMappingContext<>(); diff --git a/spring-data-rest-tests/spring-data-rest-tests-core/src/test/java/org/springframework/data/rest/tests/AbstractWebIntegrationTests.java b/spring-data-rest-tests/spring-data-rest-tests-core/src/test/java/org/springframework/data/rest/tests/AbstractWebIntegrationTests.java index 47dcc7e05..4f79a7b33 100755 --- a/spring-data-rest-tests/spring-data-rest-tests-core/src/test/java/org/springframework/data/rest/tests/AbstractWebIntegrationTests.java +++ b/spring-data-rest-tests/spring-data-rest-tests-core/src/test/java/org/springframework/data/rest/tests/AbstractWebIntegrationTests.java @@ -176,7 +176,7 @@ public abstract class AbstractWebIntegrationTests { assertThat(href).as(message, " not", rel).isNull(); } - return new Link(href, rel); + return Link.of(href, rel); } catch (InvalidPathException o_O) { diff --git a/spring-data-rest-tests/spring-data-rest-tests-core/src/test/java/org/springframework/data/rest/tests/CommonWebTests.java b/spring-data-rest-tests/spring-data-rest-tests-core/src/test/java/org/springframework/data/rest/tests/CommonWebTests.java index ee0448b19..5ab21f92e 100755 --- a/spring-data-rest-tests/spring-data-rest-tests-core/src/test/java/org/springframework/data/rest/tests/CommonWebTests.java +++ b/spring-data-rest-tests/spring-data-rest-tests-core/src/test/java/org/springframework/data/rest/tests/CommonWebTests.java @@ -180,7 +180,7 @@ public abstract class CommonWebTests extends AbstractWebIntegrationTests { for (Object href : uris) { - client.follow(new Link(href.toString())) // + client.follow(Link.of(href.toString())) // .andExpect(status().isOk()); } } diff --git a/spring-data-rest-tests/spring-data-rest-tests-core/src/test/java/org/springframework/data/rest/tests/TestMvcClient.java b/spring-data-rest-tests/spring-data-rest-tests-core/src/test/java/org/springframework/data/rest/tests/TestMvcClient.java index 2dd216175..9b5629d51 100644 --- a/spring-data-rest-tests/spring-data-rest-tests-core/src/test/java/org/springframework/data/rest/tests/TestMvcClient.java +++ b/spring-data-rest-tests/spring-data-rest-tests-core/src/test/java/org/springframework/data/rest/tests/TestMvcClient.java @@ -211,7 +211,7 @@ public class TestMvcClient { * @throws Exception */ public Links discover(LinkRelation rel) throws Exception { - return discover(new Link("/"), rel); + return discover(Link.of("/"), rel); } public Link discoverUnique(String rel) throws Exception { diff --git a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/DataRest262Tests.java b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/DataRest262Tests.java index 0fb66a255..5717123e7 100755 --- a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/DataRest262Tests.java +++ b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/DataRest262Tests.java @@ -124,7 +124,7 @@ public class DataRest262Tests { JpaPersistentEntity persistentEntity = mappingContext.getRequiredPersistentEntity(AircraftMovement.class); EntityModel resource = PersistentEntityResource.build(movement, persistentEntity).// - withLink(new Link("/api/airports/" + movement.id)).// + withLink(Link.of("/api/airports/" + movement.id)).// build(); String result = mapper.writeValueAsString(resource); diff --git a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/JpaWebTests.java b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/JpaWebTests.java index ade409cdd..f8bd24e6b 100755 --- a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/JpaWebTests.java +++ b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/JpaWebTests.java @@ -370,7 +370,7 @@ public class JpaWebTests extends CommonWebTests { patchAndGet(frodosSiblingsLink, links.get(3).getHref(), TEXT_URI_LIST); String pippinId = new UriTemplate("/people/{id}").match(links.get(3).getHref()).get("id"); - deleteAndVerify(new Link(frodosSiblingsLink.expand().getHref() + "/" + pippinId)); + deleteAndVerify(Link.of(frodosSiblingsLink.expand().getHref() + "/" + pippinId)); assertSiblingNames(frodosSiblingsLink, "Bilbo", "Merry"); } @@ -507,7 +507,7 @@ public class JpaWebTests extends CommonWebTests { String content = response.getContentAsString(); String href = JsonPath.read(content, firstAuthorPath.concat("._links.self.href")); - client.follow(new Link(href)).andExpect(client.hasLinkWithRel("books")); + client.follow(Link.of(href)).andExpect(client.hasLinkWithRel("books")); } @Test // DATAREST-353 @@ -766,7 +766,7 @@ public class JpaWebTests extends CommonWebTests { assertThat(JsonPath. read(john, "$.firstName")).isNotNull(); // Assert sibling link exposed in resource pointed to - Link selfLink = new Link(JsonPath. read(john, "$._links.self.href")); + Link selfLink = Link.of(JsonPath. read(john, "$._links.self.href")); client.follow(selfLink).// andExpect(status().isOk()).// andExpect(jsonPath("$._links.siblings", is(notNullValue()))); diff --git a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/ProfileIntegrationTests.java b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/ProfileIntegrationTests.java index f21274db7..77675d4f3 100755 --- a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/ProfileIntegrationTests.java +++ b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/ProfileIntegrationTests.java @@ -85,7 +85,7 @@ public class ProfileIntegrationTests extends AbstractControllerIntegrationTests @Test // DATAREST-230, DATAREST-638 public void profileRootLinkContainsMetadataForEachRepo() throws Exception { - Link profileLink = client.discoverUnique(new Link(ROOT_URI), ProfileResourceProcessor.PROFILE_REL); + Link profileLink = client.discoverUnique(Link.of(ROOT_URI), ProfileResourceProcessor.PROFILE_REL); assertThat(client.discoverUnique(profileLink, "self", MediaType.ALL)).isNotNull(); assertThat(client.discoverUnique(profileLink, "people", MediaType.ALL)).isNotNull(); @@ -100,7 +100,7 @@ public class ProfileIntegrationTests extends AbstractControllerIntegrationTests @Test // DATAREST-638 public void profileLinkOnCollectionResourceLeadsToRepositorySpecificMetadata() throws Exception { - Link peopleLink = client.discoverUnique(new Link(ROOT_URI), "people"); + Link peopleLink = client.discoverUnique(Link.of(ROOT_URI), "people"); Link profileLink = client.discoverUnique(peopleLink, ProfileResourceProcessor.PROFILE_REL); client.follow(profileLink, MediaTypes.ALPS_JSON).andExpect(status().is2xxSuccessful()) diff --git a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/json/PersistentEntitySerializationTests.java b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/json/PersistentEntitySerializationTests.java index 9b10da356..e74877f0e 100755 --- a/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/json/PersistentEntitySerializationTests.java +++ b/spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/json/PersistentEntitySerializationTests.java @@ -135,7 +135,7 @@ public class PersistentEntitySerializationTests { Person person = people.save(new Person("John", "Doe")); PersistentEntityResource resource = PersistentEntityResource.build(person, persistentEntity).// - withLink(new Link("/person/" + person.getId())).build(); + withLink(Link.of("/person/" + person.getId())).build(); StringWriter writer = new StringWriter(); mapper.writeValue(writer, resource); @@ -197,7 +197,7 @@ public class PersistentEntitySerializationTests { PersistentEntityResource orderResource = PersistentEntityResource.// build(order, repositories.getPersistentEntity(Order.class)).// - withLink(new Link("/orders/1")).// + withLink(Link.of("/orders/1")).// build(); PagedModel persistentEntityResource = new PagedModel( @@ -238,8 +238,8 @@ public class PersistentEntitySerializationTests { PersistentEntityResource resource = PersistentEntityResource.// build(dave, repositories.getPersistentEntity(Person.class)).// - withLink(new Link("/people/1")).// - withLink(new Link("/aditional", "processed")).// + withLink(Link.of("/people/1")).// + withLink(Link.of("/aditional", "processed")).// build(); String result = mapper.writeValueAsString(resource); @@ -284,7 +284,7 @@ public class PersistentEntitySerializationTests { PersistentEntityResource resource = PersistentEntityResource// .build(guest, context.getRequiredPersistentEntity(Guest.class))// - .withLink(new Link("/guests/1")).build(); + .withLink(Link.of("/guests/1")).build(); String result = mapper.writeValueAsString(resource); diff --git a/spring-data-rest-tests/spring-data-rest-tests-mongodb/src/test/java/org/springframework/data/rest/webmvc/json/PersistentEntitySerializationTests.java b/spring-data-rest-tests/spring-data-rest-tests-mongodb/src/test/java/org/springframework/data/rest/webmvc/json/PersistentEntitySerializationTests.java index 969de9e2d..236bb61ed 100755 --- a/spring-data-rest-tests/spring-data-rest-tests-mongodb/src/test/java/org/springframework/data/rest/webmvc/json/PersistentEntitySerializationTests.java +++ b/spring-data-rest-tests/spring-data-rest-tests-mongodb/src/test/java/org/springframework/data/rest/webmvc/json/PersistentEntitySerializationTests.java @@ -103,7 +103,7 @@ public class PersistentEntitySerializationTests { PersistentEntityResource userResource = PersistentEntityResource.// build(user, repositories.getPersistentEntity(User.class)).// - withLink(new Link("/users/1")).// + withLink(Link.of("/users/1")).// build(); PagedModel persistentEntityResource = new PagedModel( diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/AbstractRepositoryRestController.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/AbstractRepositoryRestController.java index 451817c1f..98c25cd35 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/AbstractRepositoryRestController.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/AbstractRepositoryRestController.java @@ -68,7 +68,7 @@ class AbstractRepositoryRestController { Link selfLink = resource.getRequiredLink(IanaLinkRelations.SELF); LinkRelation rel = repoMapping.getItemResourceRel(); - return new Link(selfLink.getHref(), rel); + return Link.of(selfLink.getHref(), rel); } @SuppressWarnings({ "unchecked" }) @@ -116,6 +116,6 @@ class AbstractRepositoryRestController { } protected Link getDefaultSelfLink() { - return new Link(ServletUriComponentsBuilder.fromCurrentRequest().build().toUriString()); + return Link.of(ServletUriComponentsBuilder.fromCurrentRequest().build().toUriString()); } } diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/ProfileController.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/ProfileController.java index bb64a1f7c..31015b4ad 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/ProfileController.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/ProfileController.java @@ -96,14 +96,14 @@ public class ProfileController { RepresentationModel profile = new RepresentationModel<>(); - profile.add(new Link(getRootPath(this.configuration)).withSelfRel()); + profile.add(Link.of(getRootPath(this.configuration)).withSelfRel()); for (Class domainType : this.repositories) { ResourceMetadata mapping = this.mappings.getMetadataFor(domainType); if (mapping.isExported()) { - profile.add(new Link(getPath(this.configuration, mapping), mapping.getRel())); + profile.add(Link.of(getPath(this.configuration, mapping), mapping.getRel())); } } diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/ProfileResourceProcessor.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/ProfileResourceProcessor.java index 517350d65..99b78c31b 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/ProfileResourceProcessor.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/ProfileResourceProcessor.java @@ -55,7 +55,7 @@ public class ProfileResourceProcessor implements RepresentationModelProcessor(prop.propertyValue); + return EntityModel.of(prop.propertyValue); } throw new ResourceNotFoundException(); diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/alps/RootResourceInformationToAlpsDescriptorConverter.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/alps/RootResourceInformationToAlpsDescriptorConverter.java index f669fe42a..304e08fba 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/alps/RootResourceInformationToAlpsDescriptorConverter.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/alps/RootResourceInformationToAlpsDescriptorConverter.java @@ -342,7 +342,7 @@ public class RootResourceInformationToAlpsDescriptorConverter { String href = ProfileController.getPath(configuration, targetTypeMetadata) + "#" + getRepresentationDescriptorId(targetTypeMetadata); - Link link = new Link(href).withSelfRel(); + Link link = Link.of(href).withSelfRel(); builder.// type(Type.SAFE).// diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/convert/UriListHttpMessageConverter.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/convert/UriListHttpMessageConverter.java index 28d021d38..68a255f66 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/convert/UriListHttpMessageConverter.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/convert/UriListHttpMessageConverter.java @@ -99,7 +99,7 @@ public class UriListHttpMessageConverter implements HttpMessageConverter associationLinks = links.getLinksFor(property.getRequiredAssociation(), new Path("/base")); assertThat(associationLinks).hasSize(1); - assertThat(associationLinks).contains(new Link("/base/property", "property")); + assertThat(associationLinks).contains(Link.of("/base/property", "property")); } @Test // DATAREST-262 diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/PersistentEntityResourceUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/PersistentEntityResourceUnitTests.java index 32605949f..62b4c9fc6 100755 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/PersistentEntityResourceUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/PersistentEntityResourceUnitTests.java @@ -43,7 +43,7 @@ public class PersistentEntityResourceUnitTests { @Mock PersistentEntity entity; CollectionModel resources; - Link link = new Link("http://localhost", "foo"); + Link link = Link.of("http://localhost", "foo"); @Before public void setUp() { diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositoryPropertyReferenceControllerUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositoryPropertyReferenceControllerUnitTests.java index 1c8637244..25279dd6d 100755 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositoryPropertyReferenceControllerUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/RepositoryPropertyReferenceControllerUnitTests.java @@ -84,7 +84,7 @@ public class RepositoryPropertyReferenceControllerUnitTests { doReturn(new Sample()).when(invoker).invokeSave(any(Object.class)); RootResourceInformation information = new RootResourceInformation(metadata, entity, invoker); - CollectionModel request = new CollectionModel(Collections.emptySet(), new Link("/reference/some-id")); + CollectionModel request = new CollectionModel(Collections.emptySet(), Link.of("/reference/some-id")); controller.createPropertyReference(information, HttpMethod.POST, request, 4711, "references"); diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/mapping/AssociationsUnitTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/mapping/AssociationsUnitTests.java index 05c0d2a99..0138e93c1 100755 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/mapping/AssociationsUnitTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/mapping/AssociationsUnitTests.java @@ -122,7 +122,7 @@ public class AssociationsUnitTests { List links = associations.getLinksFor(getAssociation(Root.class, "relatedAndExported"), new Path("")); assertThat(links).hasSize(1); - assertThat(links).contains(new Link("/relatedAndExported", "relatedAndExported")); + assertThat(links).contains(Link.of("/relatedAndExported", "relatedAndExported")); } @Test @@ -144,7 +144,7 @@ public class AssociationsUnitTests { List links = associations.getLinksFor(getAssociation(Root.class, "relatedAndExported"), new Path("")); assertThat(links).hasSize(1); - assertThat(links).contains(new Link("/relatedAndExported{?" + projectionParameterName + "}", "relatedAndExported")); + assertThat(links).contains(Link.of("/relatedAndExported{?" + projectionParameterName + "}", "relatedAndExported")); } private Association> getAssociation(Class type, String name) {