Package org.apache.http

Examples of org.apache.http.WritableByteChannelMock$InternalBuffer


    public void testProduceOutputLongMessageAfterSubmit() throws Exception {
        final BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/");
        final NStringEntity entity = new NStringEntity("a lot of various stuff");
        request.setEntity(entity);

        final WritableByteChannelMock wchannel = Mockito.spy(new WritableByteChannelMock(64));
        final ByteChannelMock channel = new ByteChannelMock(null, wchannel);
        Mockito.when(session.channel()).thenReturn(channel);

        conn.submitRequest(request);
        Assert.assertEquals(19, conn.outbuf.length());

        Mockito.doAnswer(new ProduceContentAnswer(entity)).when(
            handler).outputReady(Mockito.<NHttpClientConnection>any(), Mockito.<ContentEncoder>any());

        conn.produceOutput(handler);

        Assert.assertNull(conn.getHttpRequest());
        Assert.assertNull(conn.contentEncoder);
        Assert.assertEquals("POST / HTTP/1.1\r\n\r\na lot of various stuff", wchannel.dump(Consts.ASCII));

        Mockito.verify(session, Mockito.times(1)).clearEvent(SelectionKey.OP_WRITE);
        Mockito.verify(wchannel, Mockito.times(2)).write(Matchers.<ByteBuffer>any());
    }
View Full Code Here


    public void testProduceOutputShortMessage() throws Exception {
        final BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/");
        final NStringEntity entity = new NStringEntity("stuff");
        request.setEntity(entity);

        final WritableByteChannelMock wchannel = Mockito.spy(new WritableByteChannelMock(64));
        final ByteChannelMock channel = new ByteChannelMock(null, wchannel);
        Mockito.when(session.channel()).thenReturn(channel);

        Mockito.doAnswer(new RequestReadyAnswer(request)).when(
            handler).requestReady(Mockito.<NHttpClientConnection>any());

        Mockito.doAnswer(new ProduceContentAnswer(entity)).when(
            handler).outputReady(Mockito.<NHttpClientConnection>any(), Mockito.<ContentEncoder>any());

        conn.produceOutput(handler);

        Assert.assertNull(conn.getHttpRequest());
        Assert.assertNull(conn.contentEncoder);
        Assert.assertEquals("POST / HTTP/1.1\r\n\r\nstuff", wchannel.dump(Consts.ASCII));

        Mockito.verify(session, Mockito.times(1)).clearEvent(SelectionKey.OP_WRITE);
        Mockito.verify(wchannel, Mockito.times(1)).write(Matchers.<ByteBuffer>any());
    }
View Full Code Here

    public void testProduceOutputLongMessage() throws Exception {
        final BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/");
        final NStringEntity entity = new NStringEntity("a lot of various stuff");
        request.setEntity(entity);

        final WritableByteChannelMock wchannel = Mockito.spy(new WritableByteChannelMock(64));
        final ByteChannelMock channel = new ByteChannelMock(null, wchannel);
        Mockito.when(session.channel()).thenReturn(channel);

        Mockito.doAnswer(new RequestReadyAnswer(request)).when(
            handler).requestReady(Mockito.<NHttpClientConnection>any());

        Mockito.doAnswer(new ProduceContentAnswer(entity)).when(
            handler).outputReady(Mockito.<NHttpClientConnection>any(), Mockito.<ContentEncoder>any());

        conn.produceOutput(handler);

        Assert.assertNull(conn.getHttpRequest());
        Assert.assertNull(conn.contentEncoder);
        Assert.assertEquals("POST / HTTP/1.1\r\n\r\na lot of various stuff", wchannel.dump(Consts.ASCII));

        Mockito.verify(session, Mockito.times(1)).clearEvent(SelectionKey.OP_WRITE);
        Mockito.verify(wchannel, Mockito.times(2)).write(Matchers.<ByteBuffer>any());
    }
