Example usage for io.netty.handler.codec.http LastHttpContent duplicate

List of usage examples for io.netty.handler.codec.http LastHttpContent duplicate

Introduction

In this page you can find the example usage for io.netty.handler.codec.http LastHttpContent duplicate.

Prototype

@Override
    LastHttpContent duplicate();

Source Link

Usage

From source file:org.ebayopensource.scc.filter.NettyResponseProxyFilterTest.java

License:Apache License

@Test
public void testFilterChunkeResponses() throws InterruptedException {
    PolicyManager policyManager = mock(PolicyManager.class);
    AppConfiguration appConfig = mock(AppConfiguration.class);
    when(appConfig.getBoolean(AppConfiguration.KEY_DEBUG_INFO)).thenReturn(true);

    ExecutorService tp = Executors.newCachedThreadPool();
    NettyResponseProxyFilter filter = new NettyResponseProxyFilter(policyManager, tp);

    ChannelHandlerContext ctx = mock(ChannelHandlerContext.class);
    when(ctx.attr(any(AttributeKey.class))).thenReturn(mock(Attribute.class));
    Attribute cachable = mock(Attribute.class);
    when(ctx.attr(NettyRequestProxyFilter.IS_CACHABLE)).thenReturn(cachable);
    when(cachable.get()).thenReturn(Boolean.TRUE);

    Attribute cacheKey = mock(Attribute.class);
    when(ctx.attr(NettyRequestProxyFilter.CACHE_KEY)).thenReturn(cacheKey);
    when(cacheKey.get()).thenReturn("key");

    HttpResponse resp = mock(HttpResponse.class);
    when(resp.getStatus()).thenReturn(HttpResponseStatus.OK);
    filter.filterResponse(resp, ctx);//from w  w w  .  j  a  v a2 s.c  o m
    HttpContent httpContent = mock(HttpContent.class);
    when(httpContent.duplicate()).thenReturn(mock(HttpContent.class));
    filter.filterResponse(httpContent, ctx);
    LastHttpContent lastHttpContent = mock(LastHttpContent.class);
    when(lastHttpContent.duplicate()).thenReturn(mock(LastHttpContent.class));
    filter.filterResponse(lastHttpContent, ctx);

    filter.filterResponse(resp, ctx);
    filter.filterResponse(lastHttpContent, ctx);

    tp.awaitTermination(10, TimeUnit.SECONDS);
}