use of com.github.mjeanroy.junit.servers.client.HttpClient in project junit-servers by mjeanroy.
the class EmbeddedServerRunner method openClient.
private HttpClient openClient(HttpClientStrategy strategy, HttpClientConfiguration configuration) {
log.debug("Opening HTTP client using strategy: {}", strategy);
notNull(strategy, "strategy");
notNull(configuration, "configuration");
synchronized (clients) {
HttpClientId id = new HttpClientId(strategy, configuration);
if (!clients.containsKey(id) || clients.get(id).isDestroyed()) {
HttpClient client = strategy.build(configuration, server);
clients.put(id, client);
}
return clients.get(id);
}
}
use of com.github.mjeanroy.junit.servers.client.HttpClient in project junit-servers by mjeanroy.
the class HttpClientAnnotationHandler method after.
@Override
public void after(Object target, Field field) {
log.debug("Clearing HTTP client to {} # {}", target, field);
HttpClient httpClient = getter(target, field);
httpClient.destroy();
setter(target, field, null);
}
use of com.github.mjeanroy.junit.servers.client.HttpClient 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.HttpClient in project junit-servers by mjeanroy.
the class EmbeddedServerRunnerTest method it_should_get_client_and_returns_previous_one.
@Test
void it_should_get_client_and_returns_previous_one() {
final EmbeddedServer<?> server = new EmbeddedServerMockBuilder().build();
final EmbeddedServerRunner adapter = new EmbeddedServerRunner(server);
final HttpClient client1 = adapter.getClient();
final HttpClient client2 = adapter.getClient();
assertThat(client1).isNotNull();
assertThat(client2).isNotNull();
assertThat(client1).isSameAs(client2);
}
use of com.github.mjeanroy.junit.servers.client.HttpClient in project junit-servers by mjeanroy.
the class EmbeddedServerRunnerTest method it_should_stop_server_and_close_clients.
@Test
void it_should_stop_server_and_close_clients() {
final EmbeddedServer<?> server = new EmbeddedServerMockBuilder().build();
final EmbeddedServerRunner adapter = new EmbeddedServerRunner(server);
final HttpClient client = adapter.getClient();
assertThat(client).isNotNull();
assertThat(client.isDestroyed()).isFalse();
adapter.stop();
assertThat(client).isNotNull();
assertThat(client.isDestroyed()).isTrue();
}
Aggregations