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:
Rossen Stoyanchev
2018-07-19 17:11:41 -04:00
parent 28cd6978b5
commit 93b7a4838e
3 changed files with 49 additions and 31 deletions

View File

@@ -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