Search in sources :

Example 6 with AsyncCompletionHandlerAdapter

use of org.asynchttpclient.test.TestUtils.AsyncCompletionHandlerAdapter in project async-http-client by AsyncHttpClient.

the class BasicHttpTest method headHasEmptyBody.

@Test
public void headHasEmptyBody() throws Throwable {
    withClient().run(client -> {
        withServer(server).run(server -> {
            server.enqueueOk();
            Response response = client.executeRequest(head(getTargetUrl()), new AsyncCompletionHandlerAdapter() {

                @Override
                public Response onCompleted(Response response) throws Exception {
                    assertEquals(response.getStatusCode(), 200);
                    return response;
                }
            }).get(TIMEOUT, SECONDS);
            assertTrue(response.getResponseBody().isEmpty());
        });
    });
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) AsyncCompletionHandlerAdapter(org.asynchttpclient.test.TestUtils.AsyncCompletionHandlerAdapter) Test(org.testng.annotations.Test) HttpTest(org.asynchttpclient.testserver.HttpTest)

Example 7 with AsyncCompletionHandlerAdapter

use of org.asynchttpclient.test.TestUtils.AsyncCompletionHandlerAdapter in project async-http-client by AsyncHttpClient.

the class BasicHttpTest method getVirtualHost.

@Test
public void getVirtualHost() throws Throwable {
    withClient().run(client -> {
        withServer(server).run(server -> {
            String virtualHost = "localhost:" + server.getHttpPort();
            server.enqueueEcho();
            Response response = client.prepareGet(getTargetUrl()).setVirtualHost(virtualHost).execute(new AsyncCompletionHandlerAdapter()).get(TIMEOUT, SECONDS);
            assertEquals(response.getStatusCode(), 200);
            if (response.getHeader("X-" + HOST) == null) {
                System.err.println(response);
            }
            assertEquals(response.getHeader("X-" + HOST), virtualHost);
        });
    });
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) AsyncCompletionHandlerAdapter(org.asynchttpclient.test.TestUtils.AsyncCompletionHandlerAdapter) Test(org.testng.annotations.Test) HttpTest(org.asynchttpclient.testserver.HttpTest)

Example 8 with AsyncCompletionHandlerAdapter

use of org.asynchttpclient.test.TestUtils.AsyncCompletionHandlerAdapter in project async-http-client by AsyncHttpClient.

the class BasicHttpTest method getRootUrl.

@Test
public void getRootUrl() throws Throwable {
    withClient().run(client -> {
        withServer(server).run(server -> {
            String url = server.getHttpUrl();
            server.enqueueOk();
            Response response = client.executeRequest(get(url), new AsyncCompletionHandlerAdapter()).get(TIMEOUT, SECONDS);
            assertEquals(response.getUri().toUrl(), url);
        });
    });
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) AsyncCompletionHandlerAdapter(org.asynchttpclient.test.TestUtils.AsyncCompletionHandlerAdapter) Test(org.testng.annotations.Test) HttpTest(org.asynchttpclient.testserver.HttpTest)

Example 9 with AsyncCompletionHandlerAdapter

use of org.asynchttpclient.test.TestUtils.AsyncCompletionHandlerAdapter in project async-http-client by AsyncHttpClient.

the class BasicHttpTest method getUrlWithPathWithoutQuery.

@Test
public void getUrlWithPathWithoutQuery() throws Throwable {
    withClient().run(client -> {
        withServer(server).run(server -> {
            server.enqueueOk();
            Response response = client.executeRequest(get(getTargetUrl()), new AsyncCompletionHandlerAdapter()).get(TIMEOUT, SECONDS);
            assertEquals(response.getUri().toUrl(), getTargetUrl());
        });
    });
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) AsyncCompletionHandlerAdapter(org.asynchttpclient.test.TestUtils.AsyncCompletionHandlerAdapter) Test(org.testng.annotations.Test) HttpTest(org.asynchttpclient.testserver.HttpTest)

Example 10 with AsyncCompletionHandlerAdapter

use of org.asynchttpclient.test.TestUtils.AsyncCompletionHandlerAdapter in project async-http-client by AsyncHttpClient.

the class BasicHttpTest method getUrlWithPathWithQueryParams.

@Test
public void getUrlWithPathWithQueryParams() throws Throwable {
    withClient().run(client -> {
        withServer(server).run(server -> {
            server.enqueueOk();
            Response response = client.executeRequest(get(getTargetUrl()).addQueryParam("q", "a b"), new AsyncCompletionHandlerAdapter()).get(TIMEOUT, SECONDS);
            assertEquals(response.getUri().toUrl(), getTargetUrl() + "?q=a%20b");
        });
    });
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) AsyncCompletionHandlerAdapter(org.asynchttpclient.test.TestUtils.AsyncCompletionHandlerAdapter) Test(org.testng.annotations.Test) HttpTest(org.asynchttpclient.testserver.HttpTest)

Aggregations

AsyncCompletionHandlerAdapter (org.asynchttpclient.test.TestUtils.AsyncCompletionHandlerAdapter)26 HttpTest (org.asynchttpclient.testserver.HttpTest)26 Test (org.testng.annotations.Test)26 HttpServletResponse (javax.servlet.http.HttpServletResponse)25 DefaultHttpHeaders (io.netty.handler.codec.http.DefaultHttpHeaders)11 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)11 CountDownLatch (java.util.concurrent.CountDownLatch)6 IOException (java.io.IOException)5 ServletException (javax.servlet.ServletException)5 ByteArrayInputStream (java.io.ByteArrayInputStream)4 ConnectException (java.net.ConnectException)4 CancellationException (java.util.concurrent.CancellationException)4 HttpServletRequest (javax.servlet.http.HttpServletRequest)4 UnknownHostException (java.net.UnknownHostException)3 ExecutionException (java.util.concurrent.ExecutionException)3 TimeoutException (java.util.concurrent.TimeoutException)3 SSLException (javax.net.ssl.SSLException)3 MaxRedirectException (org.asynchttpclient.handler.MaxRedirectException)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 EchoHandler (org.asynchttpclient.testserver.HttpServer.EchoHandler)2