1
1
/*
2
- * Copyright 2002-2018 the original author or authors.
2
+ * Copyright 2002-2019 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.
20
20
import java .net .URI ;
21
21
import java .util .Collection ;
22
22
import java .util .Collections ;
23
+ import java .util .LinkedHashMap ;
23
24
import java .util .LinkedHashSet ;
24
25
import java .util .LinkedList ;
25
26
import java .util .List ;
27
+ import java .util .Map ;
26
28
import java .util .Set ;
29
+ import java .util .stream .Collectors ;
27
30
28
31
import org .springframework .http .HttpMethod ;
29
32
import org .springframework .http .client .ClientHttpRequest ;
@@ -49,6 +52,8 @@ public abstract class AbstractRequestExpectationManager implements RequestExpect
49
52
50
53
private final List <ClientHttpRequest > requests = new LinkedList <>();
51
54
55
+ private final Map <ClientHttpRequest , Throwable > requestFailures = new LinkedHashMap <>();
56
+
52
57
53
58
/**
54
59
* Return a read-only list of the expectations.
@@ -91,6 +96,10 @@ public ClientHttpResponse validateRequest(ClientHttpRequest request) throws IOEx
91
96
expectation = matchRequest (request );
92
97
}
93
98
}
99
+ catch (Throwable ex ) {
100
+ this .requestFailures .put (request , ex );
101
+ throw ex ;
102
+ }
94
103
finally {
95
104
this .requests .add (request );
96
105
}
@@ -129,7 +138,8 @@ protected ClientHttpResponse validateRequestInternal(ClientHttpRequest request)
129
138
* @since 5.0.3
130
139
*/
131
140
protected RequestExpectation matchRequest (ClientHttpRequest request ) throws IOException {
132
- throw new UnsupportedOperationException ("It looks like neither the deprecated \" validateRequestInternal\" " +
141
+ throw new UnsupportedOperationException (
142
+ "It looks like neither the deprecated \" validateRequestInternal\" " +
133
143
"nor its replacement (this method) are implemented." );
134
144
}
135
145
@@ -148,6 +158,12 @@ public void verify() {
148
158
String message = "Further request(s) expected leaving " + count + " unsatisfied expectation(s).\n " ;
149
159
throw new AssertionError (message + getRequestDetails ());
150
160
}
161
+ if (!this .requestFailures .isEmpty ()) {
162
+ throw new AssertionError ("Some requests did not execute successfully.\n " +
163
+ this .requestFailures .entrySet ().stream ()
164
+ .map (entry -> "Failed request:\n " + entry .getKey () + "\n " + entry .getValue ())
165
+ .collect (Collectors .joining ("\n " , "\n " , "" )));
166
+ }
151
167
}
152
168
153
169
/**
0 commit comments