Skip to content

Commit a37efc9

Browse files
committed
Add error stream tests for XmlEventDecoder
Issue: SPR-17418
1 parent f738273 commit a37efc9

File tree

1 file changed

+32
-2
lines changed

1 file changed

+32
-2
lines changed

spring-web/src/test/java/org/springframework/http/codec/xml/XmlEventDecoderTests.java

Lines changed: 32 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,9 @@
2424
import reactor.test.StepVerifier;
2525

2626
import org.springframework.core.io.buffer.AbstractDataBufferAllocatingTestCase;
27+
import org.springframework.core.io.buffer.DataBuffer;
2728

28-
import static org.junit.Assert.assertEquals;
29-
import static org.junit.Assert.assertTrue;
29+
import static org.junit.Assert.*;
3030

3131
/**
3232
* @author Arjen Poutsma
@@ -83,6 +83,36 @@ public void toXMLEventsNonAalto() {
8383
.verify();
8484
}
8585

86+
@Test
87+
public void decodeErrorAalto() {
88+
Flux<DataBuffer> source = Flux.just(stringBuffer("<pojo>"))
89+
.concatWith(Flux.error(new RuntimeException()));
90+
91+
Flux<XMLEvent> events =
92+
this.decoder.decode(source, null, null, Collections.emptyMap());
93+
94+
StepVerifier.create(events)
95+
.consumeNextWith(e -> assertTrue(e.isStartDocument()))
96+
.consumeNextWith(e -> assertStartElement(e, "pojo"))
97+
.expectError(RuntimeException.class)
98+
.verify();
99+
}
100+
101+
@Test
102+
public void decodeErrorNonAalto() {
103+
decoder.useAalto = false;
104+
105+
Flux<DataBuffer> source = Flux.just(stringBuffer("<pojo>"))
106+
.concatWith(Flux.error(new RuntimeException()));
107+
108+
Flux<XMLEvent> events =
109+
this.decoder.decode(source, null, null, Collections.emptyMap());
110+
111+
StepVerifier.create(events)
112+
.expectError(RuntimeException.class)
113+
.verify();
114+
}
115+
86116
private static void assertStartElement(XMLEvent event, String expectedLocalName) {
87117
assertTrue(event.isStartElement());
88118
assertEquals(expectedLocalName, event.asStartElement().getName().getLocalPart());

0 commit comments

Comments
 (0)