Search in sources :

Example 1 with HttpClientConfiguration

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

the class BaseHttpClientTest method testRequest_with_default_cookie.

@Test
void testRequest_with_default_cookie() {
    final String endpoint = ENDPOINT;
    final String name = "foo";
    final String value = "bar";
    final HttpClientConfiguration configuration = new HttpClientConfiguration.Builder().addDefaultCookie(name, value).build();
    stubDefaultRequest(endpoint);
    createCustomClient(configuration).prepareGet(endpoint).executeJson();
    assertRequestWithCookie(endpoint, HttpMethod.GET, name, value);
}
Also used : EmbeddedServerMockBuilder(com.github.mjeanroy.junit.servers.utils.builders.EmbeddedServerMockBuilder) HttpRequestBodies.multipartBuilder(com.github.mjeanroy.junit.servers.client.HttpRequestBodies.multipartBuilder) HttpClientConfiguration(com.github.mjeanroy.junit.servers.client.HttpClientConfiguration) WireMockTest(com.github.mjeanroy.junit.servers.utils.jupiter.WireMockTest) Test(org.junit.jupiter.api.Test)

Example 2 with HttpClientConfiguration

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

the class EmbeddedServerRunnerTest method it_should_get_client_with_custom_configuration.

@Test
public void it_should_get_client_with_custom_configuration() {
    final EmbeddedServer<?> server = new EmbeddedServerMockBuilder().build();
    final EmbeddedServerRunner adapter = new EmbeddedServerRunner(server);
    final HttpClientConfiguration configuration = new HttpClientConfiguration.Builder().disableFollowRedirect().build();
    final HttpClient client = adapter.getClient(configuration);
    assertThat(client).isNotNull();
    assertThat(client.getConfiguration()).isSameAs(configuration);
}
Also used : EmbeddedServerMockBuilder(com.github.mjeanroy.junit.servers.utils.builders.EmbeddedServerMockBuilder) FakeEmbeddedServerConfigurationBuilder(com.github.mjeanroy.junit.servers.utils.impl.FakeEmbeddedServerConfigurationBuilder) OkHttpClient(com.github.mjeanroy.junit.servers.client.impl.okhttp3.OkHttpClient) HttpClient(com.github.mjeanroy.junit.servers.client.HttpClient) EmbeddedServerMockBuilder(com.github.mjeanroy.junit.servers.utils.builders.EmbeddedServerMockBuilder) HttpClientConfiguration(com.github.mjeanroy.junit.servers.client.HttpClientConfiguration) Test(org.junit.jupiter.api.Test)

Example 3 with HttpClientConfiguration

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

the class EmbeddedServerRunnerTest method it_should_get_client_with_given_strategy_custom_configuration_and_return_previous_one_with_same_configuration.

@Test
public void it_should_get_client_with_given_strategy_custom_configuration_and_return_previous_one_with_same_configuration() {
    final EmbeddedServer<?> server = new EmbeddedServerMockBuilder().build();
    final EmbeddedServerRunner adapter = new EmbeddedServerRunner(server);
    final HttpClientStrategy strategy = HttpClientStrategy.OK_HTTP3;
    final HttpClientConfiguration configuration1 = new HttpClientConfiguration.Builder().build();
    final HttpClientConfiguration configuration2 = new HttpClientConfiguration.Builder().build();
    final HttpClient client1 = adapter.getClient(strategy, configuration1);
    final HttpClient client2 = adapter.getClient(strategy, configuration2);
    assertThat(client1).isSameAs(client2);
}
Also used : OkHttpClient(com.github.mjeanroy.junit.servers.client.impl.okhttp3.OkHttpClient) HttpClient(com.github.mjeanroy.junit.servers.client.HttpClient) HttpClientStrategy(com.github.mjeanroy.junit.servers.client.HttpClientStrategy) EmbeddedServerMockBuilder(com.github.mjeanroy.junit.servers.utils.builders.EmbeddedServerMockBuilder) HttpClientConfiguration(com.github.mjeanroy.junit.servers.client.HttpClientConfiguration) Test(org.junit.jupiter.api.Test)

Example 4 with HttpClientConfiguration

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

the class EmbeddedServerRunnerTest method it_should_get_client_and_do_not_return_previous_one_with_different_configuration.

