use of com.github.mjeanroy.junit.servers.client.HttpClientConfiguration in project junit-servers by mjeanroy.
the class HttpClientParameterResolverFunction method resolve.
@Override
public Object resolve(ParameterContext parameterContext, EmbeddedServerRunner serverAdapter) {
log.debug("Resolving HTTP Client for parameter: {}", parameterContext);
final Optional<TestHttpClient> maybeAnnotation = parameterContext.findAnnotation(TestHttpClient.class);
final HttpClientConfiguration configuration;
final HttpClientStrategy strategy;
if (maybeAnnotation.isPresent()) {
TestHttpClient annotation = maybeAnnotation.get();
strategy = getStrategy(annotation);
configuration = getConfiguration(annotation);
} else {
strategy = defaultStrategy();
configuration = defaultConfiguration();
}
return serverAdapter.getClient(strategy, configuration);
}
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_new_one_with_different_configuration.
@Test
public void it_should_get_client_with_given_strategy_custom_configuration_and_return_new_one_with_different_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().disableFollowRedirect().build();
final HttpClientConfiguration configuration2 = new HttpClientConfiguration.Builder().build();
final HttpClient client1 = adapter.getClient(strategy, configuration1);
final HttpClient client2 = adapter.getClient(strategy, configuration2);
assertThat(client1).isNotSameAs(client2);
assertThat(client1).isInstanceOf(OkHttpClient.class);
assertThat(client2).isInstanceOf(OkHttpClient.class);
assertThat(client1.getConfiguration()).isSameAs(configuration1);
assertThat(client2.getConfiguration()).isSameAs(configuration2);
}
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.
@Test
public void it_should_get_client_with_given_strategy_custom_configuration() {
final EmbeddedServer<?> server = new EmbeddedServerMockBuilder().build();
final EmbeddedServerRunner adapter = new EmbeddedServerRunner(server);
final HttpClientStrategy strategy = HttpClientStrategy.OK_HTTP3;
final HttpClientConfiguration configuration = new HttpClientConfiguration.Builder().disableFollowRedirect().build();
final HttpClient client = adapter.getClient(strategy, configuration);
assertThat(client).isInstanceOf(OkHttpClient.class);
assertThat(client.getConfiguration()).isSameAs(configuration);
}
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_and_return_previous_one_with_same_configuration.
@Test
public void it_should_get_client_with_custom_configuration_and_return_previous_one_with_same_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().build();
final HttpClient client1 = adapter.getClient(configuration1);
final HttpClient client2 = adapter.getClient(configuration2);
assertThat(client1).isSameAs(client2);
}
use of com.github.mjeanroy.junit.servers.client.HttpClientConfiguration in project junit-servers by mjeanroy.
the class BaseHttpClientTest method testRequest_with_default_cookie_object.
@Test
void testRequest_with_default_cookie_object() {
final String endpoint = ENDPOINT;
final String name = "foo";
final String value = "bar";
final HttpClientConfiguration configuration = new HttpClientConfiguration.Builder().addDefaultCookie(Cookies.cookie(name, value)).build();
stubDefaultRequest(endpoint);
createCustomClient(configuration).prepareGet(endpoint).executeJson();
assertRequestWithCookie(endpoint, HttpMethod.GET, name, value);
}
Aggregations