URI variables with MockRestRequestMatchers requestToUriTemplate
Issue: SPR-15819
This commit is contained in:
parent
181f002ddf
commit
809189be1a
|
|
@ -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"));
|
||||
|
|
|
|||
Loading…
Reference in New Issue