use of com.github.ljtfreitas.julian.Response in project julian-http-client by ljtfreitas.
the class ObservableResponseTTest method bind.
@Test
void bind() {
Promise<Response<Collection<String>>> response = new SinglePromise<>(Single.just(Response.done(List.of("one", "two", "three"))));
ResponseFn<Collection<String>, Collection<Object>> fn = new CollectionResponseT().bind(endpoint, new ObjectResponseT<Collection<Object>>().bind(endpoint, null));
when(endpoint.returnType()).thenReturn(JavaType.parameterized(Collection.class, String.class));
Observable<Object> observable = subject.bind(endpoint, fn).join(response, Arguments.empty());
TestObserver<Object> observer = new TestObserver<>();
observable.subscribe(observer);
observer.assertComplete().assertNoErrors().assertValues("one", "two", "three");
}
use of com.github.ljtfreitas.julian.Response in project julian-http-client by ljtfreitas.
the class VertxHTTPClientResponse method valueOf.
static Single<VertxHTTPClientResponse> valueOf(HttpClientResponse response) {
HTTPStatus status = HTTPStatusCode.select(response.statusCode()).map(HTTPStatus::new).orElseGet(() -> new HTTPStatus(response.statusCode(), response.statusMessage()));
HTTPHeaders headers = response.headers().names().stream().map(name -> HTTPHeader.create(name, response.headers().getAll(name))).reduce(HTTPHeaders.empty(), HTTPHeaders::join, (a, b) -> b);
Maybe<byte[]> bodyAsBytes = response.body().map(Buffer::getBytes).toMaybe();
return bodyAsBytes.map(body -> HTTPResponseBody.optional(status, headers, () -> HTTPResponseBody.some(body))).map(body -> new VertxHTTPClientResponse(HTTPClientResponse.create(status, headers, body))).switchIfEmpty(Single.fromCallable(() -> new VertxHTTPClientResponse(HTTPClientResponse.empty(status, headers))));
}
use of com.github.ljtfreitas.julian.Response in project julian-http-client by ljtfreitas.
the class ReactorNettyHTTPClientResponse method valueOf.
static Mono<ReactorNettyHTTPClientResponse> valueOf(HttpClientResponse response, ByteBufMono bodyAsBuffer) {
HTTPStatus status = HTTPStatusCode.select(response.status().code()).map(HTTPStatus::new).orElseGet(() -> new HTTPStatus(response.status().code(), response.status().reasonPhrase()));
HTTPHeaders headers = response.responseHeaders().names().stream().map(name -> HTTPHeader.create(name, response.responseHeaders().getAll(name))).reduce(HTTPHeaders.empty(), HTTPHeaders::join, (a, b) -> b);
return bodyAsBuffer.asByteArray().map(bodyAsBytes -> HTTPResponseBody.optional(status, headers, () -> HTTPResponseBody.some(bodyAsBytes))).map(body -> new ReactorNettyHTTPClientResponse(HTTPClientResponse.create(status, headers, body))).switchIfEmpty(Mono.fromCallable(() -> new ReactorNettyHTTPClientResponse(HTTPClientResponse.empty(status, headers))));
}
use of com.github.ljtfreitas.julian.Response in project julian-http-client by ljtfreitas.
the class MultiResponseTTest method bind.
@Test
void bind() {
Promise<Response<Collection<String>>> response = Promise.done(Response.done(List.of("one", "two", "three")));
when(endpoint.returnType()).thenReturn(JavaType.parameterized(Collection.class, String.class));
ResponseFn<Collection<String>, Collection<Object>> fn = new CollectionResponseT().bind(endpoint, new ObjectResponseT<Collection<Object>>().bind(endpoint, null));
Multi<Object> multi = subject.bind(endpoint, fn).join(response, Arguments.empty());
AssertSubscriber<Object> subscriber = multi.subscribe().withSubscriber(AssertSubscriber.create(3));
subscriber.assertCompleted().assertItems("one", "two", "three");
}
use of com.github.ljtfreitas.julian.Response in project julian-http-client by ljtfreitas.
the class CompletableResponseTTest method bind.
@Test
void bind() {
Promise<Response<Void>> response = new SinglePromise<>(Single.just(Response.done(null)));
ResponseFn<Void, Response<Object>> fn = new DefaultResponseT().bind(endpoint, new ObjectResponseT<>().bind(endpoint, null));
Completable completable = subject.bind(endpoint, fn).join(response, Arguments.empty());
TestObserver<Void> observer = new TestObserver<>();
completable.subscribe(observer);
observer.assertComplete().assertNoErrors();
}
Aggregations