diff --git a/pom.xml b/pom.xml
index 15f16c1eed..59382dfd2a 100644
--- a/pom.xml
+++ b/pom.xml
@@ -22,6 +22,8 @@
1.4.22
spring.data.commons
+
+ 1.1.0.0.cosium
diff --git a/src/main/java/org/springframework/data/web/HateoasPageableHandlerMethodArgumentResolver.java b/src/main/java/org/springframework/data/web/HateoasPageableHandlerMethodArgumentResolver.java
index 20e3c01630..6ab0131f7c 100644
--- a/src/main/java/org/springframework/data/web/HateoasPageableHandlerMethodArgumentResolver.java
+++ b/src/main/java/org/springframework/data/web/HateoasPageableHandlerMethodArgumentResolver.java
@@ -40,6 +40,7 @@
* @since 1.6
* @author Oliver Gierke
* @author Nick Williams
+ * @author Réda Housni Alaoui
*/
@SuppressWarnings("null")
public class HateoasPageableHandlerMethodArgumentResolver extends PageableHandlerMethodArgumentResolver
@@ -129,6 +130,11 @@ public void enhance(UriComponentsBuilder builder, @Nullable MethodParameter para
this.sortResolver.enhance(builder, parameter, pageable.getSort());
}
+ @Override
+ public TemplateVariables enhance(TemplateVariables templateVariables, UriComponents uriComponents, MethodParameter parameter) {
+ return templateVariables.concat(getPaginationTemplateVariables(parameter, uriComponents));
+ }
+
private static HateoasSortHandlerMethodArgumentResolver getDefaultedSortResolver(
@Nullable HateoasSortHandlerMethodArgumentResolver sortResolver) {
return sortResolver == null ? DEFAULT_SORT_RESOLVER : sortResolver;
diff --git a/src/main/java/org/springframework/data/web/HateoasSortHandlerMethodArgumentResolver.java b/src/main/java/org/springframework/data/web/HateoasSortHandlerMethodArgumentResolver.java
index 6ec0c7c487..a5033a554f 100644
--- a/src/main/java/org/springframework/data/web/HateoasSortHandlerMethodArgumentResolver.java
+++ b/src/main/java/org/springframework/data/web/HateoasSortHandlerMethodArgumentResolver.java
@@ -36,6 +36,7 @@
* @author Oliver Gierke
* @author Thomas Darimont
* @author Nick Williams
+ * @author Réda Housni Alaoui
*/
public class HateoasSortHandlerMethodArgumentResolver extends SortHandlerMethodArgumentResolver
implements UriComponentsContributor {
@@ -82,4 +83,9 @@ public void enhance(UriComponentsBuilder builder, @Nullable MethodParameter para
builder.queryParam(sortParameter, expression);
}
}
+
+ @Override
+ public TemplateVariables enhance(TemplateVariables templateVariables, UriComponents uriComponents, MethodParameter parameter) {
+ return templateVariables.concat(getSortTemplateVariables(parameter, uriComponents));
+ }
}
diff --git a/src/test/java/org/springframework/data/web/HateoasPageableHandlerMethodArgumentResolverUnitTests.java b/src/test/java/org/springframework/data/web/HateoasPageableHandlerMethodArgumentResolverUnitTests.java
index 45fb8487d7..d29e6944c3 100755
--- a/src/test/java/org/springframework/data/web/HateoasPageableHandlerMethodArgumentResolverUnitTests.java
+++ b/src/test/java/org/springframework/data/web/HateoasPageableHandlerMethodArgumentResolverUnitTests.java
@@ -23,6 +23,7 @@
import org.springframework.core.MethodParameter;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
+import org.springframework.hateoas.TemplateVariables;
import org.springframework.hateoas.server.mvc.UriComponentsContributor;
import org.springframework.util.MultiValueMap;
import org.springframework.web.util.UriComponents;
@@ -32,6 +33,7 @@
* Unit tests for {@link HateoasPageableHandlerMethodArgumentResolver}.
*
* @author Oliver Gierke
+ * @author Réda Housni Alaoui
*/
class HateoasPageableHandlerMethodArgumentResolverUnitTests
extends PageableHandlerMethodArgumentResolverUnitTests {
@@ -119,6 +121,18 @@ void enhancesUnpaged() {
assertThat(builder).isEqualTo(builder);
}
+ @Test // DATACMNS-1752
+ void enhanceTemplateVariables() {
+
+ UriComponents uriComponents = UriComponentsBuilder.fromPath("/foo").build();
+
+ HateoasPageableHandlerMethodArgumentResolver resolver = getResolver();
+ resolver.setPageParameterName("foo");
+ String variables = resolver.enhance(TemplateVariables.NONE, uriComponents, null).toString();
+
+ assertThat(variables).isEqualTo("{?foo,size,sort}");
+ }
+
@Override
protected HateoasPageableHandlerMethodArgumentResolver getResolver() {
diff --git a/src/test/java/org/springframework/data/web/HateoasSortHandlerMethodArgumentResolverUnitTests.java b/src/test/java/org/springframework/data/web/HateoasSortHandlerMethodArgumentResolverUnitTests.java
index 6e32c5ed72..6b2213a44a 100755
--- a/src/test/java/org/springframework/data/web/HateoasSortHandlerMethodArgumentResolverUnitTests.java
+++ b/src/test/java/org/springframework/data/web/HateoasSortHandlerMethodArgumentResolverUnitTests.java
@@ -23,6 +23,7 @@
import org.junit.jupiter.api.Test;
import org.springframework.core.MethodParameter;
import org.springframework.data.domain.Sort;
+import org.springframework.hateoas.TemplateVariables;
import org.springframework.web.util.UriComponents;
import org.springframework.web.util.UriComponentsBuilder;
@@ -30,6 +31,7 @@
* Unit tests for {@link HateoasSortHandlerMethodArgumentResolver}
*
* @author Oliver Gierke
+ * @author Réda Housni Alaoui
*/
class HateoasSortHandlerMethodArgumentResolverUnitTests extends SortHandlerMethodArgumentResolverUnitTests {
@@ -57,6 +59,15 @@ void returnCorrectTemplateVariables() {
assertThat(resolver.getSortTemplateVariables(null, uriComponents).toString()).isEqualTo("{?sort}");
}
+ @Test // DATACMNS-1752
+ void enhanceTemplateVariables(){
+
+ UriComponents uriComponents = UriComponentsBuilder.fromPath("/").build();
+
+ HateoasSortHandlerMethodArgumentResolver resolver = new HateoasSortHandlerMethodArgumentResolver();
+ assertThat(resolver.enhance(TemplateVariables.NONE, uriComponents, null).toString()).isEqualTo("{?sort}");
+ }
+
private void assertUriStringFor(Sort sort, String expected) throws Exception {
assertUriStringFor(sort, expected, "/");
}