@ -81,14 +81,23 @@ public abstract class MockMvcResultMatchers {
@@ -81,14 +81,23 @@ public abstract class MockMvcResultMatchers {
/ * *
* Asserts the request was forwarded to the given URL .
* < p > This method accepts exact matches against the expanded URL template .
* < p > This method accepts only exact matches .
* @param expectedUrl the exact URL expected
* /
public static ResultMatcher forwardedUrl ( String expectedUrl ) {
return result - > assertEquals ( "Forwarded URL" , expectedUrl , result . getResponse ( ) . getForwardedUrl ( ) ) ;
}
/ * *
* Asserts the request was forwarded to the given URL template .
* < p > This method accepts exact matches against the expanded and encoded URL template .
* @param urlTemplate a URL template ; the expanded URL will be encoded
* @param uriVars zero or more URI variables to populate the template
* @see UriComponentsBuilder # fromUriString ( String )
* /
public static ResultMatcher forwardedUrl ( String urlTemplate , Object . . . uriVars ) {
public static ResultMatcher forwardedUrlTemplate ( String urlTemplate , Object . . . uriVars ) {
String uri = UriComponentsBuilder . fromUriString ( urlTemplate ) . buildAndExpand ( uriVars ) . encode ( ) . toUriString ( ) ;
return result - > assertEquals ( "Forwarded URL" , uri , result . getResponse ( ) . getForwardedUrl ( ) ) ;
return forwardedUrl ( uri ) ;
}
/ * *
@ -110,14 +119,23 @@ public abstract class MockMvcResultMatchers {
@@ -110,14 +119,23 @@ public abstract class MockMvcResultMatchers {
/ * *
* Asserts the request was redirected to the given URL .
* < p > This method accepts exact matches against the expanded URL template .
* < p > This method accepts only exact matches .
* @param expectedUrl the exact URL expected
* /
public static ResultMatcher redirectedUrl ( String expectedUrl ) {
return result - > assertEquals ( "Redirected URL" , expectedUrl , result . getResponse ( ) . getRedirectedUrl ( ) ) ;
}
/ * *
* Asserts the request was redirected to the given URL template .
* < p > This method accepts exact matches against the expanded and encoded URL template .
* @param urlTemplate a URL template ; the expanded URL will be encoded
* @param uriVars zero or more URI variables to populate the template
* @see UriComponentsBuilder # fromUriString ( String )
* /
public static ResultMatcher redirectedUrl ( String urlTemplate , Object . . . uriVars ) {
public static ResultMatcher redirectedUrlTemplate ( String urlTemplate , Object . . . uriVars ) {
String uri = UriComponentsBuilder . fromUriString ( urlTemplate ) . buildAndExpand ( uriVars ) . encode ( ) . toUriString ( ) ;
return result - > assertEquals ( "Redirected URL" , uri , result . getResponse ( ) . getRedirectedUrl ( ) ) ;
return redirectedUrl ( uri ) ;
}
/ * *