|
43 | 43 | import org.springframework.http.HttpStatusCode;
|
44 | 44 | import org.springframework.http.MediaType;
|
45 | 45 | import org.springframework.http.ResponseEntity;
|
| 46 | +import org.springframework.http.StreamingHttpOutputMessage; |
46 | 47 | import org.springframework.http.client.ClientHttpRequestFactory;
|
47 | 48 | import org.springframework.http.client.ClientHttpRequestInterceptor;
|
48 | 49 | import org.springframework.http.client.ClientHttpResponse;
|
|
52 | 53 | import org.springframework.http.client.ReactorClientHttpRequestFactory;
|
53 | 54 | import org.springframework.http.client.SimpleClientHttpRequestFactory;
|
54 | 55 | import org.springframework.util.CollectionUtils;
|
| 56 | +import org.springframework.util.FastByteArrayOutputStream; |
55 | 57 | import org.springframework.util.LinkedMultiValueMap;
|
56 | 58 | import org.springframework.util.MultiValueMap;
|
57 | 59 | import org.springframework.web.testfixture.xml.Pojo;
|
@@ -530,27 +532,6 @@ void postPojoAsJson(ClientHttpRequestFactory requestFactory) {
|
530 | 532 | });
|
531 | 533 | }
|
532 | 534 |
|
533 |
| - @ParameterizedRestClientTest |
534 |
| - void postStreamingMessageBody(ClientHttpRequestFactory requestFactory) { |
535 |
| - startServer(requestFactory); |
536 |
| - |
537 |
| - prepareResponse(response -> response.setResponseCode(200)); |
538 |
| - |
539 |
| - ResponseEntity<Void> result = this.restClient.post() |
540 |
| - .uri("/streaming/body") |
541 |
| - .body(new ByteArrayInputStream("test-data".getBytes(UTF_8))::transferTo) |
542 |
| - .retrieve() |
543 |
| - .toBodilessEntity(); |
544 |
| - |
545 |
| - assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK); |
546 |
| - |
547 |
| - expectRequestCount(1); |
548 |
| - expectRequest(request -> { |
549 |
| - assertThat(request.getPath()).isEqualTo("/streaming/body"); |
550 |
| - assertThat(request.getBody().readUtf8()).isEqualTo("test-data"); |
551 |
| - }); |
552 |
| - } |
553 |
| - |
554 | 535 | @ParameterizedRestClientTest // gh-31361
|
555 | 536 | public void postForm(ClientHttpRequestFactory requestFactory) {
|
556 | 537 | startServer(requestFactory);
|
@@ -594,6 +575,30 @@ public void postForm(ClientHttpRequestFactory requestFactory) {
|
594 | 575 | });
|
595 | 576 | }
|
596 | 577 |
|
| 578 | + @ParameterizedRestClientTest // gh-35102 |
| 579 | + void postStreamingBody(ClientHttpRequestFactory requestFactory) { |
| 580 | + startServer(requestFactory); |
| 581 | + prepareResponse(response -> response.setResponseCode(200)); |
| 582 | + |
| 583 | + StreamingHttpOutputMessage.Body testBody = out -> { |
| 584 | + assertThat(out).as("Not a streaming response").isNotInstanceOf(FastByteArrayOutputStream.class); |
| 585 | + new ByteArrayInputStream("test-data".getBytes(UTF_8)).transferTo(out); |
| 586 | + }; |
| 587 | + |
| 588 | + ResponseEntity<Void> result = this.restClient.post() |
| 589 | + .uri("/streaming/body") |
| 590 | + .body(testBody) |
| 591 | + .retrieve() |
| 592 | + .toBodilessEntity(); |
| 593 | + |
| 594 | + assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK); |
| 595 | + |
| 596 | + expectRequestCount(1); |
| 597 | + expectRequest(request -> { |
| 598 | + assertThat(request.getPath()).isEqualTo("/streaming/body"); |
| 599 | + assertThat(request.getBody().readUtf8()).isEqualTo("test-data"); |
| 600 | + }); |
| 601 | + } |
597 | 602 |
|
598 | 603 | @ParameterizedRestClientTest
|
599 | 604 | void statusHandler(ClientHttpRequestFactory requestFactory) {
|
|
0 commit comments