@ -42,6 +42,18 @@ public class MockMvcResultMatchersTests {
@@ -42,6 +42,18 @@ public class MockMvcResultMatchersTests {
redirectedUrl ( "/resource/1" ) . match ( getRedirectedUrlStubMvcResult ( "/resource/1" ) ) ;
}
@Test
public void redirectNonMatching ( ) {
assertThatExceptionOfType ( AssertionError . class ) . isThrownBy ( ( ) - >
redirectedUrl ( "/resource/2" ) . match ( getRedirectedUrlStubMvcResult ( "/resource/1" ) ) ) ;
}
@Test
public void redirectNonMatchingBecauseNotRedirect ( ) {
assertThatExceptionOfType ( AssertionError . class ) . isThrownBy ( ( ) - >
redirectedUrl ( "/resource/1" ) . match ( getForwardedUrlStubMvcResult ( "/resource/1" ) ) ) ;
}
@Test
public void redirectWithUrlTemplate ( ) throws Exception {
redirectedUrlTemplate ( "/orders/{orderId}/items/{itemId}" , 1 , 2 ) . match ( getRedirectedUrlStubMvcResult ( "/orders/1/items/2" ) ) ;
@ -58,11 +70,29 @@ public class MockMvcResultMatchersTests {
@@ -58,11 +70,29 @@ public class MockMvcResultMatchersTests {
redirectedUrlPattern ( "/resource/" ) . match ( getRedirectedUrlStubMvcResult ( "/resource/1" ) ) ) ;
}
@Test
public void redirectWithNonMatchingPatternBecauseNotRedirect ( ) {
assertThatExceptionOfType ( AssertionError . class ) . isThrownBy ( ( ) - >
redirectedUrlPattern ( "/resource/*" ) . match ( getForwardedUrlStubMvcResult ( "/resource/1" ) ) ) ;
}
@Test
public void forward ( ) throws Exception {
forwardedUrl ( "/api/resource/1" ) . match ( getForwardedUrlStubMvcResult ( "/api/resource/1" ) ) ;
}
@Test
public void forwardNonMatching ( ) {
assertThatExceptionOfType ( AssertionError . class ) . isThrownBy ( ( ) - >
forwardedUrlPattern ( "api/resource/2" ) . match ( getForwardedUrlStubMvcResult ( "api/resource/1" ) ) ) ;
}
@Test
public void forwardNonMatchingBecauseNotForward ( ) {
assertThatExceptionOfType ( AssertionError . class ) . isThrownBy ( ( ) - >
forwardedUrlPattern ( "api/resource/1" ) . match ( getRedirectedUrlStubMvcResult ( "api/resource/1" ) ) ) ;
}
@Test
public void forwardWithQueryString ( ) throws Exception {
forwardedUrl ( "/api/resource/1?arg=value" ) . match ( getForwardedUrlStubMvcResult ( "/api/resource/1?arg=value" ) ) ;
@ -84,6 +114,12 @@ public class MockMvcResultMatchersTests {
@@ -84,6 +114,12 @@ public class MockMvcResultMatchersTests {
forwardedUrlPattern ( "/resource/" ) . match ( getForwardedUrlStubMvcResult ( "/resource/1" ) ) ) ;
}
@Test
public void forwardWithNonMatchingPatternBecauseNotForward ( ) {
assertThatExceptionOfType ( AssertionError . class ) . isThrownBy ( ( ) - >
forwardedUrlPattern ( "/resource/*" ) . match ( getRedirectedUrlStubMvcResult ( "/resource/1" ) ) ) ;
}
private StubMvcResult getRedirectedUrlStubMvcResult ( String redirectUrl ) throws Exception {
MockHttpServletResponse response = new MockHttpServletResponse ( ) ;
response . sendRedirect ( redirectUrl ) ;