Search in sources :

Example 1 with HttpFailure

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);
}
Also used : Response(org.folio.circulation.support.http.client.Response) ServerErrorFailure(org.folio.circulation.support.ServerErrorFailure) HttpFailure(org.folio.circulation.support.HttpFailure) BadRequestFailure(org.folio.circulation.support.BadRequestFailure) ValidationError(org.folio.circulation.support.http.server.ValidationError) ForwardOnFailure(org.folio.circulation.support.ForwardOnFailure) Test(org.junit.jupiter.api.Test)

Example 2 with HttpFailure

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));
}
Also used : AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) HttpFailure(org.folio.circulation.support.HttpFailure) AtomicReference(java.util.concurrent.atomic.AtomicReference) Test(org.junit.jupiter.api.Test)

Example 3 with HttpFailure

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);
}
Also used : HttpFailure(org.folio.circulation.support.HttpFailure)

Example 4 with HttpFailure

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);
}
Also used : Clients(org.folio.circulation.support.Clients) ScheduledNoticeContext(org.folio.circulation.domain.notice.schedule.ScheduledNoticeHandler.ScheduledNoticeContext) LoanRepository(org.folio.circulation.infrastructure.storage.loans.LoanRepository) ResultBinding.mapResult(org.folio.circulation.support.results.ResultBinding.mapResult) CompletableFuture.completedFuture(java.util.concurrent.CompletableFuture.completedFuture) ZonedDateTime(java.time.ZonedDateTime) LoggerFactory(org.slf4j.LoggerFactory) CompletableFuture(java.util.concurrent.CompletableFuture) AsyncCoordinationUtil.allOf(org.folio.circulation.support.AsyncCoordinationUtil.allOf) AsyncCoordinationUtil.allResultsOf(org.folio.circulation.support.AsyncCoordinationUtil.allResultsOf) HttpFailure(org.folio.circulation.support.HttpFailure) ScheduledPatronNoticeService(org.folio.circulation.domain.notice.ScheduledPatronNoticeService) Logger(org.slf4j.Logger) Result.succeeded(org.folio.circulation.support.results.Result.succeeded) MethodHandles(java.lang.invoke.MethodHandles) Loan(org.folio.circulation.domain.Loan) Result(org.folio.circulation.support.results.Result) Result.ofAsync(org.folio.circulation.support.results.Result.ofAsync) User(org.folio.circulation.domain.User) Collectors.toList(java.util.stream.Collectors.toList) List(java.util.List) NoticeLogContextItem(org.folio.circulation.domain.representations.logs.NoticeLogContextItem) TemplateContextUtil.createMultiLoanNoticeContext(org.folio.circulation.domain.notice.TemplateContextUtil.createMultiLoanNoticeContext) Predicate.not(java.util.function.Predicate.not) NoticeLogContext(org.folio.circulation.domain.representations.logs.NoticeLogContext) HttpFailure(org.folio.circulation.support.HttpFailure)

Example 5 with HttpFailure

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;
            }
        }
    };
}
Also used : Description(org.hamcrest.Description) ServerErrorFailure(org.folio.circulation.support.ServerErrorFailure) HttpFailure(org.folio.circulation.support.HttpFailure) StringContains.containsString(org.hamcrest.core.StringContains.containsString) TypeSafeDiagnosingMatcher(org.hamcrest.TypeSafeDiagnosingMatcher)

Aggregations

HttpFailure (org.folio.circulation.support.HttpFailure)6 ServerErrorFailure (org.folio.circulation.support.ServerErrorFailure)2 Test (org.junit.jupiter.api.Test)2 MethodHandles (java.lang.invoke.MethodHandles)1 ZonedDateTime (java.time.ZonedDateTime)1 List (java.util.List)1 CompletableFuture (java.util.concurrent.CompletableFuture)1 CompletableFuture.completedFuture (java.util.concurrent.CompletableFuture.completedFuture)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 AtomicReference (java.util.concurrent.atomic.AtomicReference)1 Predicate.not (java.util.function.Predicate.not)1 Collectors.toList (java.util.stream.Collectors.toList)1 Loan (org.folio.circulation.domain.Loan)1 User (org.folio.circulation.domain.User)1 ScheduledPatronNoticeService (org.folio.circulation.domain.notice.ScheduledPatronNoticeService)1 TemplateContextUtil.createMultiLoanNoticeContext (org.folio.circulation.domain.notice.TemplateContextUtil.createMultiLoanNoticeContext)1 ScheduledNoticeContext (org.folio.circulation.domain.notice.schedule.ScheduledNoticeHandler.ScheduledNoticeContext)1 NoticeLogContext (org.folio.circulation.domain.representations.logs.NoticeLogContext)1 NoticeLogContextItem (org.folio.circulation.domain.representations.logs.NoticeLogContextItem)1 LoanRepository (org.folio.circulation.infrastructure.storage.loans.LoanRepository)1