use of io.netty.channel.embedded.EmbeddedChannel in project netty by netty.
the class JsonObjectDecoderTest method testSingleByteStream.
@Test
public void testSingleByteStream() {
EmbeddedChannel ch = new EmbeddedChannel(new JsonObjectDecoder());
String json = "{\"foo\" : {\"bar\" : [{},{}]}}";
for (byte c : json.getBytes(CharsetUtil.UTF_8)) {
ch.writeInbound(Unpooled.copiedBuffer(new byte[] { c }));
}
ByteBuf res = ch.readInbound();
assertEquals(json, res.toString(CharsetUtil.UTF_8));
res.release();
assertFalse(ch.finish());
}
use of io.netty.channel.embedded.EmbeddedChannel in project netty by netty.
the class JsonObjectDecoderTest method testMaxObjectLength.
@Test(expected = TooLongFrameException.class)
public void testMaxObjectLength() {
EmbeddedChannel ch = new EmbeddedChannel(new JsonObjectDecoder(6));
try {
ch.writeInbound(Unpooled.copiedBuffer("[2,4,5]", CharsetUtil.UTF_8));
} finally {
assertFalse(ch.finish());
}
fail();
}
use of io.netty.channel.embedded.EmbeddedChannel in project netty by netty.
the class JsonObjectDecoderTest method testNonJsonContent1.
@Test(expected = CorruptedFrameException.class)
public void testNonJsonContent1() {
EmbeddedChannel ch = new EmbeddedChannel(new JsonObjectDecoder());
try {
ch.writeInbound(Unpooled.copiedBuffer(" b [1,2,3]", CharsetUtil.UTF_8));
} finally {
assertFalse(ch.finish());
}
fail();
}
use of io.netty.channel.embedded.EmbeddedChannel in project netty by netty.
the class JsonObjectDecoderTest method testBackslashInString1.
@Test
public void testBackslashInString1() {
EmbeddedChannel ch = new EmbeddedChannel(new JsonObjectDecoder());
// {"foo" : "bar\""}
String json = "{\"foo\" : \"bar\\\"\"}";
System.out.println(json);
ch.writeInbound(Unpooled.copiedBuffer(json, CharsetUtil.UTF_8));
ByteBuf res = ch.readInbound();
assertEquals(json, res.toString(CharsetUtil.UTF_8));
res.release();
assertFalse(ch.finish());
}
use of io.netty.channel.embedded.EmbeddedChannel in project netty by netty.
the class JsonObjectDecoderTest method testNonJsonContent2.
@Test(expected = CorruptedFrameException.class)
public void testNonJsonContent2() {
EmbeddedChannel ch = new EmbeddedChannel(new JsonObjectDecoder());
ch.writeInbound(Unpooled.copiedBuffer(" [1,2,3] ", CharsetUtil.UTF_8));
ByteBuf res = ch.readInbound();
assertEquals("[1,2,3]", res.toString(CharsetUtil.UTF_8));
res.release();
try {
ch.writeInbound(Unpooled.copiedBuffer(" a {\"key\" : 10}", CharsetUtil.UTF_8));
} finally {
assertFalse(ch.finish());
}
fail();
}
Aggregations