SPR-5973: now dealing with path followed by segments (and vice-versa) correctly.

This commit is contained in:
Arjen Poutsma
2011-09-15 10:24:21 +00:00
parent 1300da06a6
commit aeba9d244a
4 changed files with 132 additions and 21 deletions

View File

@@ -138,6 +138,42 @@ public class UriComponentsBuilderTests {
assertEquals(Arrays.asList("foo", "bar"), result.getPathSegments());
}
@Test
public void pathThenPath() {
UriComponentsBuilder builder = UriComponentsBuilder.fromPath("/foo/bar").path("ba/z");
UriComponents result = builder.build().encode();
assertEquals("/foo/barba/z", result.getPath());
assertEquals(Arrays.asList("foo", "barba", "z"), result.getPathSegments());
}
@Test
public void pathThenPathSegments() {
UriComponentsBuilder builder = UriComponentsBuilder.fromPath("/foo/bar").pathSegment("ba/z");
UriComponents result = builder.build().encode();
assertEquals("/foo/bar/ba%2Fz", result.getPath());
assertEquals(Arrays.asList("foo", "bar", "ba%2Fz"), result.getPathSegments());
}
@Test
public void pathSegmentsThenPathSegments() {
UriComponentsBuilder builder = UriComponentsBuilder.newInstance().pathSegment("foo").pathSegment("bar");
UriComponents result = builder.build();
assertEquals("/foo/bar", result.getPath());
assertEquals(Arrays.asList("foo", "bar"), result.getPathSegments());
}
@Test
public void pathSegmentsThenPath() {
UriComponentsBuilder builder = UriComponentsBuilder.newInstance().pathSegment("foo").path("/");
UriComponents result = builder.build();
assertEquals("/foo/", result.getPath());
assertEquals(Arrays.asList("foo"), result.getPathSegments());
}
@Test
public void queryParams() throws URISyntaxException {
UriComponentsBuilder builder = UriComponentsBuilder.newInstance();

View File

@@ -45,5 +45,13 @@ public class UriComponentsTests {
UriComponents uriComponents = UriComponentsBuilder.fromUriString("http://example.com/hotel list/Z\u00fcrich").build();
assertEquals(new URI("http://example.com/hotel%20list/Z\u00fcrich"), uriComponents.toUri());
}
@Test
public void expand() {
UriComponents uriComponents = UriComponentsBuilder.fromUriString("http://example.com").path("/{foo} {bar}").build();
uriComponents = uriComponents.expand("1 2", "3 4");
assertEquals("/1 2 3 4", uriComponents.getPath());
assertEquals("http://example.com/1 2 3 4", uriComponents.toUriString());
}
}