提交 809189be 编写于 作者: D Drummond Dawson 提交者: Rossen Stoyanchev

URI variables with MockRestRequestMatchers requestToUriTemplate

Issue: SPR-15819
上级 181f002d
......@@ -86,6 +86,18 @@ public abstract class MockRestRequestMatchers {
return request -> assertEquals("Request URI", expectedUri, request.getURI().toString());
}
/**
* Assert the request URI string.
* @param expectedUri the expected URI
* @param uriVars zero or more URI variables to populate the expected URI
* @return the request matcher
*/
public static RequestMatcher requestToUriTemplate(final String expectedUri, final Object... uriVars) {
Assert.notNull(expectedUri, "'uri' must not be null");
String uri = UriComponentsBuilder.fromUriString(expectedUri).buildAndExpand(uriVars).encode().toString();
return request -> assertEquals("Request URI", uri, request.getURI().toString());
}
/**
* Expect a request to the given URI.
* @param uri the expected URI
......
......@@ -45,6 +45,13 @@ public class MockRestRequestMatchersTests {
MockRestRequestMatchers.requestTo("http://foo.com/bar").match(this.request);
}
@Test // SPR-15819
public void requestToUriTemplate() throws Exception {
this.request.setURI(new URI("http://foo.com/bar"));
MockRestRequestMatchers.requestToUriTemplate("http://foo.com/{bar}", "bar").match(this.request);
}
@Test(expected = AssertionError.class)
public void requestToNoMatch() throws Exception {
this.request.setURI(new URI("http://foo.com/bar"));
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册