use of cn.taketoday.http.codec.DecoderHttpMessageReader in project today-framework by TAKETODAY.
the class DefaultClientResponseTests method bodyToMonoTypeReference.
@Test
public void bodyToMonoTypeReference() {
byte[] bytes = "foo".getBytes(StandardCharsets.UTF_8);
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
Flux<DataBuffer> body = Flux.just(dataBuffer);
mockTextPlainResponse(body);
List<HttpMessageReader<?>> messageReaders = Collections.singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes()));
given(mockExchangeStrategies.messageReaders()).willReturn(messageReaders);
Mono<String> resultMono = defaultClientResponse.bodyToMono(new TypeReference<String>() {
});
assertThat(resultMono.block()).isEqualTo("foo");
}
use of cn.taketoday.http.codec.DecoderHttpMessageReader in project today-framework by TAKETODAY.
the class DefaultClientResponseTests method bodyToFlux.
@Test
public void bodyToFlux() {
byte[] bytes = "foo".getBytes(StandardCharsets.UTF_8);
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
Flux<DataBuffer> body = Flux.just(dataBuffer);
mockTextPlainResponse(body);
List<HttpMessageReader<?>> messageReaders = Collections.singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes()));
given(mockExchangeStrategies.messageReaders()).willReturn(messageReaders);
Flux<String> resultFlux = defaultClientResponse.bodyToFlux(String.class);
Mono<List<String>> result = resultFlux.collectList();
assertThat(result.block()).isEqualTo(Collections.singletonList("foo"));
}
use of cn.taketoday.http.codec.DecoderHttpMessageReader in project today-framework by TAKETODAY.
the class DefaultClientResponseTests method body.
@Test
public void body() {
byte[] bytes = "foo".getBytes(StandardCharsets.UTF_8);
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
Flux<DataBuffer> body = Flux.just(dataBuffer);
mockTextPlainResponse(body);
List<HttpMessageReader<?>> messageReaders = Collections.singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes()));
given(mockExchangeStrategies.messageReaders()).willReturn(messageReaders);
Mono<String> resultMono = defaultClientResponse.body(toMono(String.class));
assertThat(resultMono.block()).isEqualTo("foo");
}
use of cn.taketoday.http.codec.DecoderHttpMessageReader in project today-infrastructure by TAKETODAY.
the class BodyExtractorsTests method createContext.
@BeforeEach
public void createContext() {
final List<HttpMessageReader<?>> messageReaders = new ArrayList<>();
messageReaders.add(new DecoderHttpMessageReader<>(new ByteBufferDecoder()));
messageReaders.add(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes()));
// messageReaders.add(new DecoderHttpMessageReader<>(new Jaxb2XmlDecoder()));
messageReaders.add(new DecoderHttpMessageReader<>(new Jackson2JsonDecoder()));
messageReaders.add(new FormHttpMessageReader());
DefaultPartHttpMessageReader partReader = new DefaultPartHttpMessageReader();
messageReaders.add(partReader);
messageReaders.add(new MultipartHttpMessageReader(partReader));
messageReaders.add(new FormHttpMessageReader());
this.context = new BodyExtractor.Context() {
@Override
public List<HttpMessageReader<?>> messageReaders() {
return messageReaders;
}
@Override
public Optional<ServerHttpResponse> serverResponse() {
return serverResponse;
}
@Override
public Map<String, Object> hints() {
return hints;
}
};
this.hints = new HashMap<>();
}
use of cn.taketoday.http.codec.DecoderHttpMessageReader in project today-infrastructure by TAKETODAY.
the class DefaultClientResponseTests method bodyToFluxTypeReference.
@Test
public void bodyToFluxTypeReference() {
byte[] bytes = "foo".getBytes(StandardCharsets.UTF_8);
DefaultDataBuffer dataBuffer = DefaultDataBufferFactory.sharedInstance.wrap(ByteBuffer.wrap(bytes));
Flux<DataBuffer> body = Flux.just(dataBuffer);
mockTextPlainResponse(body);
List<HttpMessageReader<?>> messageReaders = Collections.singletonList(new DecoderHttpMessageReader<>(StringDecoder.allMimeTypes()));
given(mockExchangeStrategies.messageReaders()).willReturn(messageReaders);
Flux<String> resultFlux = defaultClientResponse.bodyToFlux(new TypeReference<String>() {
});
Mono<List<String>> result = resultFlux.collectList();
assertThat(result.block()).isEqualTo(Collections.singletonList("foo"));
}
Aggregations