Skip to content

Test case for spring-projects#1728 - path variable rendered as empty string #2080

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: 2.1.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -162,6 +159,37 @@ void createsLinkToControllerMethodWithMultiValueMapRequestParam() {
.endsWith("/sample/multivaluemapsupport?key1=value1a&key1=value1b&key2=value2a&key2=value2b");
}

/**
* @see #1728
*/
@Test
void createsLinkToControllerMethodWithListRequestParam() {

List<String> 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
*/
Expand Down Expand Up @@ -197,6 +225,9 @@ interface SampleController {

@RequestMapping("/sample/multivaluemapsupport")
HttpEntity<?> sampleMethodWithMap(@RequestParam MultiValueMap<String, String> queryParams);

@RequestMapping("/sample/listsupport")
HttpEntity<?> sampleMethodWithList(@RequestParam List<String> queryParams);
}

static class SampleUriComponentsContributor implements UriComponentsContributor {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,8 @@ public CollectionModel<EntityModel<Employee>> 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()) //
Expand Down Expand Up @@ -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<String> params
) {
return ResponseEntity.noContent().build();
}
}