@Test
public void it_should_get_client_and_do_not_return_previous_one_with_different_configuration() {
    final EmbeddedServer<?> server = new EmbeddedServerMockBuilder().build();
    final EmbeddedServerRunner adapter = new EmbeddedServerRunner(server);
    final HttpClientConfiguration configuration1 = new HttpClientConfiguration.Builder().build();
    final HttpClientConfiguration configuration2 = new HttpClientConfiguration.Builder().disableFollowRedirect().build();
    final HttpClient client1 = adapter.getClient(configuration1);
    final HttpClient client2 = adapter.getClient(configuration2);
    assertThat(client1).isNotSameAs(client2);
    assertThat(client1.getConfiguration()).isSameAs(configuration1);
    assertThat(client2.getConfiguration()).isSameAs(configuration2);
}
Also used : EmbeddedServerMockBuilder(com.github.mjeanroy.junit.servers.utils.builders.EmbeddedServerMockBuilder) FakeEmbeddedServerConfigurationBuilder(com.github.mjeanroy.junit.servers.utils.impl.FakeEmbeddedServerConfigurationBuilder) OkHttpClient(com.github.mjeanroy.junit.servers.client.impl.okhttp3.OkHttpClient) HttpClient(com.github.mjeanroy.junit.servers.client.HttpClient) EmbeddedServerMockBuilder(com.github.mjeanroy.junit.servers.utils.builders.EmbeddedServerMockBuilder) HttpClientConfiguration(com.github.mjeanroy.junit.servers.client.HttpClientConfiguration) Test(org.junit.jupiter.api.Test)

Example 5 with HttpClientConfiguration

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

the class NingAsyncHttpClient method defaultAsyncHttpClient.

/**
 * Create new http client using internal
 * http client from async-http-client library.
 * An instance of {com.ning.http.client.NingAsyncHttpClient} will be automatically
 * created.
 *
 * @param server Embedded server.
 * @return Http client.
 * @throws NullPointerException If {@code server} is {@code null}.
 */
public static NingAsyncHttpClient defaultAsyncHttpClient(EmbeddedServer<?> server) {
    HttpClientConfiguration configuration = HttpClientConfiguration.defaultConfiguration();
    AsyncHttpClientConfig config = new AsyncHttpClientConfig.Builder().setFollowRedirect(configuration.isFollowRedirect()).build();
    return new NingAsyncHttpClient(configuration, server, new com.ning.http.client.AsyncHttpClient(config));
}
Also used : ToStringBuilder(com.github.mjeanroy.junit.servers.commons.lang.ToStringBuilder) AsyncHttpClient(com.ning.http.client.AsyncHttpClient) AsyncHttpClientConfig(com.ning.http.client.AsyncHttpClientConfig) HttpClientConfiguration(com.github.mjeanroy.junit.servers.client.HttpClientConfiguration)

Aggregations

HttpClientConfiguration (com.github.mjeanroy.junit.servers.client.HttpClientConfiguration)13 EmbeddedServerMockBuilder (com.github.mjeanroy.junit.servers.utils.builders.EmbeddedServerMockBuilder)11 Test (org.junit.jupiter.api.Test)11 HttpClient (com.github.mjeanroy.junit.servers.client.HttpClient)7 OkHttpClient (com.github.mjeanroy.junit.servers.client.impl.okhttp3.OkHttpClient)6 HttpClientStrategy (com.github.mjeanroy.junit.servers.client.HttpClientStrategy)4 HttpRequestBodies.multipartBuilder (com.github.mjeanroy.junit.servers.client.HttpRequestBodies.multipartBuilder)4 FakeEmbeddedServerConfigurationBuilder (com.github.mjeanroy.junit.servers.utils.impl.FakeEmbeddedServerConfigurationBuilder)4 WireMockTest (com.github.mjeanroy.junit.servers.utils.jupiter.WireMockTest)4 TestHttpClient (com.github.mjeanroy.junit.servers.annotations.TestHttpClient)1 HttpHeader (com.github.mjeanroy.junit.servers.client.HttpHeader)1 ToStringBuilder (com.github.mjeanroy.junit.servers.commons.lang.ToStringBuilder)1 AsyncHttpClient (com.ning.http.client.AsyncHttpClient)1 AsyncHttpClientConfig (com.ning.http.client.AsyncHttpClientConfig)1