use of com.github.mjeanroy.junit.servers.utils.commons.Pair in project junit-servers by mjeanroy.
the class BaseHttpClientTest method testPut.
@Test
void testPut() {
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().asXmlHttpRequest().setBody(jsonBody("{\"id\": 1, \"name\": \"Jane Doe\"}")).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.utils.commons.Pair in project junit-servers by mjeanroy.
the class BaseHttpClientTest method testGet.
@Test
void testGet() {
final String endpoint = 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(endpoint).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);
}
use of com.github.mjeanroy.junit.servers.utils.commons.Pair in project junit-servers by mjeanroy.
the class BaseHttpClientTest method testRequestBody.
private void testRequestBody(String body, Function<HttpRequest> func) {
final String endpoint = ENDPOINT;
final int rspStatus = 204;
final Collection<Pair> headers = emptyList();
final String rspBody = "";
stubPostRequest(endpoint, rspStatus, headers, rspBody);
final HttpRequest rq = createDefaultClient().preparePost(ENDPOINT);
func.apply(rq);
final HttpResponse rsp = rq.execute();
assertThat(rsp).isNotNull();
assertThat(rsp.status()).isEqualTo(rspStatus);
assertThat(rsp.body()).isEqualTo(rspBody);
assertRequestWithBody(endpoint, HttpMethod.POST, body);
}
use of com.github.mjeanroy.junit.servers.utils.commons.Pair 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.utils.commons.Pair 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();
}
Aggregations