Adding method to assert XML decoder framing works
Motivation: In an effort to better understand how the XmlFrameDecoder works, I consulted the tests to find a method that would reframe the inputs as per the Javadocs for that class. I couldn't find any methods that seemed to be doing it, so I wanted to add one to reinforce my understanding. Modification: Add a new test method to XmlFrameDecoder to assert that the reframing works as described. Result: New test method is added to XmlFrameDecoder
This commit is contained in:
parent
61f53c4d07
commit
476d2aea76
@ -142,6 +142,11 @@ public class XmlFrameDecoderTest {
|
|||||||
testDecodeWithXml(input, frame1, frame2, frame3);
|
testDecodeWithXml(input, frame1, frame2, frame3);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testFraming() {
|
||||||
|
testDecodeWithXml(Arrays.asList("<abc", ">123</a", "bc>"), "<abc>123</abc>");
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testDecodeWithSampleXml() {
|
public void testDecodeWithSampleXml() {
|
||||||
for (final String xmlSample : xmlSamples) {
|
for (final String xmlSample : xmlSamples) {
|
||||||
@ -149,11 +154,13 @@ public class XmlFrameDecoderTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void testDecodeWithXml(String xml, Object... expected) {
|
private static void testDecodeWithXml(List<String> xmlFrames, Object... expected) {
|
||||||
EmbeddedChannel ch = new EmbeddedChannel(new XmlFrameDecoder(1048576));
|
EmbeddedChannel ch = new EmbeddedChannel(new XmlFrameDecoder(1048576));
|
||||||
Exception cause = null;
|
Exception cause = null;
|
||||||
try {
|
try {
|
||||||
ch.writeInbound(Unpooled.copiedBuffer(xml, CharsetUtil.UTF_8));
|
for (String xmlFrame : xmlFrames) {
|
||||||
|
ch.writeInbound(Unpooled.copiedBuffer(xmlFrame, CharsetUtil.UTF_8));
|
||||||
|
}
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
cause = e;
|
cause = e;
|
||||||
}
|
}
|
||||||
@ -180,6 +187,10 @@ public class XmlFrameDecoderTest {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void testDecodeWithXml(String xml, Object... expected) {
|
||||||
|
testDecodeWithXml(Collections.singletonList(xml), expected);
|
||||||
|
}
|
||||||
|
|
||||||
private String sample(String number) throws IOException, URISyntaxException {
|
private String sample(String number) throws IOException, URISyntaxException {
|
||||||
String path = "io/netty/handler/codec/xml/sample-" + number + ".xml";
|
String path = "io/netty/handler/codec/xml/sample-" + number + ".xml";
|
||||||
URL url = getClass().getClassLoader().getResource(path);
|
URL url = getClass().getClassLoader().getResource(path);
|
||||||
|
Loading…
Reference in New Issue
Block a user