use of com.github.ljtfreitas.julian.http.DefaultHTTPRequestBody in project julian-http-client by ljtfreitas.
the class MapMultipartFormHTTPRequestWriter method write.
@Override
public HTTPRequestBody write(Map<String, ?> map, Charset encoding) {
String boundary = boundaryGen.run();
MediaType mediaType = MediaType.MULTIPART_FORM_DATA.parameter("boundary", boundary);
return new DefaultHTTPRequestBody(mediaType, () -> serialize(map, encoding, "----" + boundary));
}
use of com.github.ljtfreitas.julian.http.DefaultHTTPRequestBody in project julian-http-client by ljtfreitas.
the class DebugHTTPClientTest method show.
@Test
void show(@Mock HTTPRequest<String> httpRequest) {
mockServer.when(request("/debug").withMethod("POST").withBody("request body")).respond(response().withStatusCode(200).withContentType(TEXT_PLAIN).withHeader("x-some-header", "some-content").withBody("it works!"));
DebugHTTPClient debugHTTPClient = new DebugHTTPClient(new DefaultHTTPClient());
when(httpRequest.path()).thenReturn(URI.create("http://localhost:8090/debug"));
when(httpRequest.method()).thenReturn(HTTPMethod.POST);
when(httpRequest.headers()).thenReturn(new HTTPHeaders(List.of(new HTTPHeader("X-Some-Header", "some-content"), new HTTPHeader("Accept", "text/plain"))));
when(httpRequest.body()).thenReturn(Optional.of(new DefaultHTTPRequestBody(MediaType.TEXT_PLAIN, () -> BodyPublishers.ofString("request body"))));
HTTPClientRequest intercepted = debugHTTPClient.request(httpRequest);
intercepted.execute().join().unsafe();
verify(httpRequest, atLeastOnce()).path();
verify(httpRequest, atLeastOnce()).headers();
verify(httpRequest, atLeastOnce()).method();
}
Aggregations