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);
}
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);
}
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();
}
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();
}
Aggregations