Search in sources :

Example 6 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_meta_annotated_field.

@Test
void it_should_set_client_instance_on_meta_annotated_field() {
    final EmbeddedServer<?> server = new EmbeddedServerMockBuilder().build();
    final TestClassWithMetaAnnotationField target = new TestClassWithMetaAnnotationField();
    final Field field = extractClientField(TestClassWithMetaAnnotationField.class);
    final AnnotationHandler handler = newHttpClientAnnotationHandler(server);
    final HttpClient client = verifyBeforeTest(target, field, handler);
    verifyAfterTest(target, field, handler, client);
    verifyAsyncHttpClient(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)

Example 7 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.

@Test
void it_should_set_client_instance() {
    final EmbeddedServer<?> server = new EmbeddedServerMockBuilder().build();
    final TestClassWithAnnotatedField target = new TestClassWithAnnotatedField();
    final Field field = extractClientField(TestClassWithAnnotatedField.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)

Example 8 with HttpClient

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

the class AsyncHttpClientTest method it_should_implement_to_string.

@Test
void it_should_implement_to_string() {
    EmbeddedServer<?> server = new EmbeddedServerMockBuilder().build();
    HttpClient client = createDefaultClient(server);
    org.asynchttpclient.AsyncHttpClient internalClient = readPrivate(client, "client");
    assertThat(client).hasToString("AsyncHttpClient{" + "configuration: HttpClientConfiguration{" + "followRedirect: true, " + "defaultHeaders: {}, " + "defaultCookies: []" + "}, " + "server: MockEmbeddedServer, " + "client: " + internalClient.toString() + "}");
}
Also used : AsyncHttpClient.newAsyncHttpClient(com.github.mjeanroy.junit.servers.client.impl.async.AsyncHttpClient.newAsyncHttpClient) AsyncHttpClient.defaultAsyncHttpClient(com.github.mjeanroy.junit.servers.client.impl.async.AsyncHttpClient.defaultAsyncHttpClient) HttpClient(com.github.mjeanroy.junit.servers.client.HttpClient) EmbeddedServerMockBuilder(com.github.mjeanroy.junit.servers.utils.builders.EmbeddedServerMockBuilder) Test(org.junit.jupiter.api.Test) BaseHttpClientTest(com.github.mjeanroy.junit.servers.client.impl.BaseHttpClientTest)

Example 9 with HttpClient

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

the class OkHttpClientTest method it_should_implement_to_string.

@Test
void it_should_implement_to_string() {
    final EmbeddedServer<?> server = new EmbeddedServerMockBuilder().build();
    final HttpClient client = createDefaultClient(server);
    final okhttp3.OkHttpClient internalClient = readPrivate(client, "client");
    assertThat(client).hasToString("OkHttpClient{" + "configuration: HttpClientConfiguration{" + "followRedirect: true, " + "defaultHeaders: {}, " + "defaultCookies: []" + "}, " + "server: MockEmbeddedServer, " + "client: " + internalClient.toString() + ", " + "destroyed: false" + "}");
}
Also used : OkHttpClient.defaultOkHttpClient(com.github.mjeanroy.junit.servers.client.impl.okhttp3.OkHttpClient.defaultOkHttpClient) OkHttpClient.newOkHttpClient(com.github.mjeanroy.junit.servers.client.impl.okhttp3.OkHttpClient.newOkHttpClient) HttpClient(com.github.mjeanroy.junit.servers.client.HttpClient) EmbeddedServerMockBuilder(com.github.mjeanroy.junit.servers.utils.builders.EmbeddedServerMockBuilder) Test(org.junit.jupiter.api.Test) BaseHttpClientTest(com.github.mjeanroy.junit.servers.client.impl.BaseHttpClientTest)

Example 10 with HttpClient

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

the class BaseHttpClientTest method it_should_create_request_and_do_not_prepend_server_url.

@Test
void it_should_create_request_and_do_not_prepend_server_url() {
    final HttpClient client = createDefaultClient(server);
    final String endpoint = "/foo";
    final String absoluteUrl = server.getUrl() + endpoint;
    final HttpMethod httpMethod = HttpMethod.POST;
    final HttpRequest httpRequest = client.prepareRequest(httpMethod, absoluteUrl);
    assertThat(httpRequest.getMethod()).isEqualTo(httpMethod);
    assertThat(httpRequest.getEndpoint()).isNotNull();
    assertThat(httpRequest.getEndpoint().getScheme()).isEqualTo(scheme);
    assertThat(httpRequest.getEndpoint().getHost()).isEqualTo(host);
    assertThat(httpRequest.getEndpoint().getPort()).isEqualTo(port);
    assertThat(httpRequest.getEndpoint().getPath()).isEqualTo(path + endpoint);
    assertThat(httpRequest.getEndpoint().toString()).isEqualTo(url(scheme, host, port, path + endpoint));
}
Also used : HttpRequest(com.github.mjeanroy.junit.servers.client.HttpRequest) HttpClient(com.github.mjeanroy.junit.servers.client.HttpClient) HttpMethod(com.github.mjeanroy.junit.servers.client.HttpMethod) 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