Search in sources :

Example 21 with DefaultDataBufferFactory

use of org.springframework.core.io.buffer.DefaultDataBufferFactory in project spring-framework by spring-projects.

the class DefaultServerRequestTests method bodyToFlux.

@Test
public void bodyToFlux() throws Exception {
    DefaultDataBufferFactory factory = new DefaultDataBufferFactory();
    DefaultDataBuffer dataBuffer = factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8)));
    Flux<DataBuffer> body = Flux.just(dataBuffer);
    HttpHeaders httpHeaders = new HttpHeaders();
    httpHeaders.setContentType(MediaType.TEXT_PLAIN);
    when(mockRequest.getHeaders()).thenReturn(httpHeaders);
    when(mockRequest.getBody()).thenReturn(body);
    Set<HttpMessageReader<?>> messageReaders = Collections.singleton(new DecoderHttpMessageReader<String>(new StringDecoder()));
    when(mockHandlerStrategies.messageReaders()).thenReturn(messageReaders::stream);
    Flux<String> resultFlux = defaultRequest.bodyToFlux(String.class);
    Mono<List<String>> result = resultFlux.collectList();
    assertEquals(Collections.singletonList("foo"), result.block());
}
Also used : DefaultDataBuffer(org.springframework.core.io.buffer.DefaultDataBuffer) HttpHeaders(org.springframework.http.HttpHeaders) StringDecoder(org.springframework.core.codec.StringDecoder) HttpMessageReader(org.springframework.http.codec.HttpMessageReader) DecoderHttpMessageReader(org.springframework.http.codec.DecoderHttpMessageReader) DefaultDataBufferFactory(org.springframework.core.io.buffer.DefaultDataBufferFactory) List(java.util.List) DefaultDataBuffer(org.springframework.core.io.buffer.DefaultDataBuffer) DataBuffer(org.springframework.core.io.buffer.DataBuffer) Test(org.junit.Test)

Example 22 with DefaultDataBufferFactory

use of org.springframework.core.io.buffer.DefaultDataBufferFactory in project spring-framework by spring-projects.

the class ResourceRegionEncoderTests method setUp.

@Before
public void setUp() {
    this.encoder = new ResourceRegionEncoder();
    this.bufferFactory = new DefaultDataBufferFactory();
}
Also used : DefaultDataBufferFactory(org.springframework.core.io.buffer.DefaultDataBufferFactory) Before(org.junit.Before)

Aggregations

DefaultDataBufferFactory (org.springframework.core.io.buffer.DefaultDataBufferFactory)22 DataBuffer (org.springframework.core.io.buffer.DataBuffer)20 Test (org.junit.Test)19 DefaultDataBuffer (org.springframework.core.io.buffer.DefaultDataBuffer)17 HttpHeaders (org.springframework.http.HttpHeaders)8 DecoderHttpMessageReader (org.springframework.http.codec.DecoderHttpMessageReader)8 HttpMessageReader (org.springframework.http.codec.HttpMessageReader)8 MockServerHttpRequest (org.springframework.mock.http.server.reactive.test.MockServerHttpRequest)8 StringDecoder (org.springframework.core.codec.StringDecoder)7 Flux (reactor.core.publisher.Flux)7 Mono (reactor.core.publisher.Mono)6 ByteBuffer (java.nio.ByteBuffer)5 List (java.util.List)5 ReactiveHttpInputMessage (org.springframework.http.ReactiveHttpInputMessage)5 ReactiveHttpOutputMessage (org.springframework.http.ReactiveHttpOutputMessage)3 MockServerHttpResponse (org.springframework.mock.http.server.reactive.test.MockServerHttpResponse)3 StepVerifier (reactor.test.StepVerifier)3 StandardCharsets (java.nio.charset.StandardCharsets)2 ArrayList (java.util.ArrayList)2 Collections (java.util.Collections)2