Package org.apache.http.nio.protocol.HttpAsyncServiceHandler

Examples of org.apache.http.nio.protocol.HttpAsyncServiceHandler.HttpExchange


        Mockito.verify(this.conn).shutdown();
    }

    @Test
    public void testResponseContent() throws Exception {
        HttpExchange httpExchange = this.protocolHandler.new HttpExchange();
        BasicHttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
        response.setEntity(NStringEntity.create("stuff"));
        httpExchange.setRequestState(MessageState.COMPLETED);
        httpExchange.setResponseState(MessageState.BODY_STREAM);
        httpExchange.setResponse(response);
        httpExchange.setResponseProducer(this.responseProducer);
        this.connContext.setAttribute(HttpAsyncServiceHandler.HTTP_EXCHANGE, httpExchange);
        Mockito.when(this.encoder.isCompleted()).thenReturn(false);

        this.protocolHandler.outputReady(conn, this.encoder);

        Assert.assertEquals(MessageState.COMPLETED, httpExchange.getRequestState());
        Assert.assertEquals(MessageState.BODY_STREAM, httpExchange.getResponseState());

        Mockito.verify(this.responseProducer).produceContent(this.encoder, this.conn);
        Mockito.verify(this.conn, Mockito.never()).requestInput();
        Mockito.verify(this.conn, Mockito.never()).close();
    }
