|
|
|
@ -16,31 +16,36 @@ |
|
|
|
|
|
|
|
|
|
|
|
package org.springframework.http.codec; |
|
|
|
package org.springframework.http.codec; |
|
|
|
|
|
|
|
|
|
|
|
import java.lang.reflect.InvocationTargetException; |
|
|
|
|
|
|
|
import java.lang.reflect.Method; |
|
|
|
|
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
|
|
|
|
import java.util.Arrays; |
|
|
|
|
|
|
|
import java.util.Collections; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
import org.junit.jupiter.api.Test; |
|
|
|
import org.mockito.ArgumentCaptor; |
|
|
|
import org.mockito.ArgumentCaptor; |
|
|
|
import org.mockito.Mock; |
|
|
|
import org.mockito.Mock; |
|
|
|
import org.mockito.junit.jupiter.MockitoSettings; |
|
|
|
import org.mockito.junit.jupiter.MockitoSettings; |
|
|
|
import org.mockito.quality.Strictness; |
|
|
|
import org.mockito.quality.Strictness; |
|
|
|
import reactor.core.publisher.Flux; |
|
|
|
import org.springframework.core.ResolvableType; |
|
|
|
import reactor.core.publisher.Mono; |
|
|
|
|
|
|
|
import reactor.test.StepVerifier; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import org.springframework.core.codec.CharSequenceEncoder; |
|
|
|
import org.springframework.core.codec.CharSequenceEncoder; |
|
|
|
|
|
|
|
import org.springframework.core.codec.Encoder; |
|
|
|
import org.springframework.core.io.buffer.DataBuffer; |
|
|
|
import org.springframework.core.io.buffer.DataBuffer; |
|
|
|
import org.springframework.core.io.buffer.DefaultDataBufferFactory; |
|
|
|
import org.springframework.core.io.buffer.DefaultDataBufferFactory; |
|
|
|
|
|
|
|
import org.springframework.http.HttpHeaders; |
|
|
|
|
|
|
|
import org.springframework.http.HttpMethod; |
|
|
|
import org.springframework.http.MediaType; |
|
|
|
import org.springframework.http.MediaType; |
|
|
|
|
|
|
|
import org.springframework.http.ReactiveHttpOutputMessage; |
|
|
|
import org.springframework.util.MimeType; |
|
|
|
import org.springframework.util.MimeType; |
|
|
|
import org.springframework.util.MimeTypeUtils; |
|
|
|
import org.springframework.util.MimeTypeUtils; |
|
|
|
import org.springframework.util.ReflectionUtils; |
|
|
|
import org.springframework.util.ReflectionUtils; |
|
|
|
|
|
|
|
import org.springframework.web.testfixture.http.client.reactive.MockClientHttpRequest; |
|
|
|
import org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse; |
|
|
|
import org.springframework.web.testfixture.http.server.reactive.MockServerHttpResponse; |
|
|
|
|
|
|
|
import reactor.core.publisher.Flux; |
|
|
|
|
|
|
|
import reactor.core.publisher.Mono; |
|
|
|
|
|
|
|
import reactor.test.StepVerifier; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.lang.reflect.InvocationTargetException; |
|
|
|
|
|
|
|
import java.lang.reflect.Method; |
|
|
|
|
|
|
|
import java.nio.charset.StandardCharsets; |
|
|
|
|
|
|
|
import java.util.Arrays; |
|
|
|
|
|
|
|
import java.util.Collections; |
|
|
|
|
|
|
|
import java.util.List; |
|
|
|
|
|
|
|
import java.util.Map; |
|
|
|
|
|
|
|
|
|
|
|
import static java.nio.charset.StandardCharsets.ISO_8859_1; |
|
|
|
import static java.nio.charset.StandardCharsets.ISO_8859_1; |
|
|
|
import static java.nio.charset.StandardCharsets.UTF_8; |
|
|
|
import static java.nio.charset.StandardCharsets.UTF_8; |
|
|
|
@ -199,6 +204,35 @@ class EncoderHttpMessageWriterTests { |
|
|
|
assertThat((Boolean) method.invoke(writer, TEXT_HTML)).isFalse(); |
|
|
|
assertThat((Boolean) method.invoke(writer, TEXT_HTML)).isFalse(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void ifBodyPublisherEmpty_noContentTypeHeader() { |
|
|
|
|
|
|
|
Encoder<CharSequence> encoder = CharSequenceEncoder.textPlainOnly(); |
|
|
|
|
|
|
|
EncoderHttpMessageWriter<CharSequence> writer = new EncoderHttpMessageWriter<>(encoder); |
|
|
|
|
|
|
|
ReactiveHttpOutputMessage outputMessage = new MockClientHttpRequest(HttpMethod.POST, "/"); |
|
|
|
|
|
|
|
Mono<Void> writerMono = writer.write(Mono.empty(), ResolvableType.forClass(String.class), |
|
|
|
|
|
|
|
null, outputMessage, NO_HINTS); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
StepVerifier.create(writerMono) |
|
|
|
|
|
|
|
.verifyComplete(); |
|
|
|
|
|
|
|
assertThat(outputMessage.getHeaders()).doesNotContainKey(HttpHeaders.CONTENT_TYPE); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Test |
|
|
|
|
|
|
|
public void ifBodyPublisherEmpty_contentLengthZero() { |
|
|
|
|
|
|
|
Encoder<CharSequence> encoder = CharSequenceEncoder.textPlainOnly(); |
|
|
|
|
|
|
|
EncoderHttpMessageWriter<CharSequence> writer = new EncoderHttpMessageWriter<>(encoder); |
|
|
|
|
|
|
|
ReactiveHttpOutputMessage outputMessage = new MockClientHttpRequest(HttpMethod.POST, "/"); |
|
|
|
|
|
|
|
Mono<Void> writerMono = writer.write(Mono.empty(), ResolvableType.forClass(String.class), |
|
|
|
|
|
|
|
null, outputMessage, NO_HINTS); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
StepVerifier.create(writerMono) |
|
|
|
|
|
|
|
.verifyComplete(); |
|
|
|
|
|
|
|
List<String> contentLengthValues = outputMessage.getHeaders().get(HttpHeaders.CONTENT_LENGTH); |
|
|
|
|
|
|
|
assertThat(contentLengthValues).hasSize(1); |
|
|
|
|
|
|
|
int contentLength = Integer.parseInt(contentLengthValues.get(0)); |
|
|
|
|
|
|
|
assertThat(contentLength).isEqualTo(0); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private void configureEncoder(MimeType... mimeTypes) { |
|
|
|
private void configureEncoder(MimeType... mimeTypes) { |
|
|
|
configureEncoder(Flux.empty(), mimeTypes); |
|
|
|
configureEncoder(Flux.empty(), mimeTypes); |
|
|
|
} |
|
|
|
} |
|
|
|
|