use of org.folio.circulation.support.HttpFailure 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.HttpFailure in project mod-circulation by folio-org.
the class ResultApplySideEffectTests method shouldApplyFailureConsumerWhenFailed.
@Test
void shouldApplyFailureConsumerWhenFailed() {
final AtomicBoolean appliedSuccess = new AtomicBoolean();
final AtomicReference<HttpFailure> appliedFailure = new AtomicReference<>();
alreadyFailed().applySideEffect(value -> appliedSuccess.set(true), appliedFailure::set);
Awaitility.await().atMost(1, SECONDS).until(appliedFailure::get, isFailureContaining("Already failed"));
assertThat("Should not have applied success consumer", appliedSuccess.get(), is(false));
}
use of org.folio.circulation.support.HttpFailure in project mod-circulation by folio-org.
the class GroupedLoanScheduledNoticeHandler method handleResult.
private CompletableFuture<Result<List<ScheduledNotice>>> handleResult(Result<List<ScheduledNotice>> result, List<ScheduledNotice> notices) {
if (result.succeeded()) {
log.info("Group of {} scheduled notices was processed successfully", notices.size());
return completedFuture(result);
}
HttpFailure failure = result.cause();
log.error("Failed to process group of {} scheduled notices: {}", notices.size(), failure);
return ofAsync(() -> notices);
}
use of org.folio.circulation.support.HttpFailure in project mod-circulation by folio-org.
the class GroupedLoanScheduledNoticeHandler method handleDataCollectionFailure.
protected CompletableFuture<Result<ScheduledNoticeContext>> handleDataCollectionFailure(Result<ScheduledNoticeContext> result, ScheduledNotice notice) {
if (result.failed()) {
HttpFailure cause = result.cause();
log.error("Failed to collect data for scheduled notice: {}.\n{}", cause, notice);
return loanScheduledNoticeHandler.deleteNotice(notice, cause.toString()).thenApply(r -> r.next(n -> result));
}
return completedFuture(result);
}
use of org.folio.circulation.support.HttpFailure in project mod-circulation by folio-org.
the class FailureMatcher method isFailureContaining.
public static Matcher<HttpFailure> isFailureContaining(String expectedReason) {
return new TypeSafeDiagnosingMatcher<HttpFailure>() {
@Override
public void describeTo(Description description) {
description.appendText(String.format("a failure: %s", expectedReason));
}
@Override
protected boolean matchesSafely(HttpFailure failure, Description description) {
if (failure instanceof ServerErrorFailure) {
final ServerErrorFailure cause = (ServerErrorFailure) failure;
final Matcher<String> matcher = containsString(expectedReason);
matcher.describeMismatch(cause.reason, description);
return matcher.matches(cause.reason);
} else {
description.appendText("but is not a failure");
return false;
}
}
};
}
Aggregations