Add error stream tests for XmlEventDecoder

Issue: SPR-17418
This commit is contained in:
Arjen Poutsma 2018-10-22 12:44:32 +02:00
parent f738273486
commit a37efc9881
1 changed files with 32 additions and 2 deletions

View File

@ -24,9 +24,9 @@ import reactor.core.publisher.Flux;
import reactor.test.StepVerifier; import reactor.test.StepVerifier;
import org.springframework.core.io.buffer.AbstractDataBufferAllocatingTestCase; 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.*;
import static org.junit.Assert.assertTrue;
/** /**
* @author Arjen Poutsma * @author Arjen Poutsma
@ -83,6 +83,36 @@ public class XmlEventDecoderTests extends AbstractDataBufferAllocatingTestCase {
.verify(); .verify();
} }
@Test
public void decodeErrorAalto() {
Flux<DataBuffer> source = Flux.just(stringBuffer("<pojo>"))
.concatWith(Flux.error(new RuntimeException()));
Flux<XMLEvent> 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<DataBuffer> source = Flux.just(stringBuffer("<pojo>"))
.concatWith(Flux.error(new RuntimeException()));
Flux<XMLEvent> events =
this.decoder.decode(source, null, null, Collections.emptyMap());
StepVerifier.create(events)
.expectError(RuntimeException.class)
.verify();
}
private static void assertStartElement(XMLEvent event, String expectedLocalName) { private static void assertStartElement(XMLEvent event, String expectedLocalName) {
assertTrue(event.isStartElement()); assertTrue(event.isStartElement());
assertEquals(expectedLocalName, event.asStartElement().getName().getLocalPart()); assertEquals(expectedLocalName, event.asStartElement().getName().getLocalPart());