SPR-8020 Support UriComponentsBuilder as a controller method argument.
The UriComponentsBuilder instance passed into the method is initialized with current request information including host, scheme, port, context path, and the servlet mapping's literal part. Also added shortcut methods to buildAndExpand in UriComponentsBuilder.
This commit is contained in:
@@ -16,17 +16,19 @@
|
||||
|
||||
package org.springframework.web.util;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.util.LinkedMultiValueMap;
|
||||
import org.springframework.util.MultiValueMap;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
/** @author Arjen Poutsma */
|
||||
public class UriComponentsBuilderTests {
|
||||
|
||||
@@ -227,7 +229,6 @@ public class UriComponentsBuilderTests {
|
||||
assertEquals(expectedQueryParams, result.getQueryParams());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void replaceQueryParam() {
|
||||
UriComponentsBuilder builder = UriComponentsBuilder.newInstance().queryParam("baz", "qux", 42);
|
||||
@@ -243,4 +244,15 @@ public class UriComponentsBuilderTests {
|
||||
assertNull("Query param should have been deleted", result.getQuery());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void buildAndExpand() {
|
||||
UriComponents result = UriComponentsBuilder.fromPath("/{foo}").buildAndExpand("fooValue");
|
||||
assertEquals("/fooValue", result.toUriString());
|
||||
|
||||
Map<String, String> values = new HashMap<String, String>();
|
||||
values.put("foo", "fooValue");
|
||||
values.put("bar", "barValue");
|
||||
result = UriComponentsBuilder.fromPath("/{foo}/{bar}").buildAndExpand(values);
|
||||
assertEquals("/fooValue/barValue", result.toUriString());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -62,7 +62,6 @@ public class UriComponentsTests {
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
public void invalidCharacters() {
|
||||
UriComponentsBuilder.fromPath("/{foo}").build(true);
|
||||
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
|
||||
Reference in New Issue
Block a user