use of com.github.ljtfreitas.julian.Response in project julian-http-client by ljtfreitas.
the class MultiResponseTTest method failure.
@Test
void failure() {
RuntimeException exception = new RuntimeException("oops");
Promise<Response<Collection<String>>> response = Promise.failed(exception);
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());
subscriber.assertFailedWith(RuntimeException.class, exception.getMessage());
}
use of com.github.ljtfreitas.julian.Response in project julian-http-client by ljtfreitas.
the class DefaultHTTPResponseFailureTest method shouldCreateTheFailureResponse.
@ParameterizedTest(name = "HTTP Status: {0}")
@MethodSource("failureHTTPStatuses")
void shouldCreateTheFailureResponse(HTTPStatus status, Class<? extends HTTPResponseException> exception) {
HTTPHeaders headers = HTTPHeaders.empty();
String responseBody = "response body";
HTTPClientResponse source = new HTTPClientResponse() {
@Override
public HTTPStatus status() {
return status;
}
@Override
public HTTPHeaders headers() {
return headers;
}
@Override
public HTTPResponseBody body() {
return new PublisherHTTPResponseBody(new SimplePublisher(responseBody));
}
@Override
public <T, R extends Response<T>> Optional<R> failure(Function<? super HTTPClientResponse, R> fn) {
return Optional.empty();
}
@Override
public <T, R extends Response<T>> Optional<R> success(Function<? super HTTPClientResponse, R> fn) {
return Optional.empty();
}
};
HTTPResponse<Object> failed = failure.apply(source, JavaType.valueOf(String.class));
assertAll(() -> assertNotNull(failed), () -> assertEquals(status, failed.status()), () -> assertEquals(headers, failed.headers()));
HTTPResponseException httpResponseException = assertThrows(exception, failed.body()::unsafe);
assertAll(() -> assertEquals(status, httpResponseException.status()), () -> assertEquals(headers, httpResponseException.headers()), () -> assertEquals(responseBody, httpResponseException.bodyAsString()));
}
use of com.github.ljtfreitas.julian.Response in project julian-http-client by ljtfreitas.
the class HTTPResponseTTest method compose.
@Test
void compose() {
Promise<HTTPResponse<String>> promise = Promise.done(HTTPResponse.success(HTTPStatus.valueOf(HTTPStatusCode.OK), HTTPHeaders.empty(), "hello"));
ResponseFn<String, Response<Object>> fn = new DefaultResponseT().bind(endpoint, new ObjectResponseT<>().bind(endpoint, null));
HTTPResponse<Object> actual = responseT.bind(endpoint, fn).join(promise, Arguments.empty());
assertEquals("hello", actual.body().unsafe());
}
use of com.github.ljtfreitas.julian.Response in project julian-http-client by ljtfreitas.
the class SetResponseTTest method bind.
@Test
void bind() {
when(endpoint.returnType()).thenReturn(JavaType.parameterized(Collection.class, String.class));
Collection<String> values = java.util.List.of("one", "two", "three");
Promise<Response<Collection<String>>> promise = Promise.done(Response.done(values));
ResponseFn<Collection<String>, Collection<Object>> fn = new CollectionResponseT().bind(endpoint, new ObjectResponseT<Collection<Object>>().bind(endpoint, null));
Set<Object> set = responseT.bind(endpoint, fn).join(promise, Arguments.empty());
assertTrue(set.containsAll(values));
}
use of com.github.ljtfreitas.julian.Response in project julian-http-client by ljtfreitas.
the class TraversableResponseTTest method bindNullCollection.
@Test
void bindNullCollection() {
when(endpoint.returnType()).thenReturn(JavaType.parameterized(Collection.class, String.class));
Promise<Response<Collection<String>>> promise = Promise.done(Response.done(null));
ResponseFn<Collection<String>, Collection<Object>> fn = new CollectionResponseT().bind(endpoint, new ObjectResponseT<Collection<Object>>().bind(endpoint, null));
Traversable<Object> traversable = responseT.bind(endpoint, fn).join(promise, Arguments.empty());
assertTrue(traversable.isEmpty());
}
Aggregations