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

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


        Assert.assertSame(this.cancellable, httpExchange.getAsyncProcess());
    }

    @Test
    public void testRequestRuntimeException() throws Exception {
        HttpExchange httpExchange = this.protocolHandler.new HttpExchange();
        HttpContext exchangeContext = httpExchange.getContext();
        this.connContext.setAttribute(HttpAsyncServiceHandler.HTTP_EXCHANGE, httpExchange);

        BasicHttpRequest request = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1);
        Mockito.when(this.conn.getHttpRequest()).thenReturn(request);
        Mockito.when(this.requestHandler.processRequest(
View Full Code Here


        }
    }

    @Test
    public void testRequestHttpException() throws Exception {
        HttpExchange httpExchange = this.protocolHandler.new HttpExchange();
        HttpContext exchangeContext = httpExchange.getContext();
        this.connContext.setAttribute(HttpAsyncServiceHandler.HTTP_EXCHANGE, httpExchange);

        BasicHttpRequest request = new BasicHttpRequest("GET", "/", HttpVersion.HTTP_1_1);
        Mockito.when(this.conn.getHttpRequest()).thenReturn(request);
        Mockito.when(this.requestHandler.processRequest(
View Full Code Here

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

    @Test
    public void testRequestExpectationFailed() throws Exception {
        HttpExchange httpExchange = this.protocolHandler.new HttpExchange();
        httpExchange.setRequestState(MessageState.ACK_EXPECTED);
        this.connContext.setAttribute(HttpAsyncServiceHandler.HTTP_EXCHANGE, httpExchange);

        HttpAsyncContinueTrigger trigger = this.protocolHandler.new ContinueTriggerImpl(httpExchange, this.conn);
        Assert.assertFalse(trigger.isTriggered());
        trigger.submitResponse(this.responseProducer);
        Assert.assertTrue(trigger.isTriggered());

        Assert.assertEquals(MessageState.ACK_EXPECTED, httpExchange.getRequestState());
        Assert.assertEquals(MessageState.READY, httpExchange.getResponseState());
        Assert.assertSame(this.responseProducer, httpExchange.getResponseProducer());

        Mockito.verify(this.conn).requestOutput();

        try {
            trigger.continueRequest();
View Full Code Here

        }
    }

    @Test(expected=IllegalArgumentException.class)
    public void testRequestExpectationFailedInvalidResponseProducer() throws Exception {
        HttpExchange httpExchange = this.protocolHandler.new HttpExchange();
        httpExchange.setRequestState(MessageState.ACK_EXPECTED);
        this.connContext.setAttribute(HttpAsyncServiceHandler.HTTP_EXCHANGE, httpExchange);

        HttpAsyncContinueTrigger trigger = this.protocolHandler.new ContinueTriggerImpl(httpExchange, this.conn);
        trigger.submitResponse(null);
    }
View Full Code Here

        trigger.submitResponse(null);
    }

    @Test
    public void testRequestContinue() throws Exception {
        HttpExchange httpExchange = this.protocolHandler.new HttpExchange();
        httpExchange.setRequestState(MessageState.ACK_EXPECTED);
        this.connContext.setAttribute(HttpAsyncServiceHandler.HTTP_EXCHANGE, httpExchange);

        HttpAsyncContinueTrigger trigger = this.protocolHandler.new ContinueTriggerImpl(httpExchange, this.conn);
        Assert.assertFalse(trigger.isTriggered());
        trigger.continueRequest();
        Assert.assertTrue(trigger.isTriggered());

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

        Mockito.verify(this.conn).requestOutput();

        try {
            trigger.submitResponse(this.responseProducer);
View Full Code Here

        }
    }

    @Test
    public void testRequestContent() throws Exception {
        HttpExchange httpExchange = this.protocolHandler.new HttpExchange();
        BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/",
                HttpVersion.HTTP_1_1);
        httpExchange.setRequestState(MessageState.BODY_STREAM);
        httpExchange.setRequest(request);
        httpExchange.setRequestConsumer(this.requestConsumer);
        this.connContext.setAttribute(HttpAsyncServiceHandler.HTTP_EXCHANGE, httpExchange);
        Mockito.when(this.decoder.isCompleted()).thenReturn(false);

        this.protocolHandler.inputReady(conn, this.decoder);

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

        Mockito.verify(this.requestConsumer).consumeContent(this.decoder, this.conn);
        Mockito.verify(this.conn, Mockito.never()).suspendInput();
    }
View Full Code Here

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

    @Test
    public void testRequestContentCompleted() throws Exception {
        HttpExchange httpExchange = this.protocolHandler.new HttpExchange();
        HttpContext exchangeContext = httpExchange.getContext();
        BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/",
                HttpVersion.HTTP_1_1);
        httpExchange.setRequestState(MessageState.BODY_STREAM);
        httpExchange.setRequest(request);
        httpExchange.setRequestConsumer(this.requestConsumer);
        httpExchange.setRequestHandler(this.requestHandler);
        this.connContext.setAttribute(HttpAsyncServiceHandler.HTTP_EXCHANGE, httpExchange);
        Mockito.when(this.decoder.isCompleted()).thenReturn(true);
        Mockito.when(this.requestConsumer.getException()).thenReturn(null);
        Object data = new Object();
        Mockito.when(this.requestConsumer.getResult()).thenReturn(data);
        Mockito.when(this.requestHandler.handle(
                Mockito.eq(data),
                Mockito.any(HttpAsyncResponseTrigger.class),
                Mockito.eq(exchangeContext))).thenReturn(this.cancellable);

        this.protocolHandler.inputReady(conn, this.decoder);

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

        Mockito.verify(this.requestConsumer).consumeContent(this.decoder, this.conn);
        Mockito.verify(this.conn).suspendInput();
        Mockito.verify(this.requestConsumer).requestCompleted(exchangeContext);
        Mockito.verify(this.requestHandler).handle(
                Mockito.eq(data),
                Mockito.any(HttpAsyncResponseTrigger.class),
                Mockito.eq(exchangeContext));
        Assert.assertSame(this.cancellable, httpExchange.getAsyncProcess());
    }
