Search in sources :

Example 1 with HttpClient

use of com.github.mjeanroy.junit.servers.client.HttpClient 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 2 with HttpClient

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

the class EmbeddedServerRunnerTest method it_should_get_client_of_given_strategy.

@Test
void it_should_get_client_of_given_strategy() {
    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();
}
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 3 with HttpClient

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_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 HttpClient

use of com.github.mjeanroy.junit.servers.client.HttpClient 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 HttpClient

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

the class HttpClientAnnotationHandlerTest method it_should_set_client_instance_on_super_class.

@Test
void it_should_set_client_instance_on_super_class() {
    final EmbeddedServer<?> server = new EmbeddedServerMockBuilder().build();
    final TestInheritedClassWithAnnotatedField target = new TestInheritedClassWithAnnotatedField();
    final Field field = extractClientField(TestInheritedClassWithAnnotatedField.class);
    final AnnotationHandler handler = newHttpClientAnnotationHandler(server);
    final HttpClient client = verifyBeforeTest(target, field, handler);
    verifyAfterTest(target, field, handler, client);
}
Also used : Field(java.lang.reflect.Field) HttpClient(com.github.mjeanroy.junit.servers.client.HttpClient) TestHttpClient(com.github.mjeanroy.junit.servers.annotations.TestHttpClient) HttpClientAnnotationHandler.newHttpClientAnnotationHandler(com.github.mjeanroy.junit.servers.engine.HttpClientAnnotationHandler.newHttpClientAnnotationHandler) EmbeddedServerMockBuilder(com.github.mjeanroy.junit.servers.utils.builders.EmbeddedServerMockBuilder) Test(org.junit.jupiter.api.Test)

Aggregations

HttpClient (com.github.mjeanroy.junit.servers.client.HttpClient)41 Test (org.junit.jupiter.api.Test)38 EmbeddedServerMockBuilder (com.github.mjeanroy.junit.servers.utils.builders.EmbeddedServerMockBuilder)23 OkHttpClient (com.github.mjeanroy.junit.servers.client.impl.okhttp3.OkHttpClient)12 HttpRequest (com.github.mjeanroy.junit.servers.client.HttpRequest)9 TestHttpClient (com.github.mjeanroy.junit.servers.annotations.TestHttpClient)8 HttpClientConfiguration (com.github.mjeanroy.junit.servers.client.HttpClientConfiguration)7 HttpClientStrategy (com.github.mjeanroy.junit.servers.client.HttpClientStrategy)6 HttpMethod (com.github.mjeanroy.junit.servers.client.HttpMethod)5 BaseHttpClientTest (com.github.mjeanroy.junit.servers.client.impl.BaseHttpClientTest)4 FakeEmbeddedServerConfigurationBuilder (com.github.mjeanroy.junit.servers.utils.impl.FakeEmbeddedServerConfigurationBuilder)4 NingAsyncHttpClient (com.github.mjeanroy.junit.servers.client.impl.ning.NingAsyncHttpClient)3 HttpClientAnnotationHandler.newHttpClientAnnotationHandler (com.github.mjeanroy.junit.servers.engine.HttpClientAnnotationHandler.newHttpClientAnnotationHandler)3 Field (java.lang.reflect.Field)3 WireMockTest (com.github.mjeanroy.junit.servers.utils.jupiter.WireMockTest)2 ParameterContext (org.junit.jupiter.api.extension.ParameterContext)2 ApacheHttpClient.defaultApacheHttpClient (com.github.mjeanroy.junit.servers.client.impl.apache.ApacheHttpClient.defaultApacheHttpClient)1 ApacheHttpClient.newApacheHttpClient (com.github.mjeanroy.junit.servers.client.impl.apache.ApacheHttpClient.newApacheHttpClient)1 AsyncHttpClient.defaultAsyncHttpClient (com.github.mjeanroy.junit.servers.client.impl.async.AsyncHttpClient.defaultAsyncHttpClient)1 AsyncHttpClient.newAsyncHttpClient (com.github.mjeanroy.junit.servers.client.impl.async.AsyncHttpClient.newAsyncHttpClient)1