1
1
/*
2
- * Copyright 2002-2016 the original author or authors.
2
+ * Copyright 2002-2017 the original author or authors.
3
3
*
4
4
* Licensed under the Apache License, Version 2.0 (the "License");
5
5
* you may not use this file except in compliance with the License.
16
16
17
17
package org .springframework .test .web .client ;
18
18
19
+ import java .net .SocketException ;
20
+
19
21
import org .junit .Test ;
20
22
21
23
import org .springframework .test .web .client .MockRestServiceServer .MockRestServiceServerBuilder ;
22
24
import org .springframework .web .client .RestTemplate ;
23
25
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 .*;
26
29
27
30
/**
28
31
* Unit tests for {@link MockRestServiceServer}.
32
+ *
29
33
* @author Rossen Stoyanchev
30
34
*/
31
35
public class MockRestServiceServerTests {
32
36
33
- private RestTemplate restTemplate = new RestTemplate ();
37
+ private final RestTemplate restTemplate = new RestTemplate ();
34
38
35
39
36
40
@ Test
37
- public void buildMultipleTimes () throws Exception {
41
+ public void buildMultipleTimes () {
38
42
MockRestServiceServerBuilder builder = MockRestServiceServer .bindTo (this .restTemplate );
39
43
40
44
MockRestServiceServer server = builder .build ();
@@ -56,7 +60,7 @@ public void buildMultipleTimes() throws Exception {
56
60
}
57
61
58
62
@ Test (expected = AssertionError .class )
59
- public void exactExpectOrder () throws Exception {
63
+ public void exactExpectOrder () {
60
64
MockRestServiceServer server = MockRestServiceServer .bindTo (this .restTemplate )
61
65
.ignoreExpectOrder (false ).build ();
62
66
@@ -66,7 +70,7 @@ public void exactExpectOrder() throws Exception {
66
70
}
67
71
68
72
@ Test
69
- public void ignoreExpectOrder () throws Exception {
73
+ public void ignoreExpectOrder () {
70
74
MockRestServiceServer server = MockRestServiceServer .bindTo (this .restTemplate )
71
75
.ignoreExpectOrder (true ).build ();
72
76
@@ -78,7 +82,7 @@ public void ignoreExpectOrder() throws Exception {
78
82
}
79
83
80
84
@ Test
81
- public void resetAndReuseServer () throws Exception {
85
+ public void resetAndReuseServer () {
82
86
MockRestServiceServer server = MockRestServiceServer .bindTo (this .restTemplate ).build ();
83
87
84
88
server .expect (requestTo ("/foo" )).andRespond (withSuccess ());
@@ -92,7 +96,7 @@ public void resetAndReuseServer() throws Exception {
92
96
}
93
97
94
98
@ Test
95
- public void resetAndReuseServerWithUnorderedExpectationManager () throws Exception {
99
+ public void resetAndReuseServerWithUnorderedExpectationManager () {
96
100
MockRestServiceServer server = MockRestServiceServer .bindTo (this .restTemplate )
97
101
.ignoreExpectOrder (true ).build ();
98
102
@@ -108,4 +112,24 @@ public void resetAndReuseServerWithUnorderedExpectationManager() throws Exceptio
108
112
server .verify ();
109
113
}
110
114
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
+
111
135
}
0 commit comments