use of com.github.mjeanroy.junit.servers.client.HttpRequestBody in project junit-servers by mjeanroy.
the class BaseHttpClientTest method testRequest_set_raw_body.
@Test
void testRequest_set_raw_body() {
final String rawBody = "{\"id\": 1, \"firstName\": \"John\", \"lastName\": \"Doe\"}";
final HttpRequestBody body = requestBody(rawBody);
testRequestBody(rawBody, rq -> rq.setBody(body));
}
use of com.github.mjeanroy.junit.servers.client.HttpRequestBody in project junit-servers by mjeanroy.
the class BaseHttpClientTest method testRequest_set_body.
@Test
void testRequest_set_body() {
final String rawBody = "{\"id\": 1, \"firstName\": \"John\", \"lastName\": \"Doe\"}";
final HttpRequestBody body = requestBody(rawBody);
testRequestBody(rawBody, rq -> rq.setBody(body));
}
use of com.github.mjeanroy.junit.servers.client.HttpRequestBody in project junit-servers by mjeanroy.
the class BaseHttpClientTest method testRequest_add_form_param.
@Test
void testRequest_add_form_param() {
final String name = "firstName";
final String value = "john";
final String expectedBody = encodeFormParam(name, value);
final Map<String, String> parameters = singletonMap(name, value);
final HttpRequestBody body = formUrlEncodedBody(parameters);
testRequestBody(expectedBody, rq -> rq.setBody(body));
}
use of com.github.mjeanroy.junit.servers.client.HttpRequestBody in project junit-servers by mjeanroy.
the class BaseHttpClientTest method testPutWithJsonBodyString.
@Test
void testPutWithJsonBodyString() {
final String endpoint = ENDPOINT + "/1";
final int status = 204;
final Collection<Pair> headers = emptyList();
final String rawBody = "{\"id\": 1, \"name\": \"Jane Doe\"}";
final HttpRequestBody body = jsonBody(rawBody);
stubPutRequest(endpoint, status, headers);
final HttpResponse rsp = createDefaultClient().preparePut(endpoint).acceptJson().asXmlHttpRequest().setBody(body).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.HttpRequestBody in project junit-servers by mjeanroy.
the class BaseHttpClientTest method testPatchWithRawBody.
@Test
void testPatchWithRawBody() {
final String endpoint = ENDPOINT;
final int status = 201;
final Collection<Pair> headers = singleton(pair(CONTENT_TYPE, APPLICATION_JSON));
final String responseBody = "{\"id\": 1, \"name\": \"Jane Doe\"}";
final String rawBody = "{\"name\": \"Jane Doe\"}";
final HttpRequestBody body = jsonBody(rawBody);
stubPatchRequest(endpoint, status, headers, responseBody);
final HttpResponse rsp = createDefaultClient().preparePatch(endpoint).acceptJson().asJson().asXmlHttpRequest().setBody(body).execute();
assertRequest(endpoint, HttpMethod.PATCH);
assertThat(rsp.status()).isEqualTo(status);
assertThat(rsp.body()).isEqualTo(responseBody);
assertThat(rsp.getContentType().getFirstValue()).isEqualTo(APPLICATION_JSON);
assertThat(rsp.getContentType().getLastValue()).isEqualTo(APPLICATION_JSON);
}
Aggregations