Add defaultUriVariables property to RestTemplate

Issue: SPR-14147
This commit is contained in:
Rossen Stoyanchev
2016-04-22 16:18:26 -04:00
parent 0d007a328b
commit 065b7968a3
4 changed files with 109 additions and 5 deletions

View File

@@ -49,6 +49,22 @@ public class DefaultUriTemplateHandlerTests {
assertEquals("http://localhost:8080/context/myapiresource", actual.toString());
}
@Test // SPR-14147
public void defaultUriVariables() throws Exception {
Map<String, String> defaultVars = new HashMap<>(2);
defaultVars.put("host", "api.example.com");
defaultVars.put("port", "443");
this.handler.setDefaultUriVariables(defaultVars);
Map<String, Object> vars = new HashMap<>(1);
vars.put("id", 123L);
String template = "https://{host}:{port}/v42/customers/{id}";
URI actual = this.handler.expand(template, vars);
assertEquals("https://api.example.com:443/v42/customers/123", actual.toString());
}
@Test
public void parsePathIsOff() throws Exception {
this.handler.setParsePath(false);
@@ -114,4 +130,20 @@ public class DefaultUriTemplateHandlerTests {
assertEquals("http://www.example.com/user/john%3Bdoe/dashboard", actual.toString());
}
@Test // SPR-14147
public void strictEncodingAndDefaultUriVariables() throws Exception {
Map<String, String> defaultVars = new HashMap<>(1);
defaultVars.put("host", "www.example.com");
this.handler.setDefaultUriVariables(defaultVars);
this.handler.setStrictEncoding(true);
Map<String, Object> vars = new HashMap<>(1);
vars.put("userId", "john;doe");
String template = "http://{host}/user/{userId}/dashboard";
URI actual = this.handler.expand(template, vars);
assertEquals("http://www.example.com/user/john%3Bdoe/dashboard", actual.toString());
}
}