Search in sources :

Example 11 with EmbeddedServerMockBuilder

use of com.github.mjeanroy.junit.servers.utils.builders.EmbeddedServerMockBuilder 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 12 with EmbeddedServerMockBuilder

use of com.github.mjeanroy.junit.servers.utils.builders.EmbeddedServerMockBuilder 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)

Example 13 with EmbeddedServerMockBuilder

use of com.github.mjeanroy.junit.servers.utils.builders.EmbeddedServerMockBuilder 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 14 with EmbeddedServerMockBuilder

use of com.github.mjeanroy.junit.servers.utils.builders.EmbeddedServerMockBuilder 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 15 with EmbeddedServerMockBuilder

use of com.github.mjeanroy.junit.servers.utils.builders.EmbeddedServerMockBuilder in project junit-servers by mjeanroy.

the class HttpClientAnnotationHandlerTest method it_should_implement_to_string.

@Test
void it_should_implement_to_string() {
    final EmbeddedServer<?> server = new EmbeddedServerMockBuilder().build();
    final AnnotationHandler handler = newHttpClientAnnotationHandler(server);
    assertThat(handler).hasToString("HttpClientAnnotationHandler{" + "annotationKlass: interface com.github.mjeanroy.junit.servers.annotations.TestHttpClient, " + "server: MockEmbeddedServer" + "}");
}
Also used : 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

EmbeddedServerMockBuilder (com.github.mjeanroy.junit.servers.utils.builders.EmbeddedServerMockBuilder)56 Test (org.junit.jupiter.api.Test)52 HttpClient (com.github.mjeanroy.junit.servers.client.HttpClient)22 OkHttpClient (com.github.mjeanroy.junit.servers.client.impl.okhttp3.OkHttpClient)12 HttpClientConfiguration (com.github.mjeanroy.junit.servers.client.HttpClientConfiguration)6 HttpClientStrategy (com.github.mjeanroy.junit.servers.client.HttpClientStrategy)6 Field (java.lang.reflect.Field)6 HttpClientAnnotationHandler.newHttpClientAnnotationHandler (com.github.mjeanroy.junit.servers.engine.HttpClientAnnotationHandler.newHttpClientAnnotationHandler)5 BaseHttpClientTest (com.github.mjeanroy.junit.servers.client.impl.BaseHttpClientTest)4 EmbeddedServerRunner (com.github.mjeanroy.junit.servers.engine.EmbeddedServerRunner)4 AbstractConfiguration (com.github.mjeanroy.junit.servers.servers.AbstractConfiguration)4 AbstractConfigurationMockBuilder (com.github.mjeanroy.junit.servers.utils.builders.AbstractConfigurationMockBuilder)4 FixtureClass (com.github.mjeanroy.junit.servers.utils.fixtures.FixtureClass)4 FakeEmbeddedServerConfigurationBuilder (com.github.mjeanroy.junit.servers.utils.impl.FakeEmbeddedServerConfigurationBuilder)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 TestHttpClient (com.github.mjeanroy.junit.servers.annotations.TestHttpClient)3 ServerAnnotationHandler.newServerAnnotationHandler (com.github.mjeanroy.junit.servers.engine.ServerAnnotationHandler.newServerAnnotationHandler)3 Fields.getPrivateField (com.github.mjeanroy.junit.servers.utils.commons.Fields.getPrivateField)2 Annotation (java.lang.annotation.Annotation)2 ApacheHttpClient.defaultApacheHttpClient (com.github.mjeanroy.junit.servers.client.impl.apache.ApacheHttpClient.defaultApacheHttpClient)1