Package org.apache.http.nio.protocol.HttpAsyncService

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


        }));
    }

    @Test
    public void testResponseFailedExpectation() throws Exception {
        State state = new HttpAsyncService.State();
        HttpContext exchangeContext = state.getContext();
        BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/",
                HttpVersion.HTTP_1_1);
        state.setRequest(request);
        state.setRequestState(MessageState.ACK_EXPECTED);
        state.setResponseProducer(this.responseProducer);
        this.connContext.setAttribute(HttpAsyncService.HTTP_EXCHANGE_STATE, state);

        BasicHttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 417, "Expectation failed");
        response.setEntity(new NStringEntity("stuff"));
        Mockito.when(this.responseProducer.generateResponse()).thenReturn(response);

        this.protocolHandler.responseReady(this.conn);

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

        Mockito.verify(this.conn).resetInput();
        Mockito.verify(this.httpProcessor).process(response, exchangeContext);
        Mockito.verify(this.conn).submitResponse(response);
        Mockito.verify(this.responseProducer, Mockito.never()).responseCompleted(exchangeContext);
View Full Code Here


        Mockito.verify(this.responseProducer, Mockito.never()).responseCompleted(exchangeContext);
    }

    @Test(expected=HttpException.class)
    public void testInvalidResponseStatus() throws Exception {
        State state = new HttpAsyncService.State();
        BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/",
                HttpVersion.HTTP_1_1);
        state.setRequest(request);
        state.setRequestState(MessageState.COMPLETED);
        state.setResponseState(MessageState.READY);
        state.setResponseProducer(this.responseProducer);
        this.connContext.setAttribute(HttpAsyncService.HTTP_EXCHANGE_STATE, state);

        BasicHttpResponse response = new BasicHttpResponse(HttpVersion.HTTP_1_1, 112, "Something stupid");
        Mockito.when(this.responseProducer.generateResponse()).thenReturn(response);
        Mockito.when(this.conn.isResponseSubmitted()).thenReturn(false);
