Skip to content

Commit 99f4953

Browse files
committed
DATAREST-976 - Polishing.
Extracted test for the newly supported sorting scenario so that we now. Original pull request: #251.
1 parent ffe96e4 commit 99f4953

File tree

1 file changed

+25
-2
lines changed
  • spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa

1 file changed

+25
-2
lines changed

spring-data-rest-tests/spring-data-rest-tests-jpa/src/test/java/org/springframework/data/rest/webmvc/jpa/JpaWebTests.java

+25-2
Original file line numberDiff line numberDiff line change
@@ -494,12 +494,12 @@ public void exectuesSearchThatTakesASort() throws Exception {
494494
assertThat(findBySortedLink.getVariableNames(), hasItems("sort", "projection"));
495495

496496
// Assert results returned as specified
497-
client.follow(findBySortedLink.expand("offer.price,desc")).//
497+
client.follow(findBySortedLink.expand("title,desc")).//
498498
andExpect(jsonPath("$._embedded.books[0].title").value("Spring Data (Second Edition)")).//
499499
andExpect(jsonPath("$._embedded.books[1].title").value("Spring Data")).//
500500
andExpect(client.hasLinkWithRel("self"));
501501

502-
client.follow(findBySortedLink.expand("offer.price,asc")).//
502+
client.follow(findBySortedLink.expand("title,asc")).//
503503
andExpect(jsonPath("$._embedded.books[0].title").value("Spring Data")).//
504504
andExpect(jsonPath("$._embedded.books[1].title").value("Spring Data (Second Edition)")).//
505505
andExpect(client.hasLinkWithRel("self"));
@@ -627,6 +627,29 @@ public void callUnmappedCustomRepositoryController() throws Exception {
627627
mvc.perform(post("/orders/search/sort?sort=type&page=1&size=10")).andExpect(status().isOk());
628628
}
629629

630+
@Test // DATAREST-976
631+
public void appliesSortByEmbeddedAssociation() throws Exception {
632+
633+
Link booksLink = client.discoverUnique("books");
634+
Link searchLink = client.discoverUnique(booksLink, "search");
635+
Link findBySortedLink = client.discoverUnique(searchLink, "find-by-sorted");
636+
637+
// Assert sort options advertised
638+
assertThat(findBySortedLink.isTemplated(), is(true));
639+
assertThat(findBySortedLink.getVariableNames(), hasItems("sort", "projection"));
640+
641+
// Assert results returned as specified
642+
client.follow(findBySortedLink.expand("offer.price,desc")).//
643+
andExpect(jsonPath("$._embedded.books[0].title").value("Spring Data (Second Edition)")).//
644+
andExpect(jsonPath("$._embedded.books[1].title").value("Spring Data")).//
645+
andExpect(client.hasLinkWithRel("self"));
646+
647+
client.follow(findBySortedLink.expand("offer.price,asc")).//
648+
andExpect(jsonPath("$._embedded.books[0].title").value("Spring Data")).//
649+
andExpect(jsonPath("$._embedded.books[1].title").value("Spring Data (Second Edition)")).//
650+
andExpect(client.hasLinkWithRel("self"));
651+
}
652+
630653
private List<Link> preparePersonResources(Person primary, Person... persons) throws Exception {
631654

632655
Link peopleLink = client.discoverUnique("people");

0 commit comments

Comments
 (0)