View Full Code Here

    public void testProduceOutputLongMessageSaturatedChannel() throws Exception {
        final BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/");
        final NStringEntity entity = new NStringEntity("a lot of various stuff");
        request.setEntity(entity);

        final WritableByteChannelMock wchannel = Mockito.spy(new WritableByteChannelMock(64, 24));
        final ByteChannelMock channel = new ByteChannelMock(null, wchannel);
        Mockito.when(session.channel()).thenReturn(channel);

        Mockito.doAnswer(new RequestReadyAnswer(request)).when(
            handler).requestReady(Mockito.<NHttpClientConnection>any());

        Mockito.doAnswer(new ProduceContentAnswer(entity)).when(
            handler).outputReady(Mockito.<NHttpClientConnection>any(), Mockito.<ContentEncoder>any());

        conn.produceOutput(handler);

        Assert.assertNull(conn.getHttpRequest());
        Assert.assertNull(conn.contentEncoder);
        Assert.assertEquals("POST / HTTP/1.1\r\n\r\na lot", wchannel.dump(Consts.ASCII));
        Assert.assertEquals(17, conn.outbuf.length());

        Mockito.verify(session, Mockito.never()).clearEvent(SelectionKey.OP_WRITE);
        Mockito.verify(wchannel, Mockito.times(2)).write(Matchers.<ByteBuffer>any());
    }
View Full Code Here

        conn = new DefaultNHttpClientConnection(session, 24);
        final BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/");
        final NStringEntity entity = new NStringEntity("a loooooooooooooooooooooooot of various stuff");
        request.setEntity(entity);

        final WritableByteChannelMock wchannel = Mockito.spy(new WritableByteChannelMock(64, 24));
        final ByteChannelMock channel = new ByteChannelMock(null, wchannel);
        Mockito.when(session.channel()).thenReturn(channel);

        Mockito.doAnswer(new RequestReadyAnswer(request)).when(
            handler).requestReady(Mockito.<NHttpClientConnection>any());

        Mockito.doAnswer(new ProduceContentAnswer(entity)).when(
            handler).outputReady(Mockito.<NHttpClientConnection>any(), Mockito.<ContentEncoder>any());

        conn.produceOutput(handler);

        Assert.assertNotNull(conn.getHttpRequest());
        Assert.assertNotNull(conn.contentEncoder);
        Assert.assertEquals("POST / HTTP/1.1\r\n\r\na loo", wchannel.dump(Consts.ASCII));

        Mockito.verify(session, Mockito.never()).clearEvent(SelectionKey.OP_WRITE);
        Mockito.verify(wchannel, Mockito.times(3)).write(Matchers.<ByteBuffer>any());
    }
View Full Code Here

        request.addHeader(HTTP.TRANSFER_ENCODING, HTTP.CHUNK_CODING);
        final NStringEntity entity = new NStringEntity("a lot of various stuff");
        entity.setChunked(true);
        request.setEntity(entity);

        final WritableByteChannelMock wchannel = Mockito.spy(new WritableByteChannelMock(64));
        final ByteChannelMock channel = new ByteChannelMock(null, wchannel);
        Mockito.when(session.channel()).thenReturn(channel);

        Mockito.doAnswer(new RequestReadyAnswer(request)).when(
            handler).requestReady(Mockito.<NHttpClientConnection>any());

        Mockito.doAnswer(new ProduceContentAnswer(entity)).when(
            handler).outputReady(Mockito.<NHttpClientConnection>any(), Mockito.<ContentEncoder>any());

        conn.produceOutput(handler);

        Assert.assertNull(conn.getHttpRequest());
        Assert.assertNull(conn.contentEncoder);
        Assert.assertEquals("POST / HTTP/1.1\r\nTransfer-Encoding: chunked\r\n\r\n" +
                "5\r\na lot\r\n11\r\n of various stuff\r\n0\r\n\r\n", wchannel.dump(Consts.ASCII));

        Mockito.verify(session, Mockito.times(1)).clearEvent(SelectionKey.OP_WRITE);
        Mockito.verify(wchannel, Mockito.times(2)).write(Matchers.<ByteBuffer>any());
    }
