@@ -289,7 +289,7 @@ class HalClientSpec extends Specification {
289
289
290
290
@Unroll
291
291
@SuppressWarnings (' UnnecessaryGetter' )
292
- def ' post URL returns #success if the response is #status' () {
292
+ def ' post to URL returns #success if the response is #status' () {
293
293
given :
294
294
def mockClient = Mock (CloseableHttpClient )
295
295
client. httpClient = mockClient
@@ -308,7 +308,7 @@ class HalClientSpec extends Specification {
308
308
' failure' | 400 | Result.Err
309
309
}
310
310
311
- def ' post URL returns a failure result if an exception is thrown' () {
311
+ def ' post to URL returns a failure result if an exception is thrown' () {
312
312
given :
313
313
def mockClient = Mock (CloseableHttpClient )
314
314
client. httpClient = mockClient
@@ -322,7 +322,7 @@ class HalClientSpec extends Specification {
322
322
}
323
323
324
324
@SuppressWarnings (' UnnecessaryGetter' )
325
- def ' post URL delegates to a handler if one is supplied' () {
325
+ def ' post to URL delegates to a handler if one is supplied' () {
326
326
given :
327
327
def mockClient = Mock (CloseableHttpClient )
328
328
client. httpClient = mockClient
@@ -523,4 +523,23 @@ class HalClientSpec extends Specification {
523
523
handler. handleResponse(mockResponse)
524
524
}
525
525
}
526
+
527
+ @Issue (' 1830' )
528
+ def ' post to URL handles any error responses' () {
529
+ given :
530
+ def mockClient = Mock (CloseableHttpClient )
531
+ client. httpClient = mockClient
532
+ def mockResponse = Mock (ClassicHttpResponse ) {
533
+ getCode() >> 400
534
+ getEntity() >> new StringEntity (' {"error": ["it went bang!"]}' , ContentType . APPLICATION_JSON )
535
+ }
536
+ client. pathInfo = JsonParser . INSTANCE . parseString(' {"_links":{"path":{"href":"http://localhost:8080/"}}}' )
537
+
538
+ when :
539
+ def result = client. postJson(' path' , [:], ' "body"' )
540
+
541
+ then :
542
+ 1 * mockClient. execute(_, _, _) >> { req , c , handler -> handler. handleResponse(mockResponse) }
543
+ result instanceof Result.Err
544
+ }
526
545
}
0 commit comments