Package org.apache.http.nio.protocol.HttpAsyncRequestExecutor

Examples of org.apache.http.nio.protocol.HttpAsyncRequestExecutor.State


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

    @Test
    public void testEndOfInput() throws Exception {
        State state = new HttpAsyncRequestExecutor.State();
        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_EXCHANGE_STATE, state);

        this.protocolHandler.endOfInput(this.conn);

        Mockito.verify(this.conn).close();
View Full Code Here


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

    @Test
    public void testPrematureEndOfInput() throws Exception {
        State state = new HttpAsyncRequestExecutor.State();
        state.setRequestState(MessageState.COMPLETED);
        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_EXCHANGE_STATE, state);
        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, this.exchangeHandler);

        this.protocolHandler.endOfInput(this.conn);

        Assert.assertFalse(state.isValid());

        Mockito.verify(this.conn).close();
        Mockito.verify(this.exchangeHandler).failed(Mockito.any(ConnectionClosedException.class));
    }
View Full Code Here

        Mockito.verify(this.exchangeHandler).failed(Mockito.any(ConnectionClosedException.class));
    }

    @Test
    public void testTimeoutNoHandler() throws Exception {
        State state = new HttpAsyncRequestExecutor.State();
        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_EXCHANGE_STATE, state);

        Mockito.when(this.conn.getStatus()).thenReturn(
                NHttpConnection.ACTIVE, NHttpConnection.CLOSING);
View Full Code Here

        Mockito.when(this.exchangeHandler.generateRequest()).thenReturn(request);
        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, this.exchangeHandler);

        this.protocolHandler.connected(this.conn, null);

        final State state = (State) this.connContext.getAttribute(
                HttpAsyncRequestExecutor.HTTP_EXCHANGE_STATE);
        Assert.assertNotNull(state);
        Mockito.verify(this.exchangeHandler).generateRequest();
        Assert.assertSame(request, state.getRequest());
        Mockito.verify(this.conn).submitRequest(request);
        Mockito.verify(this.exchangeHandler).requestCompleted();
        Assert.assertEquals(MessageState.COMPLETED, state.getRequestState());
        Assert.assertEquals("request state: COMPLETED; request: GET / HTTP/1.1; " +
                "response state: READY; response: ; valid: true;", state.toString());
    }
View Full Code Here

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

    @Test
    public void testClosed() throws Exception {
        final State state = new HttpAsyncRequestExecutor.State();
        state.setRequestState(MessageState.READY);
        state.setResponseState(MessageState.READY);
        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_EXCHANGE_STATE, state);
        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, this.exchangeHandler);

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

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

    @Test
    public void testClosedInconsistentState() throws Exception {
        final State state = new HttpAsyncRequestExecutor.State();
        state.setRequestState(MessageState.COMPLETED);
        state.setResponseState(MessageState.INIT);
        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_EXCHANGE_STATE, state);
        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, this.exchangeHandler);

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

        Mockito.verify(this.exchangeHandler).failed(Mockito.any(ConnectionClosedException.class));
    }

    @Test
    public void testHttpExceptionHandling() throws Exception {
        final State state = new HttpAsyncRequestExecutor.State();
        state.setRequestState(MessageState.COMPLETED);
        state.setResponseState(MessageState.COMPLETED);
        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_EXCHANGE_STATE, state);
        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, this.exchangeHandler);

        final HttpException httpex = new HttpException();
        this.protocolHandler.exception(this.conn, httpex);
View Full Code Here

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

    @Test
    public void testIOExceptionHandling() throws Exception {
        final State state = new HttpAsyncRequestExecutor.State();
        state.setRequestState(MessageState.COMPLETED);
        state.setResponseState(MessageState.COMPLETED);
        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_EXCHANGE_STATE, state);
        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, this.exchangeHandler);

        final IOException ioex = new IOException();
        this.protocolHandler.exception(this.conn, ioex);
View Full Code Here

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

    @Test
    public void testBasicRequest() throws Exception {
        final State state = new HttpAsyncRequestExecutor.State();
        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_EXCHANGE_STATE, state);
        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, this.exchangeHandler);
        final HttpRequest request = new BasicHttpRequest("GET", "/");
        Mockito.when(this.exchangeHandler.generateRequest()).thenReturn(request);

        this.protocolHandler.requestReady(this.conn);

        Mockito.verify(this.exchangeHandler).generateRequest();
        Assert.assertSame(request, state.getRequest());

        Mockito.verify(this.conn).submitRequest(request);
        Mockito.verify(this.exchangeHandler).requestCompleted();
        Assert.assertEquals(MessageState.COMPLETED, state.getRequestState());
    }
View Full Code Here

        Assert.assertEquals(MessageState.COMPLETED, state.getRequestState());
    }

    @Test
    public void testNullRequest() throws Exception {
        final State state = new HttpAsyncRequestExecutor.State();
        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_EXCHANGE_STATE, state);
        this.connContext.setAttribute(HttpAsyncRequestExecutor.HTTP_HANDLER, this.exchangeHandler);
        Mockito.when(this.exchangeHandler.generateRequest()).thenReturn(null);

        this.protocolHandler.requestReady(this.conn);

        Mockito.verify(this.exchangeHandler).generateRequest();
        Assert.assertNull(state.getRequest());

        Mockito.verify(this.conn, Mockito.never()).submitRequest(Mockito.<HttpRequest>any());
    }
View Full Code Here

TOP

Related Classes of org.apache.http.nio.protocol.HttpAsyncRequestExecutor.State

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.