use of org.folio.circulation.support.results.Result in project mod-circulation by folio-org.
the class FakeStorageModule method batchUpdate.
private void batchUpdate(RoutingContext routingContext) {
WebContext context = new WebContext(routingContext);
JsonObject body = routingContext.getBodyAsJson();
if (batchUpdatePreProcessor != null) {
body = batchUpdatePreProcessor.apply(body);
}
JsonArray entities = body.getJsonArray(collectionPropertyName);
Result<Void> lastResult = Result.succeeded(null);
for (int entityIndex = 0; entityIndex < entities.size(); entityIndex++) {
JsonObject entity = entities.getJsonObject(entityIndex);
String id = entity.getString("id");
lastResult = lastResult.next(notUsed -> replaceSingleItem(context, id, entity));
}
if (lastResult.failed()) {
lastResult.cause().writeTo(routingContext.response());
} else {
routingContext.response().setStatusCode(201).end();
}
}
use of org.folio.circulation.support.results.Result in project mod-circulation by folio-org.
the class LogCheckInServiceTest method logCheckInOperationPropagatesException.
@Test
void logCheckInOperationPropagatesException() {
final CheckInContext context = checkInProcessRecords();
final ServerErrorFailure postError = new ServerErrorFailure("ServerError");
when(checkInStorageClient.post(any(JsonObject.class))).thenReturn(CompletableFuture.completedFuture(Result.failed(postError)));
final CompletableFuture<Result<CheckInContext>> logCheckInOperation = logCheckInService.logCheckInOperation(context);
final Result<CheckInContext> logResult = logCheckInOperation.getNow(Result.failed(new ServerErrorFailure("Uncompleted")));
assertThat(logResult.failed(), is(true));
assertThat(logResult.cause(), is(postError));
}
use of org.folio.circulation.support.results.Result in project mod-circulation by folio-org.
the class ResponseInterpretationTests method shouldCaptureErrorWhenMappingFailsAtRuntime.
@Test
void shouldCaptureErrorWhenMappingFailsAtRuntime() {
final JsonObject body = new JsonObject().put("foo", "hello").put("bar", "world");
Result<JsonObject> result = new ResponseInterpreter<JsonObject>().flatMapOn(200, response -> {
throw new RuntimeException("Not good");
}).apply(new Response(200, body.toString(), ""));
assertThat(result.succeeded(), is(false));
assertThat(result.cause(), instanceOf(ServerErrorFailure.class));
final ServerErrorFailure cause = (ServerErrorFailure) result.cause();
assertThat(cause.getReason(), containsString("Not good"));
assertThat(cause.getReason(), containsString("RuntimeException"));
}
use of org.folio.circulation.support.results.Result in project mod-circulation by folio-org.
the class VertxWebClientOkapiHttpClientTests method canPutWithJson.
@Test
public void canPutWithJson() throws InterruptedException, ExecutionException, TimeoutException {
fakeWebServer.stubFor(matchingFolioHeaders(put(urlPathEqualTo("/record/12345"))).withHeader("Content-Type", equalTo("application/json")).withRequestBody(equalToJson(dummyJsonRequestBody().encodePrettily())).willReturn(noContent()));
OkapiHttpClient client = createClient();
CompletableFuture<Result<Response>> postCompleted = client.put(fakeWebServer.url("/record/12345"), dummyJsonRequestBody());
final Response response = postCompleted.get(2, SECONDS).value();
assertThat(response, hasStatus(HTTP_NO_CONTENT));
assertThat(response.getBody(), is(emptyOrNullString()));
}
use of org.folio.circulation.support.results.Result in project mod-circulation by folio-org.
the class VertxWebClientOkapiHttpClientTests method canPostWithJson.
@Test
public void canPostWithJson() throws InterruptedException, ExecutionException, TimeoutException {
final String locationResponseHeader = "/a-different-location";
fakeWebServer.stubFor(matchingFolioHeaders(post(urlPathEqualTo("/record"))).withHeader("Content-Type", equalTo("application/json")).withRequestBody(equalToJson(dummyJsonRequestBody().encodePrettily())).willReturn(created().withBody(dummyJsonResponseBody()).withHeader("Content-Type", "application/json").withHeader("Location", locationResponseHeader)));
OkapiHttpClient client = createClient();
CompletableFuture<Result<Response>> postCompleted = client.post(fakeWebServer.url("/record"), dummyJsonRequestBody());
final Response response = postCompleted.get(2, SECONDS).value();
assertThat(response, hasStatus(HTTP_CREATED));
assertThat(response.getJson().getString("message"), is("hello"));
assertThat(response.getContentType(), is("application/json"));
assertThat(response.getHeader("location"), is(locationResponseHeader));
}
Aggregations