From a37efc98813e4f04621b51fc5462af2e205a5941 Mon Sep 17 00:00:00 2001 From: Arjen Poutsma Date: Mon, 22 Oct 2018 12:44:32 +0200 Subject: [PATCH] Add error stream tests for XmlEventDecoder Issue: SPR-17418 --- .../http/codec/xml/XmlEventDecoderTests.java | 34 +++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/spring-web/src/test/java/org/springframework/http/codec/xml/XmlEventDecoderTests.java b/spring-web/src/test/java/org/springframework/http/codec/xml/XmlEventDecoderTests.java index 3498b0ea01..8ad075cbeb 100644 --- a/spring-web/src/test/java/org/springframework/http/codec/xml/XmlEventDecoderTests.java +++ b/spring-web/src/test/java/org/springframework/http/codec/xml/XmlEventDecoderTests.java @@ -24,9 +24,9 @@ import reactor.core.publisher.Flux; import reactor.test.StepVerifier; import org.springframework.core.io.buffer.AbstractDataBufferAllocatingTestCase; +import org.springframework.core.io.buffer.DataBuffer; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; /** * @author Arjen Poutsma @@ -83,6 +83,36 @@ public class XmlEventDecoderTests extends AbstractDataBufferAllocatingTestCase { .verify(); } + @Test + public void decodeErrorAalto() { + Flux source = Flux.just(stringBuffer("")) + .concatWith(Flux.error(new RuntimeException())); + + Flux events = + this.decoder.decode(source, null, null, Collections.emptyMap()); + + StepVerifier.create(events) + .consumeNextWith(e -> assertTrue(e.isStartDocument())) + .consumeNextWith(e -> assertStartElement(e, "pojo")) + .expectError(RuntimeException.class) + .verify(); + } + + @Test + public void decodeErrorNonAalto() { + decoder.useAalto = false; + + Flux source = Flux.just(stringBuffer("")) + .concatWith(Flux.error(new RuntimeException())); + + Flux events = + this.decoder.decode(source, null, null, Collections.emptyMap()); + + StepVerifier.create(events) + .expectError(RuntimeException.class) + .verify(); + } + private static void assertStartElement(XMLEvent event, String expectedLocalName) { assertTrue(event.isStartElement()); assertEquals(expectedLocalName, event.asStartElement().getName().getLocalPart());