File tree Expand file tree Collapse file tree 3 files changed +37
-0
lines changed
spring-test/src/main/java/org/springframework/test/web/reactive/server Expand file tree Collapse file tree 3 files changed +37
-0
lines changed Original file line number Diff line number Diff line change 3434
3535import org .springframework .core .ParameterizedTypeReference ;
3636import org .springframework .core .io .ByteArrayResource ;
37+ import org .springframework .core .io .buffer .DataBuffer ;
3738import org .springframework .http .HttpHeaders ;
3839import org .springframework .http .HttpMethod ;
3940import org .springframework .http .MediaType ;
4647import org .springframework .util .MimeType ;
4748import org .springframework .util .MultiValueMap ;
4849import org .springframework .web .reactive .function .BodyExtractor ;
50+ import org .springframework .web .reactive .function .BodyExtractors ;
4951import org .springframework .web .reactive .function .BodyInserter ;
5052import org .springframework .web .reactive .function .client .ClientResponse ;
5153import org .springframework .web .reactive .function .client .WebClient ;
@@ -379,6 +381,11 @@ public BodyContentSpec expectBody() {
379381 return new DefaultBodyContentSpec (this .result .decodeToByteArray ());
380382 }
381383
384+ @ Override
385+ public FluxExchangeResult <DataBuffer > returnResult () {
386+ return this .result .decodeToFlux (BodyExtractors .toDataBuffers ());
387+ }
388+
382389 @ Override
383390 public <T > FluxExchangeResult <T > returnResult (Class <T > elementType ) {
384391 return this .result .decodeToFlux (toFlux (elementType ));
Original file line number Diff line number Diff line change 1717package org .springframework .test .web .reactive .server ;
1818
1919import java .time .Duration ;
20+ import java .util .function .Consumer ;
2021
2122import reactor .core .publisher .Flux ;
2223import reactor .core .publisher .Mono ;
@@ -97,4 +98,23 @@ public byte[] getResponseBodyContent() {
9798 .block ();
9899 }
99100
101+ /**
102+ * Invoke the given consumer within {@link #assertWithDiagnostics(Runnable)}
103+ * passing {@code "this"} instance to it. This method allows the following,
104+ * without leaving the {@code WebTestClient} chain of calls:
105+ * <pre class="code">
106+ * client.get()
107+ * .uri("/persons")
108+ * .accept(TEXT_EVENT_STREAM)
109+ * .exchange()
110+ * .expectStatus().isOk()
111+ * .returnResult()
112+ * .consumeWith(result -> assertThat(...);
113+ * </pre>
114+ * @param consumer consumer for {@code "this"} instance
115+ */
116+ public void consumeWith (Consumer <FluxExchangeResult <T >> consumer ) {
117+ assertWithDiagnostics (() -> consumer .accept (this ));
118+ }
119+
100120}
Original file line number Diff line number Diff line change 2929
3030import org .springframework .context .ApplicationContext ;
3131import org .springframework .core .ParameterizedTypeReference ;
32+ import org .springframework .core .io .buffer .DataBuffer ;
3233import org .springframework .format .FormatterRegistry ;
3334import org .springframework .http .HttpHeaders ;
3435import org .springframework .http .HttpMethod ;
@@ -663,6 +664,15 @@ interface ResponseSpec {
663664 * Variant of {@link #returnResult(Class)} for element types with generics.
664665 */
665666 <T > FluxExchangeResult <T > returnResult (ParameterizedTypeReference <T > elementType );
667+
668+ /**
669+ * Return the exchange result with the body decoded to
670+ * {@code Flux<DataBuffer>}. Use this option for infinite streams and
671+ * consume the stream with the {@code StepVerifier} from the Reactor Add-Ons.
672+ *
673+ * @return
674+ */
675+ FluxExchangeResult <DataBuffer > returnResult ();
666676 }
667677
668678 /**
You can’t perform that action at this time.
0 commit comments