View Full Code Here


        Mockito.verify(this.conn, Mockito.never()).close();
    }

    @Test
    public void testResponseContentCompleted() throws Exception {
        HttpExchange httpExchange = this.protocolHandler.new HttpExchange();
        HttpContext exchangeContext = httpExchange.getContext();
        BasicHttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
        response.setEntity(NStringEntity.create("stuff"));
        httpExchange.setRequestState(MessageState.COMPLETED);
        httpExchange.setResponseState(MessageState.BODY_STREAM);
        httpExchange.setResponse(response);
        httpExchange.setResponseProducer(this.responseProducer);
        this.connContext.setAttribute(HttpAsyncServiceHandler.HTTP_EXCHANGE, httpExchange);
        Mockito.when(this.encoder.isCompleted()).thenReturn(true);
        Mockito.when(this.reuseStrategy.keepAlive(response, exchangeContext)).thenReturn(true);

        this.protocolHandler.outputReady(conn, this.encoder);

        Assert.assertEquals(MessageState.READY, httpExchange.getRequestState());
        Assert.assertEquals(MessageState.READY, httpExchange.getResponseState());

        Mockito.verify(this.responseProducer).produceContent(this.encoder, this.conn);
        Mockito.verify(this.responseProducer).responseCompleted(exchangeContext);
        Mockito.verify(this.conn).requestInput();
        Mockito.verify(this.conn, Mockito.never()).close();
View Full Code Here

        Mockito.verify(this.conn, Mockito.never()).close();
    }

    @Test
    public void testResponseContentCompletedNoKeepAlive() throws Exception {
        HttpExchange httpExchange = this.protocolHandler.new HttpExchange();
        HttpContext exchangeContext = httpExchange.getContext();
        BasicHttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
        response.setEntity(NStringEntity.create("stuff"));
        httpExchange.setRequestState(MessageState.COMPLETED);
        httpExchange.setResponseState(MessageState.BODY_STREAM);
        httpExchange.setResponse(response);
        httpExchange.setResponseProducer(this.responseProducer);
        this.connContext.setAttribute(HttpAsyncServiceHandler.HTTP_EXCHANGE, httpExchange);
        Mockito.when(this.encoder.isCompleted()).thenReturn(true);
        Mockito.when(this.reuseStrategy.keepAlive(response, exchangeContext)).thenReturn(false);

        this.protocolHandler.outputReady(conn, this.encoder);

        Assert.assertEquals(MessageState.READY, httpExchange.getRequestState());
        Assert.assertEquals(MessageState.READY, httpExchange.getResponseState());

        Mockito.verify(this.responseProducer).produceContent(this.encoder, this.conn);
        Mockito.verify(this.responseProducer).responseCompleted(exchangeContext);
        Mockito.verify(this.conn, Mockito.never()).requestInput();
        Mockito.verify(this.conn).close();
View Full Code Here

        Mockito.verify(this.conn).close();
    }

    @Test
    public void testResponseContentRuntimeException() throws Exception {
        HttpExchange httpExchange = this.protocolHandler.new HttpExchange();
        BasicHttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
        response.setEntity(NStringEntity.create("stuff"));
        httpExchange.setRequestState(MessageState.COMPLETED);
        httpExchange.setResponseState(MessageState.BODY_STREAM);
        httpExchange.setResponse(response);
        httpExchange.setResponseProducer(this.responseProducer);
        this.connContext.setAttribute(HttpAsyncServiceHandler.HTTP_EXCHANGE, httpExchange);
        Mockito.when(this.encoder.isCompleted()).thenReturn(false);

        Mockito.doThrow(new RuntimeException()).when(
                this.responseProducer).produceContent(this.encoder, this.conn);
View Full Code Here

        }
    }

    @Test
    public void testResponseContentIOException() throws Exception {
        HttpExchange httpExchange = this.protocolHandler.new HttpExchange();
        BasicHttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK");
        response.setEntity(NStringEntity.create("stuff"));
        httpExchange.setRequestState(MessageState.COMPLETED);
        httpExchange.setResponseState(MessageState.BODY_STREAM);
        httpExchange.setResponse(response);
        httpExchange.setResponseProducer(this.responseProducer);
        this.connContext.setAttribute(HttpAsyncServiceHandler.HTTP_EXCHANGE, httpExchange);
        Mockito.when(this.encoder.isCompleted()).thenReturn(false);

        Mockito.doThrow(new IOException()).when(
                this.responseProducer).produceContent(this.encoder, this.conn);
View Full Code Here

        Mockito.verify(this.conn).shutdown();
    }

    @Test
    public void testTimeoutActiveConnection() throws Exception {
        HttpExchange httpExchange = this.protocolHandler.new HttpExchange();
        this.connContext.setAttribute(HttpAsyncServiceHandler.HTTP_EXCHANGE, httpExchange);
        Mockito.when(this.conn.getStatus()).thenReturn(NHttpClientConnection.ACTIVE, NHttpClientConnection.CLOSED);

        this.protocolHandler.timeout(this.conn);
View Full Code Here

        Mockito.verify(this.conn, Mockito.never()).setSocketTimeout(Mockito.anyInt());
    }

    @Test
    public void testTimeoutActiveConnectionBufferedData() throws Exception {
        HttpExchange httpExchange = this.protocolHandler.new HttpExchange();
        this.connContext.setAttribute(HttpAsyncServiceHandler.HTTP_EXCHANGE, httpExchange);
        Mockito.when(this.conn.getStatus()).thenReturn(NHttpClientConnection.ACTIVE, NHttpClientConnection.CLOSING);

        this.protocolHandler.timeout(this.conn);
View Full Code Here

        Mockito.verify(this.conn).setSocketTimeout(250);
    }

    @Test
    public void testTimeoutClosingConnection() throws Exception {
        HttpExchange httpExchange = this.protocolHandler.new HttpExchange();
        this.connContext.setAttribute(HttpAsyncServiceHandler.HTTP_EXCHANGE, httpExchange);
        Mockito.when(this.conn.getStatus()).thenReturn(NHttpClientConnection.CLOSING);

        this.protocolHandler.timeout(this.conn);
View Full Code Here

    @Test
    public void testConnected() throws Exception {
        this.protocolHandler.connected(this.conn);

        HttpExchange httpExchange = (HttpExchange) this.connContext.getAttribute(
                HttpAsyncServiceHandler.HTTP_EXCHANGE);
        Assert.assertNotNull(httpExchange);
        Assert.assertEquals(MessageState.READY, httpExchange.getRequestState());
        Assert.assertEquals(MessageState.READY, httpExchange.getResponseState());
        Assert.assertEquals("request state: READY; request: ; " +
                "response state: READY; response: ;", httpExchange.toString());
    }
View Full Code Here

                "response state: READY; response: ;", httpExchange.toString());
    }

    @Test
    public void testClosed() throws Exception {
        HttpExchange httpExchange = this.protocolHandler.new HttpExchange();
        httpExchange.setRequestState(MessageState.COMPLETED);
        httpExchange.setResponseState(MessageState.COMPLETED);
        httpExchange.setRequestConsumer(this.requestConsumer);
        httpExchange.setResponseProducer(this.responseProducer);
        httpExchange.setAsyncProcess(this.cancellable);
        this.connContext.setAttribute(HttpAsyncServiceHandler.HTTP_EXCHANGE, httpExchange);

        this.protocolHandler.closed(this.conn);

        Assert.assertEquals(MessageState.READY, httpExchange.getRequestState());
        Assert.assertEquals(MessageState.READY, httpExchange.getResponseState());
        Mockito.verify(this.requestConsumer).close();
        Mockito.verify(this.responseProducer).close();
        Mockito.verify(this.cancellable).cancel();
    }
View Full Code Here

TOP

Related Classes of org.apache.http.nio.protocol.HttpAsyncServiceHandler.HttpExchange

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.