#24406 - Add String based URI template variants
This commit is contained in:
committed by
Rossen Stoyanchev
parent
d1708460e7
commit
816466e492
@@ -27,7 +27,10 @@ import java.util.Map;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import org.springframework.core.ParameterizedTypeReference;
|
||||
import org.springframework.web.util.DefaultUriBuilderFactory;
|
||||
import org.springframework.web.util.UriComponentsBuilder;
|
||||
import org.springframework.web.util.UriTemplate;
|
||||
import org.springframework.web.util.UriTemplateHandler;
|
||||
|
||||
import static org.assertj.core.api.Assertions.assertThat;
|
||||
|
||||
@@ -35,6 +38,7 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
* Unit tests for {@link org.springframework.http.RequestEntity}.
|
||||
*
|
||||
* @author Arjen Poutsma
|
||||
* @author Parviz Rozikov
|
||||
*/
|
||||
public class RequestEntityTests {
|
||||
|
||||
@@ -79,6 +83,34 @@ public class RequestEntityTests {
|
||||
assertThat(entity.getUrl()).isEqualTo(expected);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void uriExpansion() throws URISyntaxException{
|
||||
String template = "/foo?bar={bar}";
|
||||
String bar = "foo";
|
||||
URI expected = new URI("/foo?bar=foo");
|
||||
|
||||
RequestEntity<Void> entity = RequestEntity.get(template).uriVariables(bar).build();
|
||||
|
||||
assertThat(entity.getUrl()).isEqualTo(expected);
|
||||
|
||||
String url = "https://www.{host}.com/{path}";
|
||||
String host = "example";
|
||||
String path = "foo/bar";
|
||||
expected = new URI("https://www.example.com/foo/bar");
|
||||
|
||||
entity = RequestEntity.get(url).uriVariables(host, path).build();
|
||||
DefaultUriBuilderFactory uriTemplateHandler = new DefaultUriBuilderFactory();
|
||||
uriTemplateHandler.setEncodingMode(DefaultUriBuilderFactory.EncodingMode.NONE);
|
||||
|
||||
assertThat(entity.getUrl(uriTemplateHandler)).isEqualTo(expected);
|
||||
|
||||
expected = new URI("https://www.example.com/foo%2Fbar");
|
||||
uriTemplateHandler.setEncodingMode(DefaultUriBuilderFactory.EncodingMode.TEMPLATE_AND_VALUES);
|
||||
|
||||
assertThat(entity.getUrl(uriTemplateHandler)).isEqualTo(expected);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void get() {
|
||||
RequestEntity<Void> requestEntity = RequestEntity.get(URI.create("https://example.com")).accept(
|
||||
|
||||
Reference in New Issue
Block a user