use of org.folio.circulation.support.ServerErrorFailure in project mod-circulation by folio-org.
the class RequestByInstanceIdResourceTests method getExpectedErrorMessages.
@Test
void getExpectedErrorMessages() {
HttpFailure validationError = ValidationErrorFailure.singleValidationError(new ValidationError("validationError", "someParam", "null"));
String errorMessage = RequestByInstanceIdResource.getErrorMessage(validationError);
assertTrue(errorMessage.contains("validationError"));
HttpFailure serverErrorFailure = new ServerErrorFailure("serverError");
errorMessage = RequestByInstanceIdResource.getErrorMessage(serverErrorFailure);
assertEquals("serverError", errorMessage);
HttpFailure badRequestFailure = new BadRequestFailure("badRequestFailure");
errorMessage = RequestByInstanceIdResource.getErrorMessage(badRequestFailure);
assertEquals("badRequestFailure", errorMessage);
Response fakeResponse = new Response(500, "fakeResponseFailure", "text/javascript");
HttpFailure forwardOnFailure = new ForwardOnFailure(fakeResponse);
errorMessage = RequestByInstanceIdResource.getErrorMessage(forwardOnFailure);
assertEquals("fakeResponseFailure", errorMessage);
}
use of org.folio.circulation.support.ServerErrorFailure 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.ServerErrorFailure 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.ServerErrorFailure in project mod-circulation by folio-org.
the class MoreThanOneLoanValidatorTests method allowSingleLoan.
@Test
void allowSingleLoan() {
final MoreThanOneLoanValidator validator = new MoreThanOneLoanValidator(() -> new ServerErrorFailure("More than one loan"));
final Result<MultipleRecords<Loan>> multipleLoans = multipleLoansResult(generateLoan());
final Result<MultipleRecords<Loan>> result = validator.failWhenMoreThanOneLoan(multipleLoans);
assertThat(result.succeeded(), is(true));
}
use of org.folio.circulation.support.ServerErrorFailure in project mod-circulation by folio-org.
the class MoreThanOneLoanValidatorTests method failWhenMoreThanOneLoan.
@Test
void failWhenMoreThanOneLoan() {
final MoreThanOneLoanValidator validator = new MoreThanOneLoanValidator(() -> new ServerErrorFailure("More than one loan"));
final Result<MultipleRecords<Loan>> multipleLoans = multipleLoansResult(generateLoan(), generateLoan());
final Result<MultipleRecords<Loan>> result = validator.failWhenMoreThanOneLoan(multipleLoans);
assertThat(result, isErrorFailureContaining("More than one loan"));
}
Aggregations