Search in sources :

Example 6 with HttpClientStrategy

use of com.github.mjeanroy.junit.servers.client.HttpClientStrategy 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);
}
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) 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 7 with HttpClientStrategy

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

the class EmbeddedServerRunnerTest method it_should_get_client_of_given_strategy_and_returns_previous_one.

@Test
void it_should_get_client_of_given_strategy_and_returns_previous_one() {
    final EmbeddedServer<?> server = new EmbeddedServerMockBuilder().build();
    final EmbeddedServerRunner adapter = new EmbeddedServerRunner(server);
    final HttpClientStrategy strategy = HttpClientStrategy.OK_HTTP3;
    final HttpClient client1 = adapter.getClient(strategy);
    final HttpClient client2 = adapter.getClient(strategy);
    assertThat(client1).isNotNull();
    assertThat(client2).isNotNull();
    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) Test(org.junit.jupiter.api.Test)

Example 8 with HttpClientStrategy

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

the class EmbeddedServerRunnerTest method it_should_get_client_of_given_strategy_and_destroy_it_when_server_stop.

@Test
void it_should_get_client_of_given_strategy_and_destroy_it_when_server_stop() {
    final EmbeddedServer<?> server = new EmbeddedServerMockBuilder().build();
    final EmbeddedServerRunner adapter = new EmbeddedServerRunner(server);
    final HttpClientStrategy strategy = HttpClientStrategy.OK_HTTP3;
    final HttpClient client = adapter.getClient(strategy);
    assertThat(client).isNotNull();
    assertThat(client.isDestroyed()).isFalse();
    adapter.stop();
    assertThat(client).isNotNull();
    assertThat(client.isDestroyed()).isTrue();
}
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) Test(org.junit.jupiter.api.Test)

Aggregations

HttpClientStrategy (com.github.mjeanroy.junit.servers.client.HttpClientStrategy)8 HttpClient (com.github.mjeanroy.junit.servers.client.HttpClient)6 OkHttpClient (com.github.mjeanroy.junit.servers.client.impl.okhttp3.OkHttpClient)6 EmbeddedServerMockBuilder (com.github.mjeanroy.junit.servers.utils.builders.EmbeddedServerMockBuilder)6 Test (org.junit.jupiter.api.Test)6 HttpClientConfiguration (com.github.mjeanroy.junit.servers.client.HttpClientConfiguration)4 TestHttpClient (com.github.mjeanroy.junit.servers.annotations.TestHttpClient)2 FakeEmbeddedServerConfigurationBuilder (com.github.mjeanroy.junit.servers.utils.impl.FakeEmbeddedServerConfigurationBuilder)2