diff --git a/src/test/java/org/springframework/hateoas/mediatype/hal/forms/HalFormsWebMvcIntegrationTest.java b/src/test/java/org/springframework/hateoas/mediatype/hal/forms/HalFormsWebMvcIntegrationTest.java index dac383564..de803484e 100644 --- a/src/test/java/org/springframework/hateoas/mediatype/hal/forms/HalFormsWebMvcIntegrationTest.java +++ b/src/test/java/org/springframework/hateoas/mediatype/hal/forms/HalFormsWebMvcIntegrationTest.java @@ -104,12 +104,16 @@ void collectionOfEmployees() throws Exception { .andExpect(jsonPath("$._links.*", hasSize(1))) .andExpect(jsonPath("$._links['self'].href", is("http://localhost/employees"))) - .andExpect(jsonPath("$._templates.*", hasSize(1))) + .andExpect(jsonPath("$._templates.*", hasSize(2))) .andExpect(jsonPath("$._templates['default'].method", is("POST"))) .andExpect(jsonPath("$._templates['default'].properties[0].name", is("name"))) .andExpect(jsonPath("$._templates['default'].properties[0].required").value(true)) .andExpect(jsonPath("$._templates['default'].properties[1].name", is("role"))) - .andExpect(jsonPath("$._templates['default'].properties[1].required").doesNotExist()); + .andExpect(jsonPath("$._templates['default'].properties[1].required").doesNotExist()) + + // @see #1728 + .andExpect(jsonPath("$._templates['anotherOperation'].method", is("POST"))) + .andExpect(jsonPath("$._templates['anotherOperation'].target", is("http://localhost/anotherOperation?params={params}"))); } @Test diff --git a/src/test/java/org/springframework/hateoas/server/mvc/WebMvcLinkBuilderFactoryUnitTest.java b/src/test/java/org/springframework/hateoas/server/mvc/WebMvcLinkBuilderFactoryUnitTest.java index b457f4839..97897c54a 100644 --- a/src/test/java/org/springframework/hateoas/server/mvc/WebMvcLinkBuilderFactoryUnitTest.java +++ b/src/test/java/org/springframework/hateoas/server/mvc/WebMvcLinkBuilderFactoryUnitTest.java @@ -20,10 +20,7 @@ import java.time.LocalDateTime; import java.time.format.DateTimeFormatter; -import java.util.Arrays; -import java.util.Collections; -import java.util.LinkedHashMap; -import java.util.Map; +import java.util.*; import org.junit.jupiter.api.Test; import org.springframework.core.MethodParameter; @@ -162,6 +159,37 @@ void createsLinkToControllerMethodWithMultiValueMapRequestParam() { .endsWith("/sample/multivaluemapsupport?key1=value1a&key1=value1b&key2=value2a&key2=value2b"); } + /** + * @see #1728 + */ + @Test + void createsLinkToControllerMethodWithListRequestParam() { + + List queryParams = new ArrayList<>(); + queryParams.add("value1"); + queryParams.add("value2"); + + Link link = factory.linkTo(methodOn(SampleController.class).sampleMethodWithList(queryParams)).withSelfRel(); + + assertPointsToMockServer(link); + assertThat(link.getRel()).isEqualTo(IanaLinkRelations.SELF); + assertThat(link.getHref()) // + .endsWith("/sample/listsupport?queryParams=value1&queryParams=value2"); + } + + /** + * @see #1728 + */ + @Test + void createsLinkToControllerMethodWithNullListRequestParam() { + Link link = factory.linkTo(methodOn(SampleController.class).sampleMethodWithList(null)).withSelfRel(); + + assertPointsToMockServer(link); + assertThat(link.getRel()).isEqualTo(IanaLinkRelations.SELF); + assertThat(link.getHref()) // + .endsWith("/sample/listsupport?queryParams={queryParams}"); + } + /** * @see #372 */ @@ -197,6 +225,9 @@ interface SampleController { @RequestMapping("/sample/multivaluemapsupport") HttpEntity sampleMethodWithMap(@RequestParam MultiValueMap queryParams); + + @RequestMapping("/sample/listsupport") + HttpEntity sampleMethodWithList(@RequestParam List queryParams); } static class SampleUriComponentsContributor implements UriComponentsContributor { diff --git a/src/test/java/org/springframework/hateoas/support/WebMvcEmployeeController.java b/src/test/java/org/springframework/hateoas/support/WebMvcEmployeeController.java index ae3f3e531..ab0272e58 100644 --- a/src/test/java/org/springframework/hateoas/support/WebMvcEmployeeController.java +++ b/src/test/java/org/springframework/hateoas/support/WebMvcEmployeeController.java @@ -75,7 +75,8 @@ public CollectionModel> all() { Link selfLink = linkTo(controller.all()).withSelfRel() // .andAffordance(afford(controller.newEmployee(null))) // - .andAffordance(afford(controller.search(null, null))); + .andAffordance(afford(controller.search(null, null))) + .andAffordance(afford(controller.anotherOperation(null))); // Return the collection of employee resources along with the composite affordance return IntStream.range(0, EMPLOYEES.size()) // @@ -224,4 +225,14 @@ public ResponseEntity problem() { .withStatus(HttpStatus.BAD_REQUEST) // .withDetail("This is a test case")); } + + /** + * @see #1728 + */ + @PostMapping("/anotherOperation") + public ResponseEntity anotherOperation( + @RequestParam List params + ) { + return ResponseEntity.noContent().build(); + } }