Search in sources :

Example 1 with DefaultDataBufferFactory

use of cn.taketoday.core.io.buffer.DefaultDataBufferFactory in project today-infrastructure by TAKETODAY.

the class EncoderHttpMessageWriterTests method setContentLengthForMonoBody.

@Test
void setContentLengthForMonoBody() {
    DefaultDataBufferFactory factory = DefaultDataBufferFactory.sharedInstance;
    DataBuffer buffer = factory.wrap("body".getBytes(StandardCharsets.UTF_8));
    configureEncoder(Flux.just(buffer), MimeTypeUtils.TEXT_PLAIN);
    HttpMessageWriter<String> writer = new EncoderHttpMessageWriter<>(this.encoder);
    writer.write(Mono.just("body"), fromClass(String.class), TEXT_PLAIN, this.response, NO_HINTS).block();
    assertThat(this.response.getHeaders().getContentLength()).isEqualTo(4);
}
Also used : DefaultDataBufferFactory(cn.taketoday.core.io.buffer.DefaultDataBufferFactory) DataBuffer(cn.taketoday.core.io.buffer.DataBuffer) Test(org.junit.jupiter.api.Test)

Example 2 with DefaultDataBufferFactory

use of cn.taketoday.core.io.buffer.DefaultDataBufferFactory in project today-framework by TAKETODAY.

the class EncoderHttpMessageWriterTests method setContentLengthForMonoBody.

@Test
void setContentLengthForMonoBody() {
    DefaultDataBufferFactory factory = DefaultDataBufferFactory.sharedInstance;
    DataBuffer buffer = factory.wrap("body".getBytes(StandardCharsets.UTF_8));
    configureEncoder(Flux.just(buffer), MimeTypeUtils.TEXT_PLAIN);
    HttpMessageWriter<String> writer = new EncoderHttpMessageWriter<>(this.encoder);
    writer.write(Mono.just("body"), fromClass(String.class), TEXT_PLAIN, this.response, NO_HINTS).block();
    assertThat(this.response.getHeaders().getContentLength()).isEqualTo(4);
}
Also used : DefaultDataBufferFactory(cn.taketoday.core.io.buffer.DefaultDataBufferFactory) DataBuffer(cn.taketoday.core.io.buffer.DataBuffer) Test(org.junit.jupiter.api.Test)

Example 3 with DefaultDataBufferFactory

use of cn.taketoday.core.io.buffer.DefaultDataBufferFactory in project today-framework by TAKETODAY.

the class BodyExtractorsTests method toMono.

@Test
public void toMono() {
    BodyExtractor<Mono<String>, ReactiveHttpInputMessage> extractor = BodyExtractors.toMono(String.class);
    DefaultDataBufferFactory factory = DefaultDataBufferFactory.sharedInstance;
    DefaultDataBuffer dataBuffer = factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8)));
    Flux<DataBuffer> body = Flux.just(dataBuffer);
    MockServerHttpRequest request = MockServerHttpRequest.post("/").body(body);
    Mono<String> result = extractor.extract(request, this.context);
    StepVerifier.create(result).expectNext("foo").expectComplete().verify();
}
Also used : DefaultDataBuffer(cn.taketoday.core.io.buffer.DefaultDataBuffer) MockServerHttpRequest(cn.taketoday.web.testfixture.http.server.reactive.MockServerHttpRequest) DefaultDataBufferFactory(cn.taketoday.core.io.buffer.DefaultDataBufferFactory) Mono(reactor.core.publisher.Mono) ReactiveHttpInputMessage(cn.taketoday.http.ReactiveHttpInputMessage) NettyDataBuffer(cn.taketoday.core.io.buffer.NettyDataBuffer) DataBuffer(cn.taketoday.core.io.buffer.DataBuffer) DefaultDataBuffer(cn.taketoday.core.io.buffer.DefaultDataBuffer) Test(org.junit.jupiter.api.Test)

Example 4 with DefaultDataBufferFactory

use of cn.taketoday.core.io.buffer.DefaultDataBufferFactory in project today-infrastructure by TAKETODAY.

the class BodyExtractorsTests method toMono.

@Test
public void toMono() {
    BodyExtractor<Mono<String>, ReactiveHttpInputMessage> extractor = BodyExtractors.toMono(String.class);
    DefaultDataBufferFactory factory = DefaultDataBufferFactory.sharedInstance;
    DefaultDataBuffer dataBuffer = factory.wrap(ByteBuffer.wrap("foo".getBytes(StandardCharsets.UTF_8)));
    Flux<DataBuffer> body = Flux.just(dataBuffer);
    MockServerHttpRequest request = MockServerHttpRequest.post("/").body(body);
    Mono<String> result = extractor.extract(request, this.context);
    StepVerifier.create(result).expectNext("foo").expectComplete().verify();
}
Also used : DefaultDataBuffer(cn.taketoday.core.io.buffer.DefaultDataBuffer) MockServerHttpRequest(cn.taketoday.web.testfixture.http.server.reactive.MockServerHttpRequest) DefaultDataBufferFactory(cn.taketoday.core.io.buffer.DefaultDataBufferFactory) Mono(reactor.core.publisher.Mono) ReactiveHttpInputMessage(cn.taketoday.http.ReactiveHttpInputMessage) NettyDataBuffer(cn.taketoday.core.io.buffer.NettyDataBuffer) DataBuffer(cn.taketoday.core.io.buffer.DataBuffer) DefaultDataBuffer(cn.taketoday.core.io.buffer.DefaultDataBuffer) Test(org.junit.jupiter.api.Test)

Aggregations

DataBuffer (cn.taketoday.core.io.buffer.DataBuffer)4 DefaultDataBufferFactory (cn.taketoday.core.io.buffer.DefaultDataBufferFactory)4 Test (org.junit.jupiter.api.Test)4 DefaultDataBuffer (cn.taketoday.core.io.buffer.DefaultDataBuffer)2 NettyDataBuffer (cn.taketoday.core.io.buffer.NettyDataBuffer)2 ReactiveHttpInputMessage (cn.taketoday.http.ReactiveHttpInputMessage)2 MockServerHttpRequest (cn.taketoday.web.testfixture.http.server.reactive.MockServerHttpRequest)2 Mono (reactor.core.publisher.Mono)2