Search in sources :

Example 16 with HttpClient

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

the class HttpClientAnnotationHandlerTest method verifyBeforeTest.

private static HttpClient verifyBeforeTest(Object target, Field field, AnnotationHandler handler) {
    handler.before(target, field);
    final HttpClient client = readPrivate(target, "client");
    assertThat(client).isNotNull();
    assertThat(client.isDestroyed()).isFalse();
    return client;
}
Also used : HttpClient(com.github.mjeanroy.junit.servers.client.HttpClient) TestHttpClient(com.github.mjeanroy.junit.servers.annotations.TestHttpClient)

Example 17 with HttpClient

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

the class ServerRuleTest method it_should_destroy_http_client_when_rule_stop.

@Test
void it_should_destroy_http_client_when_rule_stop() {
    final EmbeddedServer<?> server = new EmbeddedServerMockBuilder().build();
    final ServerRule rule = createRule(server);
    final HttpClient client = rule.getClient();
    assertThat(client).isNotNull();
    assertThat(client.isDestroyed()).isFalse();
    rule.after();
    assertThat(client.isDestroyed()).isTrue();
}
Also used : HttpClient(com.github.mjeanroy.junit.servers.client.HttpClient) EmbeddedServerMockBuilder(com.github.mjeanroy.junit.servers.utils.builders.EmbeddedServerMockBuilder) Test(org.junit.jupiter.api.Test)

Example 18 with HttpClient

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

the class ServerRuleTest method it_should_get_http_client.

@Test
void it_should_get_http_client() {
    final EmbeddedServer<?> server = new EmbeddedServerMockBuilder().build();
    final ServerRule rule = createRule(server);
    final HttpClient client = rule.getClient();
    assertThat(client).isNotNull();
    assertThat(client).isSameAs(rule.getClient());
    assertThat(client.isDestroyed()).isFalse();
}
Also used : HttpClient(com.github.mjeanroy.junit.servers.client.HttpClient) EmbeddedServerMockBuilder(com.github.mjeanroy.junit.servers.utils.builders.EmbeddedServerMockBuilder) Test(org.junit.jupiter.api.Test)

Example 19 with HttpClient

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

the class HttpClientParameterResolverFunctionTest method it_should_resolve_http_client_with_given_configuration_on_meta_annotation.

@Test
public void it_should_resolve_http_client_with_given_configuration_on_meta_annotation() throws Exception {
    final ParameterContext parameterContext = extractParameterContext("method_with_meta_annotation");
    final Object result = resolver.resolve(parameterContext, adapter);
    assertThat(result).isInstanceOf(HttpClient.class);
    final HttpClient httpClient = (HttpClient) result;
    assertThat(httpClient.getConfiguration()).isNotNull();
    assertThat(httpClient.getConfiguration().isFollowRedirect()).isFalse();
}
Also used : HttpClient(com.github.mjeanroy.junit.servers.client.HttpClient) TestHttpClient(com.github.mjeanroy.junit.servers.annotations.TestHttpClient) NingAsyncHttpClient(com.github.mjeanroy.junit.servers.client.impl.ning.NingAsyncHttpClient) ParameterContext(org.junit.jupiter.api.extension.ParameterContext) Test(org.junit.jupiter.api.Test)

Example 20 with HttpClient

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

the class HttpClientParameterResolverFunctionTest method it_should_resolve_http_client_with_given_configuration.

@Test
public void it_should_resolve_http_client_with_given_configuration() throws Exception {
    final ParameterContext parameterContext = extractParameterContext("method_with_annotation_and_configuration_factory");
    final Object result = resolver.resolve(parameterContext, adapter);
    assertThat(result).isInstanceOf(HttpClient.class);
    final HttpClient httpClient = (HttpClient) result;
    assertThat(httpClient.getConfiguration()).isNotNull();
    assertThat(httpClient.getConfiguration().isFollowRedirect()).isFalse();
}
Also used : HttpClient(com.github.mjeanroy.junit.servers.client.HttpClient) TestHttpClient(com.github.mjeanroy.junit.servers.annotations.TestHttpClient) NingAsyncHttpClient(com.github.mjeanroy.junit.servers.client.impl.ning.NingAsyncHttpClient) ParameterContext(org.junit.jupiter.api.extension.ParameterContext) 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