Merge branch '6.1.x'

This commit is contained in:
Sébastien Deleuze
2024-07-09 12:06:29 +02:00
4 changed files with 72 additions and 6 deletions

View File

@@ -22,15 +22,14 @@ import org.junit.jupiter.api.Test
import org.springframework.core.MethodParameter
import org.springframework.core.Ordered
import org.springframework.core.ResolvableType
import org.springframework.core.codec.DecodingException
import org.springframework.core.io.buffer.DataBuffer
import org.springframework.core.io.buffer.DataBufferUtils
import org.springframework.core.testfixture.codec.AbstractDecoderTests
import org.springframework.http.MediaType
import reactor.core.publisher.Flux
import reactor.core.publisher.Mono
import reactor.test.StepVerifier
import reactor.test.StepVerifier.FirstStep
import java.lang.UnsupportedOperationException
import java.math.BigDecimal
import java.nio.charset.Charset
import java.nio.charset.StandardCharsets
@@ -85,6 +84,29 @@ class KotlinSerializationJsonDecoderTests : AbstractDecoderTests<KotlinSerializa
}, null, null)
}
@Test
fun decodeWithUnexpectedFormat() {
val input = Flux.concat(
stringBuffer("{\"ba\":\"b1\",\"fo\":\"f1\"}\n"),
)
testDecode(input, ResolvableType.forClass(Pojo::class.java), { step: FirstStep<Pojo> ->
step
.expectError(DecodingException::class.java)
.verify() }, null, null)
}
@Test
fun decodeToMonoWithUnexpectedFormat() {
val input = Flux.concat(
stringBuffer("{\"ba\":\"b1\",\"fo\":\"f1\"}\n"),
)
testDecodeToMono(input, ResolvableType.forClass(Pojo::class.java), { step: FirstStep<Pojo> ->
step.expectError(DecodingException::class.java)
.verify() }, null, null)
}
@Test
fun decodeStreamWithSingleBuffer() {
val input = Flux.concat(

View File

@@ -24,6 +24,7 @@ import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.springframework.core.Ordered
import org.springframework.core.ResolvableType
import org.springframework.core.codec.DecodingException
import org.springframework.core.io.buffer.DataBuffer
import org.springframework.core.testfixture.codec.AbstractDecoderTests
import org.springframework.http.MediaType
@@ -86,6 +87,21 @@ class KotlinSerializationProtobufDecoderTests : AbstractDecoderTests<KotlinSeria
}, null, null)
}
@Test
fun decodeToMonoWithUnexpectedFormat() {
val input = Mono.just(
bufferFactory.allocateBuffer(0),
)
val elementType = ResolvableType.forClass(Pojo::class.java)
testDecodeToMono(input, elementType, { step: FirstStep<Any> ->
step
.expectError(DecodingException::class.java)
.verify()
}, null, null)
}
private fun byteBuffer(value: Any): Mono<DataBuffer> {
return Mono.defer {
val bytes = ProtoBuf.Default.encodeToByteArray(serializer(Pojo::class.java), value)