use of com.github.mjeanroy.junit.servers.client.HttpClient in project junit-servers by mjeanroy.
the class JunitServerExtensionTest method it_should_reset_injected_http_client_after_each_test.
@Test
void it_should_reset_injected_http_client_after_each_test() {
final JunitServerExtension extension = new JunitServerExtension();
final FixtureClass testInstance = new FixtureClass();
final FakeExtensionContext context = new FakeExtensionContext(testInstance);
extension.beforeAll(context);
extension.beforeEach(context);
final HttpClient client = testInstance.client;
final FakeStore store = context.getSingleStore();
extension.afterEach(context);
assertThat(store.get("annotationsAdapter")).isNull();
assertThat(testInstance.client).isNull();
assertThat(client.isDestroyed()).isTrue();
}
use of com.github.mjeanroy.junit.servers.client.HttpClient in project junit-servers by mjeanroy.
the class ServerRuleTest method it_should_get_new_http_client_if_it_has_been_destroyed.
@Test
void it_should_get_new_http_client_if_it_has_been_destroyed() {
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();
client.destroy();
final HttpClient newClient = rule.getClient();
assertThat(newClient).isNotNull();
assertThat(newClient).isNotSameAs(client);
assertThat(newClient.isDestroyed()).isFalse();
}
use of com.github.mjeanroy.junit.servers.client.HttpClient in project junit-servers by mjeanroy.
the class BaseHttpClientTest method it_should_fail_to_create_request_from_a_destroyed_client.
@Test
void it_should_fail_to_create_request_from_a_destroyed_client() {
final String endpoint = "/foo";
final HttpClient newClient = createDefaultClient();
newClient.destroy();
assertThatThrownBy(() -> newClient.prepareGet(endpoint)).isExactlyInstanceOf(IllegalStateException.class).hasMessage("Cannot create request from a destroyed client");
}
use of com.github.mjeanroy.junit.servers.client.HttpClient in project junit-servers by mjeanroy.
the class NingAsyncHttpClientTest 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 AsyncHttpClient internalClient = readPrivate(client, "client");
assertThat(client).hasToString("NingAsyncHttpClient{" + "configuration: HttpClientConfiguration{" + "followRedirect: true, " + "defaultHeaders: {}, " + "defaultCookies: []" + "}, " + "server: MockEmbeddedServer, " + "client: " + internalClient.toString() + "}");
}
use of com.github.mjeanroy.junit.servers.client.HttpClient in project junit-servers by mjeanroy.
the class BaseHttpClientTest method it_should_destroy_client.
@Test
void it_should_destroy_client() {
final HttpClient newClient = createDefaultClient();
assertThat(newClient.isDestroyed()).isFalse();
newClient.destroy();
assertThat(newClient.isDestroyed()).isTrue();
}
Aggregations