Search in sources :

Example 6 with StringResponse

use of io.airlift.http.client.StringResponseHandler.StringResponse in project airlift by airlift.

the class TestJaxrsTestingHttpProcessor method testUndefinedResource.

@Test
public void testUndefinedResource() {
    Request request = prepareGet().setUri(URI.create("http://fake.invalid/unknown")).build();
    StringResponse response = HTTP_CLIENT.execute(request, createStringResponseHandler());
    assertEquals(response.getStatusCode(), 404);
}
Also used : Request(io.airlift.http.client.Request) StringResponse(io.airlift.http.client.StringResponseHandler.StringResponse) Test(org.testng.annotations.Test)

Example 7 with StringResponse

use of io.airlift.http.client.StringResponseHandler.StringResponse in project airlift by airlift.

the class TestMBeanResource method testGetHtmlPage.

@Test
public void testGetHtmlPage() {
    StringResponse response = client.execute(prepareGet().setUri(uriFor("/v1/jmx")).build(), createStringResponseHandler());
    assertEquals(response.getStatusCode(), 200);
    assertContentType(response, HTML_UTF_8);
    assertContains(response.getBody(), "<html>");
}
Also used : StringResponse(io.airlift.http.client.StringResponseHandler.StringResponse) Test(org.testng.annotations.Test)

Example 8 with StringResponse

use of io.airlift.http.client.StringResponseHandler.StringResponse in project airlift by airlift.

the class TestServer method testOptions.

@Test
public void testOptions() {
    StringResponse response = client.execute(new Request.Builder().setMethod("OPTIONS").setUri(uriFor("/v1/person")).build(), createStringResponseHandler());
    assertThat(response.getStatusCode()).isEqualTo(HTTP_OK);
    assertThat(response.getHeader(CONTENT_TYPE)).isEqualTo("application/vnd.sun.wadl+xml");
    assertThat(response.getBody()).startsWith("<?xml ").contains("<application ");
}
Also used : StringResponse(io.airlift.http.client.StringResponseHandler.StringResponse) Test(org.testng.annotations.Test)

Example 9 with StringResponse

use of io.airlift.http.client.StringResponseHandler.StringResponse in project airlift by airlift.

the class AbstractHttpClientTest method testErrorResponseBody.

@Test
public void testErrorResponseBody() throws Exception {
    servlet.setResponseStatusCode(500);
    servlet.setResponseBody("body text");
    Request request = prepareGet().setUri(baseURI).build();
    StringResponse response = executeRequest(request, createStringResponseHandler());
    assertEquals(response.getStatusCode(), 500);
    assertEquals(response.getBody(), "body text");
}
Also used : StringResponse(io.airlift.http.client.StringResponseHandler.StringResponse) Test(org.testng.annotations.Test)

Example 10 with StringResponse

use of io.airlift.http.client.StringResponseHandler.StringResponse in project airlift by airlift.

the class AbstractHttpClientTest method testCompressionIsDisabled.

@Test
public void testCompressionIsDisabled() throws Exception {
    Request request = prepareGet().setUri(baseURI).build();
    String body = executeRequest(request, createStringResponseHandler()).getBody();
    assertEquals(body, "");
    assertFalse(servlet.getRequestHeaders().containsKey(HeaderName.of(ACCEPT_ENCODING)));
    String json = "{\"fuite\":\"apple\",\"hello\":\"world\"}";
    assertGreaterThanOrEqual(json.length(), GzipHandler.DEFAULT_MIN_GZIP_SIZE);
    servlet.setResponseBody(json);
    servlet.addResponseHeader(CONTENT_TYPE, "application/json");
    StringResponse response = executeRequest(request, createStringResponseHandler());
    assertEquals(response.getHeader(CONTENT_TYPE), "application/json");
    assertEquals(response.getBody(), json);
}
Also used : Throwables.getStackTraceAsString(com.google.common.base.Throwables.getStackTraceAsString) StringResponse(io.airlift.http.client.StringResponseHandler.StringResponse) Test(org.testng.annotations.Test)

Aggregations

StringResponse (io.airlift.http.client.StringResponseHandler.StringResponse)21 Test (org.testng.annotations.Test)13 JettyHttpClient (io.airlift.http.client.jetty.JettyHttpClient)7 Request (io.airlift.http.client.Request)6 HttpClient (io.airlift.http.client.HttpClient)4 HttpUriBuilder (io.airlift.http.client.HttpUriBuilder)3 URI (java.net.URI)3 MediaType (com.google.common.net.MediaType)2 ObjectMapperProvider (io.airlift.json.ObjectMapperProvider)2 File (java.io.File)2 Throwables.getStackTraceAsString (com.google.common.base.Throwables.getStackTraceAsString)1 ImmutableListMultimap (com.google.common.collect.ImmutableListMultimap)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 ListMultimap (com.google.common.collect.ListMultimap)1 CONTENT_TYPE (com.google.common.net.HttpHeaders.CONTENT_TYPE)1 Injector (com.google.inject.Injector)1 Bootstrap (io.airlift.bootstrap.Bootstrap)1 AbstractEventClient (io.airlift.event.client.AbstractEventClient)1 EventClient (io.airlift.event.client.EventClient)1 InMemoryEventModule (io.airlift.event.client.InMemoryEventModule)1