use of cn.taketoday.http.codec.HttpMessageWriter in project today-infrastructure by TAKETODAY.
the class ClientCodecConfigurerTests method clonedConfigurer.
@Test
public void clonedConfigurer() {
ClientCodecConfigurer clone = this.configurer.clone();
Jackson2JsonDecoder jackson2Decoder = new Jackson2JsonDecoder();
clone.defaultCodecs().serverSentEventDecoder(jackson2Decoder);
clone.defaultCodecs().multipartCodecs().encoder(new Jackson2SmileEncoder());
clone.defaultCodecs().multipartCodecs().writer(new ResourceHttpMessageWriter());
// Clone has the customizations
Decoder<?> sseDecoder = findCodec(clone.getReaders(), ServerSentEventHttpMessageReader.class).getDecoder();
List<HttpMessageWriter<?>> writers = findCodec(clone.getWriters(), MultipartHttpMessageWriter.class).getPartWriters();
assertThat(sseDecoder).isSameAs(jackson2Decoder);
assertThat(writers).hasSize(2);
// Original does not have the customizations
sseDecoder = findCodec(this.configurer.getReaders(), ServerSentEventHttpMessageReader.class).getDecoder();
writers = findCodec(this.configurer.getWriters(), MultipartHttpMessageWriter.class).getPartWriters();
assertThat(sseDecoder).isNotSameAs(jackson2Decoder);
assertThat(writers).hasSize(10);
}
use of cn.taketoday.http.codec.HttpMessageWriter in project today-infrastructure by TAKETODAY.
the class ClientCodecConfigurerTests method cloneShouldNotDropMultipartCodecs.
// gh-24194
@Test
public void cloneShouldNotDropMultipartCodecs() {
ClientCodecConfigurer clone = this.configurer.clone();
List<HttpMessageWriter<?>> writers = findCodec(clone.getWriters(), MultipartHttpMessageWriter.class).getPartWriters();
assertThat(writers).hasSize(10);
}
use of cn.taketoday.http.codec.HttpMessageWriter in project today-infrastructure by TAKETODAY.
the class ClientCodecConfigurerTests method cloneShouldNotBeImpactedByChangesToOriginal.
@Test
public void cloneShouldNotBeImpactedByChangesToOriginal() {
ClientCodecConfigurer clone = this.configurer.clone();
this.configurer.registerDefaults(false);
this.configurer.customCodecs().register(new Jackson2JsonEncoder());
List<HttpMessageWriter<?>> writers = findCodec(clone.getWriters(), MultipartHttpMessageWriter.class).getPartWriters();
assertThat(writers).hasSize(10);
}
use of cn.taketoday.http.codec.HttpMessageWriter in project today-infrastructure by TAKETODAY.
the class DefaultClientRequestBuilderTests method bodyInserter.
@Test
public void bodyInserter() {
String body = "foo";
BodyInserter<String, ClientHttpRequest> inserter = (response, strategies) -> {
byte[] bodyBytes = body.getBytes(UTF_8);
DataBuffer buffer = DefaultDataBufferFactory.sharedInstance.wrap(bodyBytes);
return response.writeWith(Mono.just(buffer));
};
ClientRequest result = ClientRequest.create(POST, DEFAULT_URL).body(inserter).build();
List<HttpMessageWriter<?>> messageWriters = new ArrayList<>();
messageWriters.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.allMimeTypes()));
ExchangeStrategies strategies = mock(ExchangeStrategies.class);
given(strategies.messageWriters()).willReturn(messageWriters);
MockClientHttpRequest request = new MockClientHttpRequest(GET, "/");
result.writeTo(request, strategies).block();
assertThat(request.getBody()).isNotNull();
StepVerifier.create(request.getBody()).expectNextCount(1).verifyComplete();
}
use of cn.taketoday.http.codec.HttpMessageWriter in project today-infrastructure by TAKETODAY.
the class DefaultClientRequestBuilderTests method bodyParameterizedTypeReference.
@Test
public void bodyParameterizedTypeReference() {
String body = "foo";
Publisher<String> publisher = Mono.just(body);
TypeReference<String> typeReference = new TypeReference<>() {
};
ClientRequest result = ClientRequest.create(POST, DEFAULT_URL).body(publisher, typeReference).build();
List<HttpMessageWriter<?>> messageWriters = new ArrayList<>();
messageWriters.add(new EncoderHttpMessageWriter<>(CharSequenceEncoder.allMimeTypes()));
ExchangeStrategies strategies = mock(ExchangeStrategies.class);
given(strategies.messageWriters()).willReturn(messageWriters);
MockClientHttpRequest request = new MockClientHttpRequest(GET, "/");
result.writeTo(request, strategies).block();
assertThat(request.getBody()).isNotNull();
StepVerifier.create(request.getBody()).expectNextCount(1).verifyComplete();
}
Aggregations