View Full Code Here

        Assert.assertSame(this.cancellable, httpExchange.getAsyncProcess());
    }

    @Test
    public void testRequestCompletedWithException() throws Exception {
        HttpExchange httpExchange = this.protocolHandler.new HttpExchange();
        HttpContext exchangeContext = httpExchange.getContext();
        BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/",
                HttpVersion.HTTP_1_1);
        httpExchange.setRequestState(MessageState.BODY_STREAM);
        httpExchange.setRequest(request);
        httpExchange.setRequestConsumer(this.requestConsumer);
        httpExchange.setRequestHandler(this.requestHandler);
        this.connContext.setAttribute(HttpAsyncServiceHandler.HTTP_EXCHANGE, httpExchange);
        Mockito.when(this.decoder.isCompleted()).thenReturn(true);
        Mockito.when(this.requestConsumer.getException()).thenReturn(new HttpException());
        Mockito.when(this.requestConsumer.getResult()).thenReturn(null);

        this.protocolHandler.inputReady(conn, this.decoder);

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

        Mockito.verify(this.requestConsumer).consumeContent(this.decoder, this.conn);
        Mockito.verify(this.conn).suspendInput();
        Mockito.verify(this.requestConsumer).requestCompleted(exchangeContext);
        Mockito.verify(this.conn).requestOutput();
View Full Code Here

                Mockito.any(HttpContext.class));
    }

    @Test
    public void testRequestHandlingHttpException() throws Exception {
        HttpExchange httpExchange = this.protocolHandler.new HttpExchange();
        HttpContext exchangeContext = httpExchange.getContext();
        BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/",
                HttpVersion.HTTP_1_1);
        httpExchange.setRequestState(MessageState.BODY_STREAM);
        httpExchange.setRequest(request);
        httpExchange.setRequestConsumer(this.requestConsumer);
        httpExchange.setRequestHandler(this.requestHandler);
        this.connContext.setAttribute(HttpAsyncServiceHandler.HTTP_EXCHANGE, httpExchange);
        Mockito.when(this.decoder.isCompleted()).thenReturn(true);
        Mockito.when(this.requestConsumer.getException()).thenReturn(null);
        Object data = new Object();
        Mockito.when(this.requestConsumer.getResult()).thenReturn(data);
        Mockito.doThrow(new UnsupportedHttpVersionException()).when(
                this.requestHandler).handle(
                        Mockito.eq(data),
                        Mockito.any(HttpAsyncResponseTrigger.class),
                        Mockito.eq(exchangeContext));

        this.protocolHandler.inputReady(conn, this.decoder);

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

        Mockito.verify(this.requestConsumer).consumeContent(this.decoder, this.conn);
        Mockito.verify(this.conn).suspendInput();
        Mockito.verify(this.requestConsumer).requestCompleted(exchangeContext);
        Mockito.verify(this.conn).requestOutput();
View Full Code Here

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

    @Test
    public void testRequestContentRuntimeException() throws Exception {
        HttpExchange httpExchange = this.protocolHandler.new HttpExchange();
        HttpContext exchangeContext = httpExchange.getContext();
        BasicHttpEntityEnclosingRequest request = new BasicHttpEntityEnclosingRequest("POST", "/",
                HttpVersion.HTTP_1_1);
        httpExchange.setRequestState(MessageState.BODY_STREAM);
        httpExchange.setRequest(request);
        httpExchange.setRequestConsumer(this.requestConsumer);
        this.connContext.setAttribute(HttpAsyncServiceHandler.HTTP_EXCHANGE, httpExchange);
        Mockito.when(this.decoder.isCompleted()).thenReturn(true);
        Mockito.doThrow(new RuntimeException()).when(
                this.requestConsumer).requestCompleted(exchangeContext);
        try {
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.