use of com.github.ljtfreitas.julian.http.HTTPHeader in project julian-http-client by ljtfreitas.
the class HeadersResponseTTest method compose.
@Test
void compose(@Mock ResponseFn<Void, Void> fn, @Mock HTTPResponse<Void> response) {
Arguments arguments = Arguments.empty();
Headers headers = Headers.create(new Header("X-Header", "x-header-content"));
when(response.headers()).thenReturn(headers.all().stream().reduce(HTTPHeaders.empty(), (a, b) -> a.join(new HTTPHeader(b.name(), b.values())), (a, b) -> b));
when(response.cast(notNull())).thenCallRealMethod();
Headers actual = responseT.bind(endpoint, fn).join(Promise.done(response), arguments);
assertThat(actual, contains(headers.all().toArray()));
}
use of com.github.ljtfreitas.julian.http.HTTPHeader in project julian-http-client by ljtfreitas.
the class WebClientHTTPRequest method read.
Mono<HTTPResponse<T>> read(ClientResponse response) {
HTTPStatus status = new HTTPStatus(response.rawStatusCode(), response.statusCode().getReasonPhrase());
HTTPHeaders headers = response.headers().asHttpHeaders().entrySet().stream().reduce(HTTPHeaders.empty(), (h, e) -> h.join(new HTTPHeader(e.getKey(), e.getValue())), (a, b) -> b);
if (response.statusCode().isError()) {
return response.createException().map(e -> failure(status, headers, e));
} else {
return success(status, headers, response);
}
}
use of com.github.ljtfreitas.julian.http.HTTPHeader 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