use of com.github.mjeanroy.junit.servers.client.HttpResponse in project junit-servers by mjeanroy.
the class BaseHttpClientTest method testQueryParams.
private void testQueryParams(String expectedUrl, Function<HttpRequest> func) {
// GIVEN
final int rspStatus = 200;
final Collection<Pair> headers = singleton(pair(CONTENT_TYPE, APPLICATION_JSON));
final String rspBody = "[]";
stubGetRequest(expectedUrl, rspStatus, headers, rspBody);
// WHEN
final HttpRequest rq = createDefaultClient().prepareGet(ENDPOINT);
func.apply(rq);
// THEN
final HttpResponse rsp = rq.execute();
assertThat(rsp).isNotNull();
assertThat(rsp.status()).isEqualTo(rspStatus);
assertThat(rsp.body()).isEqualTo(rspBody);
assertRequest(expectedUrl, HttpMethod.GET);
}
use of com.github.mjeanroy.junit.servers.client.HttpResponse in project junit-servers by mjeanroy.
the class BaseHttpClientTest method testPutWithoutBody.
@Test
void testPutWithoutBody() {
final String endpoint = ENDPOINT + "/1";
final int status = 204;
final Collection<Pair> headers = emptyList();
stubPutRequest(endpoint, status, headers);
final HttpResponse rsp = createDefaultClient().preparePut(endpoint).acceptJson().asJson().asXmlHttpRequest().execute();
assertRequest(endpoint, HttpMethod.PUT);
assertThat(rsp.status()).isEqualTo(status);
assertThat(rsp.body()).isEmpty();
assertThat(rsp.getContentType()).isNull();
}
use of com.github.mjeanroy.junit.servers.client.HttpResponse in project junit-servers by mjeanroy.
the class NingAsyncHttpResponseFactoryTest method it_should_create_http_response.
@Test
void it_should_create_http_response() {
final Response delegate = new NingHttpResponseBuilder().build();
final long duration = 1000L;
final HttpResponse response = NingAsyncHttpResponseFactory.of(delegate, duration);
assertThat(response).isNotNull().isExactlyInstanceOf(NingAsyncHttpResponse.class);
assertThat(response.getRequestDuration()).isEqualTo(duration);
}
use of com.github.mjeanroy.junit.servers.client.HttpResponse in project junit-servers by mjeanroy.
the class OkHttpResponseFactoryTest method it_should_create_http_response.
@Test
void it_should_create_http_response() {
final Response delegate = new OkHttpResponseBuilder().build();
final long duration = 1000L;
final HttpResponse response = OkHttpResponseFactory.of(delegate, duration);
assertThat(response).isNotNull().isExactlyInstanceOf(OkHttpResponse.class);
assertThat(response.getRequestDuration()).isEqualTo(duration);
}
use of com.github.mjeanroy.junit.servers.client.HttpResponse in project junit-servers by mjeanroy.
the class BaseHttpClientTest method testGetWithFullEndpoint.
@Test
void testGetWithFullEndpoint() {
final String endpoint = ENDPOINT;
final String rqUrl = url(scheme, host, port, endpoint);
final int status = 200;
final Collection<Pair> headers = singleton(pair(CONTENT_TYPE, APPLICATION_JSON));
final String body = "[{\"id\": 1, \"name\": \"John Doe\"}]";
stubGetRequest(endpoint, status, headers, body);
final HttpResponse rsp = createDefaultClient().prepareGet(rqUrl).acceptJson().asXmlHttpRequest().execute();
assertRequest(endpoint, HttpMethod.GET);
assertThat(rsp.status()).isEqualTo(status);
assertThat(rsp.body()).isEqualTo(body);
assertThat(rsp.getContentType().getFirstValue()).isEqualTo(APPLICATION_JSON);
assertThat(rsp.getContentType().getLastValue()).isEqualTo(APPLICATION_JSON);
}
Aggregations