use of io.netty.channel.embedded.EmbeddedChannel in project netty by netty.
the class Socks5CommandRequestDecoderTest method test.
private static void test(Socks5CommandType type, Socks5AddressType dstAddrType, String dstAddr, int dstPort) {
logger.debug("Testing type: " + type + " dstAddrType: " + dstAddrType + " dstAddr: " + dstAddr + " dstPort: " + dstPort);
Socks5CommandRequest msg = new DefaultSocks5CommandRequest(type, dstAddrType, dstAddr, dstPort);
EmbeddedChannel embedder = new EmbeddedChannel(new Socks5CommandRequestDecoder());
Socks5CommonTestUtils.writeFromClientToServer(embedder, msg);
msg = embedder.readInbound();
assertSame(msg.type(), type);
assertSame(msg.dstAddrType(), dstAddrType);
assertEquals(msg.dstAddr(), IDN.toASCII(dstAddr));
assertEquals(msg.dstPort(), dstPort);
assertNull(embedder.readInbound());
}
use of io.netty.channel.embedded.EmbeddedChannel in project netty by netty.
the class SmtpRequestEncoderTest method testEncodeDataAndContent.
@Test
public void testEncodeDataAndContent() {
EmbeddedChannel channel = new EmbeddedChannel(new SmtpRequestEncoder());
assertTrue(channel.writeOutbound(SmtpRequests.data()));
assertTrue(channel.writeOutbound(new DefaultSmtpContent(Unpooled.copiedBuffer("Subject: Test\r\n\r\n", CharsetUtil.US_ASCII))));
assertTrue(channel.writeOutbound(new DefaultLastSmtpContent(Unpooled.copiedBuffer("Test\r\n", CharsetUtil.US_ASCII))));
assertTrue(channel.finish());
ByteBuf written = Unpooled.buffer();
for (; ; ) {
ByteBuf buffer = channel.readOutbound();
if (buffer == null) {
break;
}
written.writeBytes(buffer);
buffer.release();
}
assertEquals("DATA\r\nSubject: Test\r\n\r\nTest\r\n.\r\n", written.toString(CharsetUtil.US_ASCII));
written.release();
}
use of io.netty.channel.embedded.EmbeddedChannel in project netty by netty.
the class SmtpRequestEncoderTest method testEncode.
private static void testEncode(SmtpRequest request, String expected) {
EmbeddedChannel channel = new EmbeddedChannel(new SmtpRequestEncoder());
assertTrue(channel.writeOutbound(request));
assertTrue(channel.finish());
ByteBuf buffer = channel.readOutbound();
assertEquals(expected, buffer.toString(CharsetUtil.US_ASCII));
buffer.release();
assertNull(channel.readOutbound());
}
use of io.netty.channel.embedded.EmbeddedChannel in project netty by netty.
the class SmtpResponseDecoderTest method testDecodeTwoLineResponseChunked.
@Test
public void testDecodeTwoLineResponseChunked() {
EmbeddedChannel channel = newChannel();
assertFalse(channel.writeInbound(newBuffer("200-")));
assertFalse(channel.writeInbound(newBuffer("Hello\r\n2")));
assertFalse(channel.writeInbound(newBuffer("00 Ok")));
assertTrue(channel.writeInbound(newBuffer("\r\n")));
assertTrue(channel.finish());
SmtpResponse response = channel.readInbound();
assertEquals(200, response.code());
List<CharSequence> sequences = response.details();
assertEquals(2, sequences.size());
assertEquals("Hello", sequences.get(0).toString());
assertEquals("Ok", sequences.get(1).toString());
assertNull(channel.readInbound());
}
use of io.netty.channel.embedded.EmbeddedChannel in project netty by netty.
the class SmtpResponseDecoderTest method testDecodeTwoLineResponse.
@Test
public void testDecodeTwoLineResponse() {
EmbeddedChannel channel = newChannel();
assertTrue(channel.writeInbound(newBuffer("200-Hello\r\n200 Ok\r\n")));
assertTrue(channel.finish());
SmtpResponse response = channel.readInbound();
assertEquals(200, response.code());
List<CharSequence> sequences = response.details();
assertEquals(2, sequences.size());
assertEquals("Hello", sequences.get(0).toString());
assertEquals("Ok", sequences.get(1).toString());
assertNull(channel.readInbound());
}
Aggregations