Fix error handling regression for non-streaming Flux

Closes gh-29038
This commit is contained in:
rstoyanchev
2022-09-14 10:47:05 +01:00
parent 3307630a95
commit e370c15bc6
2 changed files with 34 additions and 12 deletions

View File

@@ -137,21 +137,30 @@ public class Jackson2JsonEncoderTests extends AbstractEncoderTests<Jackson2JsonE
);
testEncode(input, Pojo.class, step -> step
.consumeNextWith(expectString("["))
.consumeNextWith(expectString("{\"foo\":\"foo\",\"bar\":\"bar\"}"))
.consumeNextWith(expectString("[{\"foo\":\"foo\",\"bar\":\"bar\"}"))
.consumeNextWith(expectString(",{\"foo\":\"foofoo\",\"bar\":\"barbar\"}"))
.consumeNextWith(expectString(",{\"foo\":\"foofoofoo\",\"bar\":\"barbarbar\"}"))
.consumeNextWith(expectString("]"))
.verifyComplete());
}
@Test // gh-29038
void encodeNonStreamWithErrorAsFirstSignal() {
String message = "I'm a teapot";
Flux<Object> input = Flux.error(new IllegalStateException(message));
Flux<DataBuffer> output = this.encoder.encode(
input, this.bufferFactory, ResolvableType.forClass(Pojo.class), null, null);
StepVerifier.create(output).expectErrorMessage(message).verify();
}
@Test
public void encodeWithType() {
Flux<ParentClass> input = Flux.just(new Foo(), new Bar());
testEncode(input, ParentClass.class, step -> step
.consumeNextWith(expectString("["))
.consumeNextWith(expectString("{\"type\":\"foo\"}"))
.consumeNextWith(expectString("[{\"type\":\"foo\"}"))
.consumeNextWith(expectString(",{\"type\":\"bar\"}"))
.consumeNextWith(expectString("]"))
.verifyComplete());
@@ -159,7 +168,7 @@ public class Jackson2JsonEncoderTests extends AbstractEncoderTests<Jackson2JsonE
@Test // SPR-15727
public void encodeAsStreamWithCustomStreamingType() {
public void encodeStreamWithCustomStreamingType() {
MediaType fooMediaType = new MediaType("application", "foo");
MediaType barMediaType = new MediaType("application", "bar");
this.encoder.setStreamingMediaTypes(Arrays.asList(fooMediaType, barMediaType));
@@ -263,8 +272,7 @@ public class Jackson2JsonEncoderTests extends AbstractEncoderTests<Jackson2JsonE
ResolvableType.forClass(Pojo.class), MimeTypeUtils.APPLICATION_JSON, Collections.emptyMap());
StepVerifier.create(result)
.consumeNextWith(expectString("["))
.consumeNextWith(expectString("{\"foo\":\"foo\",\"bar\":\"bar\"}"))
.consumeNextWith(expectString("[{\"foo\":\"foo\",\"bar\":\"bar\"}"))
.consumeNextWith(expectString("]"))
.expectComplete()
.verify(Duration.ofSeconds(5));