11/*
2- * Copyright 2002-2016 the original author or authors.
2+ * Copyright 2002-2017 the original author or authors.
33 *
44 * Licensed under the Apache License, Version 2.0 (the "License");
55 * you may not use this file except in compliance with the License.
1616
1717package org .springframework .test .web .client ;
1818
19+ import java .net .SocketException ;
20+
1921import org .junit .Test ;
2022
2123import org .springframework .test .web .client .MockRestServiceServer .MockRestServiceServerBuilder ;
2224import org .springframework .web .client .RestTemplate ;
2325
24- import static org .springframework .test .web .client .match .MockRestRequestMatchers .requestTo ;
25- import static org .springframework .test .web .client .response .MockRestResponseCreators .withSuccess ;
26+ import static org .springframework .http .HttpMethod .*;
27+ import static org .springframework .test .web .client .match .MockRestRequestMatchers .*;
28+ import static org .springframework .test .web .client .response .MockRestResponseCreators .*;
2629
2730/**
2831 * Unit tests for {@link MockRestServiceServer}.
32+ *
2933 * @author Rossen Stoyanchev
3034 */
3135public class MockRestServiceServerTests {
3236
33- private RestTemplate restTemplate = new RestTemplate ();
37+ private final RestTemplate restTemplate = new RestTemplate ();
3438
3539
3640 @ Test
37- public void buildMultipleTimes () throws Exception {
41+ public void buildMultipleTimes () {
3842 MockRestServiceServerBuilder builder = MockRestServiceServer .bindTo (this .restTemplate );
3943
4044 MockRestServiceServer server = builder .build ();
@@ -56,7 +60,7 @@ public void buildMultipleTimes() throws Exception {
5660 }
5761
5862 @ Test (expected = AssertionError .class )
59- public void exactExpectOrder () throws Exception {
63+ public void exactExpectOrder () {
6064 MockRestServiceServer server = MockRestServiceServer .bindTo (this .restTemplate )
6165 .ignoreExpectOrder (false ).build ();
6266
@@ -66,7 +70,7 @@ public void exactExpectOrder() throws Exception {
6670 }
6771
6872 @ Test
69- public void ignoreExpectOrder () throws Exception {
73+ public void ignoreExpectOrder () {
7074 MockRestServiceServer server = MockRestServiceServer .bindTo (this .restTemplate )
7175 .ignoreExpectOrder (true ).build ();
7276
@@ -78,7 +82,7 @@ public void ignoreExpectOrder() throws Exception {
7882 }
7983
8084 @ Test
81- public void resetAndReuseServer () throws Exception {
85+ public void resetAndReuseServer () {
8286 MockRestServiceServer server = MockRestServiceServer .bindTo (this .restTemplate ).build ();
8387
8488 server .expect (requestTo ("/foo" )).andRespond (withSuccess ());
@@ -92,7 +96,7 @@ public void resetAndReuseServer() throws Exception {
9296 }
9397
9498 @ Test
95- public void resetAndReuseServerWithUnorderedExpectationManager () throws Exception {
99+ public void resetAndReuseServerWithUnorderedExpectationManager () {
96100 MockRestServiceServer server = MockRestServiceServer .bindTo (this .restTemplate )
97101 .ignoreExpectOrder (true ).build ();
98102
@@ -108,4 +112,24 @@ public void resetAndReuseServerWithUnorderedExpectationManager() throws Exceptio
108112 server .verify ();
109113 }
110114
115+ @ Test // SPR-16132
116+ public void followUpRequestAfterFailure () {
117+ MockRestServiceServer server = MockRestServiceServer .bindTo (this .restTemplate ).build ();
118+
119+ server .expect (requestTo ("/some-service/some-endpoint" ))
120+ .andRespond (request -> { throw new SocketException ("pseudo network error" ); });
121+
122+ server .expect (requestTo ("/reporting-service/report-error" ))
123+ .andExpect (method (POST )).andRespond (withSuccess ());
124+
125+ try {
126+ this .restTemplate .getForEntity ("/some-service/some-endpoint" , String .class );
127+ }
128+ catch (Exception ex ) {
129+ this .restTemplate .postForEntity ("/reporting-service/report-error" , ex .toString (), String .class );
130+ }
131+
132+ server .verify ();
133+ }
134+
111135}
0 commit comments