View Full Code Here

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

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

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

    @Test
    public void testClosed() throws Exception {
        State state = new HttpAsyncService.State();
        state.setRequestState(MessageState.COMPLETED);
        state.setResponseState(MessageState.COMPLETED);
        state.setRequestConsumer(this.requestConsumer);
        state.setResponseProducer(this.responseProducer);
        state.setCancellable(this.cancellable);
        this.connContext.setAttribute(HttpAsyncService.HTTP_EXCHANGE_STATE, state);

        this.protocolHandler.closed(this.conn);

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

        Mockito.verify(this.cancellable).cancel();
    }

    @Test
    public void testHttpExceptionHandling() throws Exception {
        State state = new HttpAsyncService.State();
        state.setRequestState(MessageState.READY);
        state.setResponseState(MessageState.READY);
        state.setRequestConsumer(this.requestConsumer);
        state.setCancellable(this.cancellable);
        this.connContext.setAttribute(HttpAsyncService.HTTP_EXCHANGE_STATE, state);

        HttpException httpex = new HttpException();
        this.protocolHandler.exception(this.conn, httpex);

        Assert.assertEquals(MessageState.READY, state.getRequestState());
        Assert.assertEquals(MessageState.BODY_STREAM, state.getResponseState());
        Assert.assertNotNull(state.getResponseProducer());
        Assert.assertNotNull(state.getResponse());
        Assert.assertEquals(500, state.getResponse().getStatusLine().getStatusCode());

        Mockito.verify(this.requestConsumer).failed(httpex);
        Mockito.verify(this.requestConsumer).close();
        Mockito.verify(this.cancellable).cancel();
        Mockito.verify(this.conn, Mockito.never()).shutdown();
View Full Code Here

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

    @Test
    public void testHttpExceptionHandlingRuntimeException() throws Exception {
        State state = new HttpAsyncService.State();
        HttpContext exchangeContext = state.getContext();
        state.setRequestState(MessageState.READY);
        state.setResponseState(MessageState.READY);
        state.setRequestConsumer(this.requestConsumer);
        state.setResponseProducer(this.responseProducer);
        state.setCancellable(this.cancellable);
        this.connContext.setAttribute(HttpAsyncService.HTTP_EXCHANGE_STATE, state);

        Mockito.doThrow(new RuntimeException()).when(this.httpProcessor).process(
                Mockito.any(HttpResponse.class), Mockito.eq(exchangeContext));
        HttpException httpex = new HttpException();
View Full Code Here

        }
    }

    @Test
    public void testHttpExceptionHandlingIOException() throws Exception {
        State state = new HttpAsyncService.State();
        HttpContext exchangeContext = state.getContext();
        state.setRequestState(MessageState.READY);
        state.setResponseState(MessageState.READY);
        state.setRequestConsumer(this.requestConsumer);
        state.setResponseProducer(this.responseProducer);
        state.setCancellable(this.cancellable);
        this.connContext.setAttribute(HttpAsyncService.HTTP_EXCHANGE_STATE, state);

        Mockito.doThrow(new IOException()).when(this.httpProcessor).process(
                Mockito.any(HttpResponse.class), Mockito.eq(exchangeContext));
        HttpException httpex = new HttpException();
View Full Code Here

        Mockito.verify(this.cancellable).cancel();
    }

    @Test
    public void testHttpExceptionHandlingResponseSubmitted() throws Exception {
        State state = new HttpAsyncService.State();
        state.setRequestState(MessageState.READY);
        state.setResponseState(MessageState.READY);
        state.setRequestConsumer(this.requestConsumer);
        state.setResponseProducer(this.responseProducer);
        this.connContext.setAttribute(HttpAsyncService.HTTP_EXCHANGE_STATE, state);
        Mockito.when(this.conn.isResponseSubmitted()).thenReturn(true);

        HttpException httpex = new HttpException();
        this.protocolHandler.exception(this.conn, httpex);

        Assert.assertEquals(MessageState.READY, state.getRequestState());
        Assert.assertEquals(MessageState.READY, state.getResponseState());
        Mockito.verify(this.conn).close();
        Mockito.verify(this.requestConsumer).failed(httpex);
        Mockito.verify(this.requestConsumer).close();
        Mockito.verify(this.responseProducer).failed(httpex);
        Mockito.verify(this.responseProducer).close();
View Full Code Here

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

    @Test
    public void testIOExceptionHandling() throws Exception {
        State state = new HttpAsyncService.State();
        state.setRequestState(MessageState.READY);
        state.setResponseState(MessageState.READY);
        state.setRequestConsumer(this.requestConsumer);
        state.setResponseProducer(this.responseProducer);
        this.connContext.setAttribute(HttpAsyncService.HTTP_EXCHANGE_STATE, state);

        IOException httpex = new IOException();
        this.protocolHandler.exception(this.conn, httpex);

        Assert.assertEquals(MessageState.READY, state.getRequestState());
        Assert.assertEquals(MessageState.READY, state.getResponseState());
        Mockito.verify(this.conn).shutdown();
        Mockito.verify(this.requestConsumer).failed(httpex);
        Mockito.verify(this.requestConsumer).close();
        Mockito.verify(this.responseProducer).failed(httpex);
        Mockito.verify(this.responseProducer).close();
View Full Code Here

        }
    }

    @Test(expected=IllegalArgumentException.class)
    public void testRequestExpectationFailedInvalidResponseProducer() throws Exception {
        State state = new HttpAsyncService.State();
        state.setRequestState(MessageState.ACK_EXPECTED);
        this.connContext.setAttribute(HttpAsyncService.HTTP_EXCHANGE_STATE, state);

        HttpAsyncExchange httpexchanage = new HttpAsyncService.Exchange(
                new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1),
                new BasicHttpResponse(HttpVersion.HTTP_1_1, 200, "OK"),
View Full Code Here

TOP

Related Classes of org.apache.http.nio.protocol.HttpAsyncService.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.