I tried to create a unit test for HexDumpProxyFrontendHandler from standard examples of netty. But have trouble doing so using EmbeddedChannel. Here is my code:
public class HexDumpProxyFrontendHandlerTest {
@Test
public void test1() throws Exception {
HttpRequest request = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.GET, "/");
HttpUtil.set100ContinueExpected(request, true);
EmbeddedChannel channel = new EmbeddedChannel(new HexDumpProxyFrontendHandler("127.0.0.1", 8080));
channel.writeInbound(request);
}
}
I got java.nio.channels.ClosedChannelException
as I understood the code tried to connect to another server - 127.0.0.1:8080
.
I would like to know is there some way to test this piece of code with EmbeddedChannel? Or I should create some sort of mock server
I start using Moco to create target http server. It's special framework for creating stub servers. I run proxy in another thread and read data via network stream. Now test looks like:
I know that it isn't a unit test but I didn't find any better way than that.
All my experiments with
EmbeddedChannel
class were failed for FrontendHandler. I was able to use this class only with BackendHandler.