From 99f49532b614959dd458df8c4dd3fb65ba1c03bb Mon Sep 17 00:00:00 2001 From: Oliver Gierke Date: Mon, 16 Jan 2017 13:31:45 +0100 Subject: [PATCH] DATAREST-976 - Polishing. Extracted test for the newly supported sorting scenario so that we now. Original pull request: #251. --- .../data/rest/webmvc/jpa/JpaWebTests.java | 27 +++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) 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 791bbb064..b8a952f7f 100644 --- 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 @@ -494,12 +494,12 @@ public class JpaWebTests extends CommonWebTests { assertThat(findBySortedLink.getVariableNames(), hasItems("sort", "projection")); // Assert results returned as specified - client.follow(findBySortedLink.expand("offer.price,desc")).// + client.follow(findBySortedLink.expand("title,desc")).// andExpect(jsonPath("$._embedded.books[0].title").value("Spring Data (Second Edition)")).// andExpect(jsonPath("$._embedded.books[1].title").value("Spring Data")).// andExpect(client.hasLinkWithRel("self")); - client.follow(findBySortedLink.expand("offer.price,asc")).// + client.follow(findBySortedLink.expand("title,asc")).// andExpect(jsonPath("$._embedded.books[0].title").value("Spring Data")).// andExpect(jsonPath("$._embedded.books[1].title").value("Spring Data (Second Edition)")).// andExpect(client.hasLinkWithRel("self")); @@ -627,6 +627,29 @@ public class JpaWebTests extends CommonWebTests { mvc.perform(post("/orders/search/sort?sort=type&page=1&size=10")).andExpect(status().isOk()); } + @Test // DATAREST-976 + public void appliesSortByEmbeddedAssociation() throws Exception { + + Link booksLink = client.discoverUnique("books"); + Link searchLink = client.discoverUnique(booksLink, "search"); + Link findBySortedLink = client.discoverUnique(searchLink, "find-by-sorted"); + + // Assert sort options advertised + assertThat(findBySortedLink.isTemplated(), is(true)); + assertThat(findBySortedLink.getVariableNames(), hasItems("sort", "projection")); + + // Assert results returned as specified + client.follow(findBySortedLink.expand("offer.price,desc")).// + andExpect(jsonPath("$._embedded.books[0].title").value("Spring Data (Second Edition)")).// + andExpect(jsonPath("$._embedded.books[1].title").value("Spring Data")).// + andExpect(client.hasLinkWithRel("self")); + + client.follow(findBySortedLink.expand("offer.price,asc")).// + andExpect(jsonPath("$._embedded.books[0].title").value("Spring Data")).// + andExpect(jsonPath("$._embedded.books[1].title").value("Spring Data (Second Edition)")).// + andExpect(client.hasLinkWithRel("self")); + } + private List preparePersonResources(Person primary, Person... persons) throws Exception { Link peopleLink = client.discoverUnique("people");