Closed
Description
Réda Housni Alaoui opened DATACMNS-1757 and commented
Let's consider the following test:
@Test
@DisplayName("GET with pageable and additional request parameter")
public void test2() throws Exception {
mockMvc
.perform(
MockMvcRequestBuilders.get("/api/PagedResourcesAssemblerTest")
.queryParam("text", "foo")
.queryParam("page_size", "1")
.queryParam("page_number", "1"))
.andExpect(status().isOk())
.andExpect(jsonPath("$._links.first.href").value(containsString("text=foo")));
}
@Controller
@RequestMapping("/PagedResourcesAssemblerTest")
public static class MyController {
@GetMapping
public ResponseEntity<?> get(
@RequestParam(name = "text", required = false) String text,
Pageable pageable,
PagedResourcesAssembler<Element> pageAssembler) {
Page<Element> page =
new PageImpl<>(Collections.singletonList(new Element("foo")), pageable, 10);
return ResponseEntity.ok(pageAssembler.toModel(page));
}
}
The described test fails because the generate response body is:
{
"_embedded": {
"content": [{
"name": "foo"
}]
},
"_links": {
"first": {
"href": "http://localhost/api/PagedResourcesAssemblerTest?page_number=0&page_size=1"
},
"prev": {
"href": "http://localhost/api/PagedResourcesAssemblerTest?page_number=0&page_size=1"
},
"self": {
"href": "http://localhost/api/PagedResourcesAssemblerTest?page_number=1&page_size=1"
},
"next": {
"href": "http://localhost/api/PagedResourcesAssemblerTest?page_number=2&page_size=1"
},
"last": {
"href": "http://localhost/api/PagedResourcesAssemblerTest?page_number=9&page_size=1"
}
},
"page": {
"size": 1,
"totalElements": 10,
"totalPages": 10,
"number": 1
}
}
The navigation links hold the correct page parameters, but they are missing request parameter text.
Affects: 2.4 M1 (2020.0.0)
Referenced from: pull request #452