From bc04809bcf7af6202a95e88041b871b07933c2da Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Tue, 14 Apr 2015 22:02:37 +0200 Subject: [PATCH] DATAREST-519 - RepositoryEntityLinks now adds existing Pageable and Sort. --- .../rest/webmvc/support/RepositoryEntityLinks.java | 7 +++++-- .../RepositoryEntityLinksIntegrationTests.java | 12 +++++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/support/RepositoryEntityLinks.java b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/support/RepositoryEntityLinks.java index d0fa1a75a..00e80e636 100644 --- a/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/support/RepositoryEntityLinks.java +++ b/spring-data-rest-webmvc/src/main/java/org/springframework/data/rest/webmvc/support/RepositoryEntityLinks.java @@ -286,14 +286,17 @@ public class RepositoryEntityLinks extends AbstractEntityLinks { return null; } - LinkBuilder builder = linkFor(type).slash(mappings.getSearchResourceMappings(type).getPath()); + LinkBuilder builder = linkFor(type).// + slash(mappings.getSearchResourceMappings(type).getPath()).// + slash(mapping.getPath()); + UriComponents uriComponents = prepareUri(builder.toString(), mapping, pageable, sort); TemplateVariables variables = getParameterVariables(mapping).// concat(getTemplateVariables(uriComponents, mapping, pageable, sort)).// concat(getProjectionVariable(mapping.getReturnedDomainType())); - return new Link(new UriTemplate(builder.slash(mapping.getPath()).toString(), variables), mapping.getRel()); + return new Link(new UriTemplate(uriComponents.toString(), variables), mapping.getRel()); } /** diff --git a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/support/RepositoryEntityLinksIntegrationTests.java b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/support/RepositoryEntityLinksIntegrationTests.java index eb800e401..2b3c9f4ae 100644 --- a/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/support/RepositoryEntityLinksIntegrationTests.java +++ b/spring-data-rest-webmvc/src/test/java/org/springframework/data/rest/webmvc/support/RepositoryEntityLinksIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2014 the original author or authors. + * Copyright 2014-2015 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,6 +31,8 @@ import org.springframework.data.rest.webmvc.jpa.Person; import org.springframework.hateoas.Link; import org.springframework.hateoas.Links; import org.springframework.test.context.ContextConfiguration; +import org.springframework.web.util.UriComponents; +import org.springframework.web.util.UriComponentsBuilder; /** * Integration tests for {@link RepositoryEntityLinks}. @@ -127,6 +129,7 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt /** * @see DATAREST-467 + * @see DATAREST-519 */ @Test public void prepopulatesPaginationInformationForSearchResourceLink() { @@ -137,6 +140,9 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt assertThat(link.isTemplated(), is(true)); assertThat(link.getVariableNames(), hasItem("firstname")); assertThat(link.getVariableNames(), not(hasItems("page", "size"))); + + UriComponents components = UriComponentsBuilder.fromUriString(link.getHref()).build(); + assertThat(components.getQueryParams(), allOf(hasKey("page"), hasKey("size"))); } /** @@ -153,6 +159,7 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt /** * @see DATAREST-467 + * @see DATAREST-519 */ @Test public void prepopulatesSortInformationForSearchResourceLink() { @@ -163,5 +170,8 @@ public class RepositoryEntityLinksIntegrationTests extends AbstractControllerInt assertThat(link.isTemplated(), is(true)); assertThat(link.getVariableNames(), hasItem("lastname")); assertThat(link.getVariableNames(), not(hasItems("sort"))); + + UriComponents components = UriComponentsBuilder.fromUriString(link.getHref()).build(); + assertThat(components.getQueryParams(), hasKey("sort")); } }