View Full Code Here

        request.addHeader(HTTP.TRANSFER_ENCODING, HTTP.CHUNK_CODING);
        final NStringEntity entity = new NStringEntity("a lot of various stuff");
        entity.setChunked(true);
        request.setEntity(entity);

        final WritableByteChannelMock wchannel = Mockito.spy(new WritableByteChannelMock(64, 64));
        final ByteChannelMock channel = new ByteChannelMock(null, wchannel);
        Mockito.when(session.channel()).thenReturn(channel);

        Mockito.doAnswer(new RequestReadyAnswer(request)).when(
            handler).requestReady(Mockito.<NHttpClientConnection>any());

        Mockito.doAnswer(new ProduceContentAnswer(entity)).when(
            handler).outputReady(Mockito.<NHttpClientConnection>any(), Mockito.<ContentEncoder>any());

        conn.produceOutput(handler);

        Assert.assertNull(conn.getHttpRequest());
        Assert.assertNull(conn.contentEncoder);
        Assert.assertEquals("POST / HTTP/1.1\r\nTransfer-Encoding: chunked\r\n\r\n" +
                "5\r\na lot\r\n11\r\n of", wchannel.dump(Consts.ASCII));
        Assert.assertEquals(21, conn.outbuf.length());

        Mockito.verify(session, Mockito.never()).clearEvent(SelectionKey.OP_WRITE);
        Mockito.verify(wchannel, Mockito.times(2)).write(Matchers.<ByteBuffer>any());
    }
View Full Code Here

    @Test
    public void testProduceOutputClosingConnection() throws Exception {
        final BasicHttpRequest request = new BasicHttpRequest("GET", "/");

        final WritableByteChannelMock wchannel = Mockito.spy(new WritableByteChannelMock(64));
        final ByteChannelMock channel = new ByteChannelMock(null, wchannel);
        Mockito.when(session.channel()).thenReturn(channel);

        conn.submitRequest(request);
        conn.close();
View Full Code Here

    public void testProduceOutputShortMessageAfterSubmit() throws Exception {
        final BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/");
        final NStringEntity entity = new NStringEntity("stuff");
        request.setEntity(entity);

        final WritableByteChannelMock wchannel = Mockito.spy(new WritableByteChannelMock(64));
        final ByteChannelMock channel = new ByteChannelMock(null, wchannel);
        Mockito.when(session.channel()).thenReturn(channel);

        conn.submitRequest(request);
        Assert.assertEquals(19, conn.outbuf.length());

        Mockito.doAnswer(new ProduceContentAnswer(entity)).when(
            handler).outputReady(Mockito.<NHttpClientConnection>any(), Mockito.<ContentEncoder>any());

        conn.produceOutput(handler);

        Assert.assertNull(conn.getHttpRequest());
        Assert.assertNull(conn.contentEncoder);
        Assert.assertEquals("POST / HTTP/1.1\r\n\r\nstuff", wchannel.dump(Consts.ASCII));

        Mockito.verify(session, Mockito.times(1)).clearEvent(SelectionKey.OP_WRITE);
        Mockito.verify(wchannel, Mockito.times(1)).write(Matchers.<ByteBuffer>any());
    }
View Full Code Here

    public void testProduceOutputLongMessageAfterSubmit() throws Exception {
        final BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/");
        final NStringEntity entity = new NStringEntity("a lot of various stuff");
        request.setEntity(entity);

        final WritableByteChannelMock wchannel = Mockito.spy(new WritableByteChannelMock(64));
        final ByteChannelMock channel = new ByteChannelMock(null, wchannel);
        Mockito.when(session.channel()).thenReturn(channel);

        conn.submitRequest(request);
        Assert.assertEquals(19, conn.outbuf.length());

        Mockito.doAnswer(new ProduceContentAnswer(entity)).when(
            handler).outputReady(Mockito.<NHttpClientConnection>any(), Mockito.<ContentEncoder>any());

        conn.produceOutput(handler);

        Assert.assertNull(conn.getHttpRequest());
        Assert.assertNull(conn.contentEncoder);
        Assert.assertEquals("POST / HTTP/1.1\r\n\r\na lot of various stuff", wchannel.dump(Consts.ASCII));

        Mockito.verify(session, Mockito.times(1)).clearEvent(SelectionKey.OP_WRITE);
        Mockito.verify(wchannel, Mockito.times(2)).write(Matchers.<ByteBuffer>any());
    }
View Full Code Here

TOP

Related Classes of org.apache.http.WritableByteChannelMock$InternalBuffer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.