use of com.github.mjeanroy.junit.servers.client.HttpRequestBody in project junit-servers by mjeanroy.
the class BaseHttpClientTest method testPostWithJsonBodyString.
@Test
void testPostWithJsonBodyString() {
final String endpoint = ENDPOINT;
final int status = 201;
final String rawBody = "{\"id\": 1, \"name\": \"Jane Doe\"}";
final HttpRequestBody body = jsonBody(rawBody);
final Collection<Pair> expectedHeaders = singleton(pair(CONTENT_TYPE, APPLICATION_JSON));
stubPostRequest(endpoint, status, expectedHeaders, rawBody);
final HttpResponse rsp = createDefaultClient().preparePost(endpoint).acceptJson().asXmlHttpRequest().setBody(body).execute();
assertRequest(endpoint, HttpMethod.POST);
assertThat(rsp.status()).isEqualTo(status);
assertThat(rsp.body()).isEqualTo(rawBody);
assertThat(rsp.getContentType().getFirstValue()).isEqualTo(APPLICATION_JSON);
assertThat(rsp.getContentType().getLastValue()).isEqualTo(APPLICATION_JSON);
}
use of com.github.mjeanroy.junit.servers.client.HttpRequestBody in project junit-servers by mjeanroy.
the class BaseHttpClientTest method testRequest_add_non_escaped_form_param_value.
@Test
void testRequest_add_non_escaped_form_param_value() {
final String name = "name";
final String value = "john doe";
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 testRequest_add_non_escaped_form_param_name.
@Test
void testRequest_add_non_escaped_form_param_name() {
final String name = "first name";
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 testRequest_add_several_form_params.
@Test
void testRequest_add_several_form_params() {
final String n1 = "firstName";
final String v1 = "John";
final HttpParameter p1 = param(n1, v1);
final String n2 = "lastName";
final String v2 = "Doe";
final HttpParameter p2 = param(n2, v2);
final HttpRequestBody body = formUrlEncodedBody(p1, p2);
final String expectedBody = encodeFormParam(n1, v1) + "&" + encodeFormParam(n2, v2);
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 testPatch.
@Test
void testPatch() {
final String endpoint = ENDPOINT;
final int status = 201;
final Collection<Pair> headers = singleton(pair(CONTENT_TYPE, APPLICATION_JSON));
final String bodyResponse = "{\"id\": 1, \"name\": \"Jane Doe\"}";
final String rawBody = "{\"name\": \"Jane Doe\"}";
final HttpRequestBody body = jsonBody(rawBody);
stubPatchRequest(endpoint, status, headers, bodyResponse);
final HttpResponse rsp = createDefaultClient().preparePatch(endpoint).acceptJson().asXmlHttpRequest().setBody(body).execute();
assertRequest(endpoint, HttpMethod.PATCH);
assertThat(rsp.status()).isEqualTo(status);
assertThat(rsp.body()).isEqualTo(bodyResponse);
assertThat(rsp.getContentType().getFirstValue()).isEqualTo(APPLICATION_JSON);
assertThat(rsp.getContentType().getLastValue()).isEqualTo(APPLICATION_JSON);
}
Aggregations