Search in sources :

Example 21 with HttpResponse

use of com.github.mjeanroy.junit.servers.client.HttpResponse in project junit-servers by mjeanroy.

the class OkHttpRequest method doExecute.

@Override
protected HttpResponse doExecute() throws Exception {
    final HttpUrl endpoint = getEndpoint();
    final okhttp3.HttpUrl.Builder httpUrlBuilder = new okhttp3.HttpUrl.Builder().scheme(endpoint.getScheme()).host(endpoint.getHost()).port(endpoint.getPort()).addPathSegments(endpoint.getPath().substring(1));
    // Append all query parameters.
    for (HttpParameter queryParam : queryParams.values()) {
        httpUrlBuilder.addEncodedQueryParameter(queryParam.getEncodedName(), queryParam.getEncodedValue());
    }
    final Request.Builder builder = new Request.Builder().url(httpUrlBuilder.build());
    handleBody(builder);
    handleCookies(builder);
    handleHeaders(builder);
    final Call call = client.newCall(builder.build());
    final long start = System.nanoTime();
    try (Response response = call.execute()) {
        final long duration = System.nanoTime() - start;
        return OkHttpResponseFactory.of(response, duration);
    }
}
Also used : Response(okhttp3.Response) HttpResponse(com.github.mjeanroy.junit.servers.client.HttpResponse) Call(okhttp3.Call) Request(okhttp3.Request) HttpRequest(com.github.mjeanroy.junit.servers.client.HttpRequest) AbstractHttpRequest(com.github.mjeanroy.junit.servers.client.impl.AbstractHttpRequest) HttpParameter(com.github.mjeanroy.junit.servers.client.HttpParameter) HttpUrl(com.github.mjeanroy.junit.servers.client.HttpUrl)

Example 22 with HttpResponse

use of com.github.mjeanroy.junit.servers.client.HttpResponse in project springmvc-mustache by mjeanroy.

the class IndexControllerTest method it_should_render_handlebars_template_using_model_and_mustache_view.

@Test
void it_should_render_handlebars_template_using_model_and_mustache_view(HttpClient client) {
    HttpResponse response = client.prepareGet("/jane").execute();
    assertThat(response.status()).isEqualTo(200);
    assertThat(response.body()).contains("Hello, my name is Jane Doe");
}
Also used : HttpResponse(com.github.mjeanroy.junit.servers.client.HttpResponse) Test(org.junit.jupiter.api.Test) JettyTest(com.github.mjeanroy.junit.servers.jetty.jupiter.JettyTest)

Example 23 with HttpResponse

use of com.github.mjeanroy.junit.servers.client.HttpResponse in project springmvc-mustache by mjeanroy.

the class IndexControllerTest method it_should_render_mustache_template.

@Test
void it_should_render_mustache_template(HttpClient client) {
    HttpResponse response = client.prepareGet("/").execute();
    assertThat(response.status()).isEqualTo(200);
    assertThat(response.body()).contains("Hello, my name is John Doe");
}
Also used : HttpResponse(com.github.mjeanroy.junit.servers.client.HttpResponse) Test(org.junit.jupiter.api.Test) JettyTest(com.github.mjeanroy.junit.servers.jetty.jupiter.JettyTest)

Example 24 with HttpResponse

use of com.github.mjeanroy.junit.servers.client.HttpResponse in project springmvc-mustache by mjeanroy.

the class IndexControllerTest method it_should_render_handlebars_template.

@Test
void it_should_render_handlebars_template(HttpClient client) {
    HttpResponse response = client.prepareGet("/").execute();
    assertThat(response.status()).isEqualTo(200);
    assertThat(response.body()).contains("Hello, my name is John Doe");
}
Also used : HttpResponse(com.github.mjeanroy.junit.servers.client.HttpResponse) Test(org.junit.jupiter.api.Test) JettyTest(com.github.mjeanroy.junit.servers.jetty.jupiter.JettyTest)

Example 25 with HttpResponse

use of com.github.mjeanroy.junit.servers.client.HttpResponse in project springmvc-mustache by mjeanroy.

the class IndexControllerTest method it_should_render_handlebars_template.

@Test
void it_should_render_handlebars_template(HttpClient client) {
    HttpResponse response = client.prepareGet("/").execute();
    assertThat(response.status()).isEqualTo(200);
    assertThat(response.body()).contains("Hello, my name is John Doe");
}
Also used : HttpResponse(com.github.mjeanroy.junit.servers.client.HttpResponse) Test(org.junit.jupiter.api.Test) JettyTest(com.github.mjeanroy.junit.servers.jetty.jupiter.JettyTest)

Aggregations

HttpResponse (com.github.mjeanroy.junit.servers.client.HttpResponse)50 Test (org.junit.jupiter.api.Test)41 Pair (com.github.mjeanroy.junit.servers.utils.commons.Pair)25 WireMockTest (com.github.mjeanroy.junit.servers.utils.jupiter.WireMockTest)23 JettyTest (com.github.mjeanroy.junit.servers.jetty.jupiter.JettyTest)14 HttpRequest (com.github.mjeanroy.junit.servers.client.HttpRequest)7 HttpRequestBody (com.github.mjeanroy.junit.servers.client.HttpRequestBody)4 HttpUrl (com.github.mjeanroy.junit.servers.client.HttpUrl)3 AbstractHttpRequest (com.github.mjeanroy.junit.servers.client.impl.AbstractHttpRequest)3 HttpHeader (com.github.mjeanroy.junit.servers.client.HttpHeader)2 Response (com.ning.http.client.Response)2 Response (okhttp3.Response)2 Response (org.asynchttpclient.Response)2 Cookie (com.github.mjeanroy.junit.servers.client.Cookie)1 HttpParameter (com.github.mjeanroy.junit.servers.client.HttpParameter)1 WireMockTestUtils.assertRequestWithCookie (com.github.mjeanroy.junit.servers.client.it.WireMockTestUtils.assertRequestWithCookie)1 TomcatTest (com.github.mjeanroy.junit.servers.tomcat.jupiter.TomcatTest)1 AsyncHttpResponseBuilder (com.github.mjeanroy.junit.servers.utils.builders.AsyncHttpResponseBuilder)1 NingHttpResponseBuilder (com.github.mjeanroy.junit.servers.utils.builders.NingHttpResponseBuilder)1 OkHttpResponseBuilder (com.github.mjeanroy.junit.servers.utils.builders.OkHttpResponseBuilder)1