use of com.github.mjeanroy.junit.servers.client.HttpMethod in project junit-servers by mjeanroy.
the class OkHttpRequest method handleBody.
/**
* Add request body if appropriate.
*
* @param builder The native OkHttp request builder.
* @see Request.Builder#method(String, RequestBody)
* @see RequestBody
*/
private void handleBody(Request.Builder builder) throws IOException {
log.debug("Adding request body");
RequestBody okhttpRequestBody = hasBody() ? createBody() : null;
log.debug("Created body: {}", okhttpRequestBody);
// Force an empty body, as POST & PUT methods requires
// a body element.
HttpMethod method = getMethod();
if (okhttpRequestBody == null && method.isBodyAllowed()) {
log.debug("Request method {} requires a body, but no one found, adding empty request body)", method);
okhttpRequestBody = createEmptyBody();
}
builder.method(method.getVerb(), okhttpRequestBody);
if (body != null && body.getContentType() != null) {
builder.header("Content-Type", body.getContentType());
}
}
use of com.github.mjeanroy.junit.servers.client.HttpMethod in project junit-servers by mjeanroy.
the class BaseHttpClientTest method it_should_create_request.
@Test
void it_should_create_request() {
final HttpClient client = createDefaultClient(server);
final String endpoint = "/foo";
final HttpMethod httpMethod = HttpMethod.POST;
final HttpRequest httpRequest = client.prepareRequest(httpMethod, endpoint);
assertThat(httpRequest.getMethod()).isEqualTo(httpMethod);
assertThat(httpRequest.getEndpoint()).isNotNull();
assertThat(httpRequest.getEndpoint().getScheme()).isEqualTo(scheme);
assertThat(httpRequest.getEndpoint().getHost()).isEqualTo(host);
assertThat(httpRequest.getEndpoint().getPort()).isEqualTo(port);
assertThat(httpRequest.getEndpoint().getPath()).isEqualTo(path + endpoint);
assertThat(httpRequest.getEndpoint().toString()).isEqualTo(url(scheme, host, port, path + endpoint));
}
Aggregations