Search in sources :

Example 1 with HttpResponseStatus

use of org.asynchttpclient.HttpResponseStatus in project async-http-client by AsyncHttpClient.

the class AsyncHttpSingleTest method testAbort.

@Test(groups = "standalone")
public void testAbort() throws Exception {
    final TestSubscriber<Response> subscriber = new TestSubscriber<>();
    try (AsyncHttpClient client = asyncHttpClient()) {
        final Single<Response> underTest = AsyncHttpSingle.create(client.prepareGet("http://gatling.io"), () -> new AsyncCompletionHandlerBase() {

            @Override
            public State onStatusReceived(HttpResponseStatus status) {
                return State.ABORT;
            }
        });
        underTest.subscribe(subscriber);
        subscriber.awaitTerminalEvent();
    }
    subscriber.assertTerminalEvent();
    subscriber.assertNoErrors();
    subscriber.assertCompleted();
    subscriber.assertValue(null);
}
Also used : Response(org.asynchttpclient.Response) HttpResponseStatus(org.asynchttpclient.HttpResponseStatus) TestSubscriber(rx.observers.TestSubscriber) AsyncCompletionHandlerBase(org.asynchttpclient.AsyncCompletionHandlerBase) AsyncHttpClient(org.asynchttpclient.AsyncHttpClient) Test(org.testng.annotations.Test)

Example 2 with HttpResponseStatus

use of org.asynchttpclient.HttpResponseStatus in project async-http-client by AsyncHttpClient.

the class ResumableAsyncHandlerTest method testOnStatusReceivedOkStatus.

@Test
public void testOnStatusReceivedOkStatus() throws Exception {
    MapResumableProcessor processor = new MapResumableProcessor();
    ResumableAsyncHandler handler = new ResumableAsyncHandler(processor);
    HttpResponseStatus responseStatus200 = mock(HttpResponseStatus.class);
    when(responseStatus200.getStatusCode()).thenReturn(200);
    when(responseStatus200.getUri()).thenReturn(mock(Uri.class));
    State state = handler.onStatusReceived(responseStatus200);
    assertEquals(state, AsyncHandler.State.CONTINUE, "Status should be CONTINUE for a OK response");
}
Also used : HttpResponseStatus(org.asynchttpclient.HttpResponseStatus) State(org.asynchttpclient.AsyncHandler.State) Uri(org.asynchttpclient.uri.Uri) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 3 with HttpResponseStatus

use of org.asynchttpclient.HttpResponseStatus in project async-http-client by AsyncHttpClient.

the class ResumableAsyncHandlerTest method testOnStatusReceived500Status.

@Test
public void testOnStatusReceived500Status() throws Exception {
    MapResumableProcessor processor = new MapResumableProcessor();
    ResumableAsyncHandler handler = new ResumableAsyncHandler(processor);
    HttpResponseStatus mockResponseStatus = mock(HttpResponseStatus.class);
    when(mockResponseStatus.getStatusCode()).thenReturn(500);
    when(mockResponseStatus.getUri()).thenReturn(mock(Uri.class));
    State state = handler.onStatusReceived(mockResponseStatus);
    assertEquals(state, AsyncHandler.State.ABORT, "State should be ABORT for Internal Server Error status");
}
Also used : HttpResponseStatus(org.asynchttpclient.HttpResponseStatus) State(org.asynchttpclient.AsyncHandler.State) Uri(org.asynchttpclient.uri.Uri) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 4 with HttpResponseStatus

use of org.asynchttpclient.HttpResponseStatus in project async-http-client by AsyncHttpClient.

the class ResumableAsyncHandlerTest method testOnStatusReceivedOkStatusWithDecoratedAsyncHandler.

@Test
public void testOnStatusReceivedOkStatusWithDecoratedAsyncHandler() throws Exception {
    HttpResponseStatus mockResponseStatus = mock(HttpResponseStatus.class);
    when(mockResponseStatus.getStatusCode()).thenReturn(200);
    when(mockResponseStatus.getUri()).thenReturn(mock(Uri.class));
    @SuppressWarnings("unchecked") AsyncHandler<Response> decoratedAsyncHandler = mock(AsyncHandler.class);
    State mockState = mock(State.class);
    when(decoratedAsyncHandler.onStatusReceived(mockResponseStatus)).thenReturn(mockState);
    ResumableAsyncHandler handler = new ResumableAsyncHandler(decoratedAsyncHandler);
    State state = handler.onStatusReceived(mockResponseStatus);
    verify(decoratedAsyncHandler).onStatusReceived(mockResponseStatus);
    assertEquals(state, mockState, "State returned should be equal to the one returned from decoratedAsyncHandler");
}
Also used : Response(org.asynchttpclient.Response) HttpResponseStatus(org.asynchttpclient.HttpResponseStatus) State(org.asynchttpclient.AsyncHandler.State) Uri(org.asynchttpclient.uri.Uri) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Example 5 with HttpResponseStatus

use of org.asynchttpclient.HttpResponseStatus in project async-http-client by AsyncHttpClient.

the class ResumableAsyncHandlerTest method testOnStatusReceived206Status.

@Test
public void testOnStatusReceived206Status() throws Exception {
    MapResumableProcessor processor = new MapResumableProcessor();
    ResumableAsyncHandler handler = new ResumableAsyncHandler(processor);
    HttpResponseStatus responseStatus206 = mock(HttpResponseStatus.class);
    when(responseStatus206.getStatusCode()).thenReturn(206);
    when(responseStatus206.getUri()).thenReturn(mock(Uri.class));
    State state = handler.onStatusReceived(responseStatus206);
    assertEquals(state, AsyncHandler.State.CONTINUE, "Status should be CONTINUE for a 'Partial Content' response");
}
Also used : HttpResponseStatus(org.asynchttpclient.HttpResponseStatus) State(org.asynchttpclient.AsyncHandler.State) Uri(org.asynchttpclient.uri.Uri) Test(org.testng.annotations.Test) PrepareForTest(org.powermock.core.classloader.annotations.PrepareForTest)

Aggregations

HttpResponseStatus (org.asynchttpclient.HttpResponseStatus)10 Test (org.testng.annotations.Test)9 State (org.asynchttpclient.AsyncHandler.State)5 Response (org.asynchttpclient.Response)5 Uri (org.asynchttpclient.uri.Uri)5 PrepareForTest (org.powermock.core.classloader.annotations.PrepareForTest)5 AsyncHttpClient (org.asynchttpclient.AsyncHttpClient)4 HttpResponseBodyPart (org.asynchttpclient.HttpResponseBodyPart)4 HttpResponseHeaders (org.asynchttpclient.HttpResponseHeaders)4 AbstractBasicTest (org.asynchttpclient.AbstractBasicTest)3 File (java.io.File)2 FileOutputStream (java.io.FileOutputStream)2 HttpServletResponse (javax.servlet.http.HttpServletResponse)2 AsyncHandler (org.asynchttpclient.AsyncHandler)2 BasicHttpsTest (org.asynchttpclient.BasicHttpsTest)2 HttpRequest (io.netty.handler.codec.http.HttpRequest)1 HttpResponse (io.netty.handler.codec.http.HttpResponse)1 LastHttpContent (io.netty.handler.codec.http.LastHttpContent)1 WebSocketFrame (io.netty.handler.codec.http.websocketx.WebSocketFrame)1 IOException (java.io.IOException)1