UriComponentsBuilder method to configure URI variables
See Javadoc on UriComponentsBuilder#uriVariables for details. This helps to prepare for SPR-17027 where the MvcUriComponentsBuilder already does a partial expand but was forced to build UriComonents and then create a new UriComponentsBuilder from it to continue. This change makes it possible to stay with the same builder instance. Issue: SPR-17027
This commit is contained in:
@@ -70,19 +70,12 @@ public class UriComponentsTests {
|
||||
@Test
|
||||
public void encodeAndExpandPartially() {
|
||||
|
||||
Map<String, Object> uriVars = new HashMap<>();
|
||||
uriVars.put("city", "Z\u00fcrich");
|
||||
|
||||
UriComponents uri = UriComponentsBuilder
|
||||
.fromPath("/hotel list/{city} specials").queryParam("q", "{value}").encode().build()
|
||||
.expand(name -> uriVars.getOrDefault(name, UriTemplateVariables.SKIP_VALUE));
|
||||
.fromPath("/hotel list/{city} specials").queryParam("q", "{value}").encode()
|
||||
.uriVariables(Collections.singletonMap("city", "Z\u00fcrich"))
|
||||
.build();
|
||||
|
||||
assertEquals("/hotel%20list/Z%C3%BCrich%20specials?q={value}", uri.toString());
|
||||
|
||||
uriVars.put("value", "a+b");
|
||||
uri = uri.expand(uriVars);
|
||||
|
||||
assertEquals("/hotel%20list/Z%C3%BCrich%20specials?q=a%2Bb", uri.toString());
|
||||
assertEquals("/hotel%20list/Z%C3%BCrich%20specials?q=a%2Bb", uri.expand("a+b").toString());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user