Add support for URI templates in redirectedUrl() & forwardedUrl()

Prior to this commit, the redirectedUrl() and forwardedUrl() methods in
MockMvcResultMatchers supported fully constructed URLs and URLs
containing Ant-style path patterns. However, URI templates were not
supported for these result matchers even though the request path can be
built using URL templates -- for example, via the get() and post()
methods in MockMvcRequestBuilders.

This commit addresses this shortcoming by allowing users to supply a
URL template instead of a fully constructed URL to redirectedUrl() and
forwardedUrl(). To populate the URL template, template variables may be
supplied to redirectedUrl() and forwardedUrl() as var-args.

Issue: SPR-14790
This commit is contained in:
Sam Brannen
2016-10-13 16:50:40 +02:00
parent 509796a4b5
commit a795fd4714
2 changed files with 25 additions and 8 deletions

View File

@@ -36,6 +36,11 @@ public class MockMvcResultMatchersTests {
redirectedUrl("/resource/1").match(getRedirectedUrlStubMvcResult("/resource/1"));
}
@Test
public void redirectWithUrlTemplate() throws Exception {
redirectedUrl("/orders/{orderId}/items/{itemId}", 1, 2).match(getRedirectedUrlStubMvcResult("/orders/1/items/2"));
}
@Test
public void redirectWithMatchingPattern() throws Exception {
redirectedUrlPattern("/resource/*").match(getRedirectedUrlStubMvcResult("/resource/1"));
@@ -56,6 +61,11 @@ public class MockMvcResultMatchersTests {
forwardedUrl("/api/resource/1?arg=value").match(getForwardedUrlStubMvcResult("/api/resource/1?arg=value"));
}
@Test
public void forwardWithUrlTemplate() throws Exception {
forwardedUrl("/orders/{orderId}/items/{itemId}", 1, 2).match(getForwardedUrlStubMvcResult("/orders/1/items/2"));
}
@Test
public void forwardWithMatchingPattern() throws Exception {
forwardedUrlPattern("/api/**/?").match(getForwardedUrlStubMvcResult("/api/resource/1"));