Search in sources :

Example 1 with LoanPolicyBuilder

use of api.support.builders.LoanPolicyBuilder in project mod-circulation by folio-org.

the class OverrideRenewalTest method shouldUseOverrideDateWhenLoanIsNotLoanable.

@Test
void shouldUseOverrideDateWhenLoanIsNotLoanable() {
    final ZonedDateTime overrideDate = ClockUtil.getZonedDateTime().plusMonths(1);
    final JsonObject loanPolicyJson = new LoanPolicyBuilder().withLoanable(false).create();
    final Result<Loan> renewedLoan = renew(LoanPolicy.from(loanPolicyJson), overrideDate);
    assertDueDate(overrideDate, renewedLoan);
    assertEquals(CHECKED_OUT, renewedLoan.value().getItem().getStatus());
}
Also used : Loan(org.folio.circulation.domain.Loan) ZonedDateTime(java.time.ZonedDateTime) JsonObject(io.vertx.core.json.JsonObject) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) Test(org.junit.jupiter.api.Test)

Example 2 with LoanPolicyBuilder

use of api.support.builders.LoanPolicyBuilder in project mod-circulation by folio-org.

the class OverrideRenewalTest method nonLoanableAgedToLostItemShouldBeProperlyRenewed.

@Test
void nonLoanableAgedToLostItemShouldBeProperlyRenewed() {
    final ZonedDateTime newDueDate = ClockUtil.getZonedDateTime().plusWeeks(1);
    final ZonedDateTime ageToLostDate = ClockUtil.getZonedDateTime();
    final LoanPolicy loanPolicy = LoanPolicy.from(new LoanPolicyBuilder().withLoanable(false).create());
    final Loan loan = Loan.from(new JsonObject()).withItem(createCheckedOutItem()).withLoanPolicy(loanPolicy);
    loan.ageOverdueItemToLost(ageToLostDate).setAgedToLostDelayedBilling(false, ageToLostDate.plusDays(1));
    final Result<Loan> renewedLoan = renew(loan, newDueDate);
    assertDueDate(newDueDate, renewedLoan);
    assertEquals(CHECKED_OUT, renewedLoan.value().getItem().getStatus());
    assertThat(renewedLoan.value().asJson(), allOf(hasNoJsonPath("agedToLostDelayedBilling.lostItemHasBeenBilled"), hasNoJsonPath("agedToLostDelayedBilling.dateLostItemShouldBeBilled")));
}
Also used : Loan(org.folio.circulation.domain.Loan) ZonedDateTime(java.time.ZonedDateTime) LoanPolicy(org.folio.circulation.domain.policy.LoanPolicy) JsonObject(io.vertx.core.json.JsonObject) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) Test(org.junit.jupiter.api.Test)

Example 3 with LoanPolicyBuilder

use of api.support.builders.LoanPolicyBuilder in project mod-circulation by folio-org.

the class OverrideRenewalTest method overrideDateIsRequiredWhenLoanIsNotLoanable.

@Test
void overrideDateIsRequiredWhenLoanIsNotLoanable() {
    final JsonObject loanPolicyJson = new LoanPolicyBuilder().withLoanable(false).create();
    final Result<Loan> renewedLoan = renew(LoanPolicy.from(loanPolicyJson), null);
    assertThat(renewedLoan, hasValidationError(hasMessage(OVERRIDE_DUE_DATE_MUST_BE_SPECIFIED_ERROR)));
}
Also used : Loan(org.folio.circulation.domain.Loan) JsonObject(io.vertx.core.json.JsonObject) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) Test(org.junit.jupiter.api.Test)

Example 4 with LoanPolicyBuilder

use of api.support.builders.LoanPolicyBuilder in project mod-circulation by folio-org.

the class RegularRenewalTest method cannotRenewWhenHoldRequestedAndFixedPolicyHasAlternativeRenewPeriod.

@Test
void cannotRenewWhenHoldRequestedAndFixedPolicyHasAlternativeRenewPeriod() {
    final var request = new RequestBuilder().hold().asDomainObject();
    final var loanPolicy = new LoanPolicyBuilder().fixed(UUID.randomUUID()).withHolds(null, true, days(1)).asDomainObject();
    CirculationErrorHandler errorHandler = new OverridingErrorHandler(null);
    renew(loanPolicy, request, errorHandler);
    assertTrue(matchErrorReason(errorHandler, ALTERNATIVE_RENEWAL_PERIOD_FOR_HOLDS_IS_SPECIFIED));
}
Also used : RequestBuilder(api.support.builders.RequestBuilder) CirculationErrorHandler(org.folio.circulation.resources.handlers.error.CirculationErrorHandler) OverridingErrorHandler(org.folio.circulation.resources.handlers.error.OverridingErrorHandler) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 5 with LoanPolicyBuilder

use of api.support.builders.LoanPolicyBuilder in project mod-circulation by folio-org.

the class RegularRenewalTest method cannotRenewWhenHoldRequestedAndFixedPolicyHasRenewPeriod.

@Test
void cannotRenewWhenHoldRequestedAndFixedPolicyHasRenewPeriod() {
    final var request = new RequestBuilder().hold().asDomainObject();
    final var loanPolicy = new LoanPolicyBuilder().fixed(UUID.randomUUID()).renewWith(days(10)).withHolds(null, true, null).asDomainObject();
    CirculationErrorHandler errorHandler = new OverridingErrorHandler(null);
    renew(loanPolicy, request, errorHandler);
    assertTrue(matchErrorReason(errorHandler, POLICY_HAS_FIXED_PROFILE_BUT_RENEWAL_PERIOD_IS_SPECIFIED));
}
Also used : RequestBuilder(api.support.builders.RequestBuilder) CirculationErrorHandler(org.folio.circulation.resources.handlers.error.CirculationErrorHandler) OverridingErrorHandler(org.folio.circulation.resources.handlers.error.OverridingErrorHandler) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

LoanPolicyBuilder (api.support.builders.LoanPolicyBuilder)199 Test (org.junit.jupiter.api.Test)173 ZonedDateTime (java.time.ZonedDateTime)135 IndividualResource (api.support.http.IndividualResource)97 JsonObject (io.vertx.core.json.JsonObject)87 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)79 Loan (org.folio.circulation.domain.Loan)70 FixedDueDateSchedulesBuilder (api.support.builders.FixedDueDateSchedulesBuilder)64 UUID (java.util.UUID)63 ClockUtil.getZonedDateTime (org.folio.circulation.support.utils.ClockUtil.getZonedDateTime)57 OverridingErrorHandler (org.folio.circulation.resources.handlers.error.OverridingErrorHandler)50 CirculationErrorHandler (org.folio.circulation.resources.handlers.error.CirculationErrorHandler)39 RequestQueue (org.folio.circulation.domain.RequestQueue)37 RequestBuilder (api.support.builders.RequestBuilder)34 Response (org.folio.circulation.support.http.client.Response)32 ItemResource (api.support.http.ItemResource)25 CheckOutByBarcodeRequestBuilder (api.support.builders.CheckOutByBarcodeRequestBuilder)23 LoanBuilder (api.support.builders.LoanBuilder)18 FixedDueDateSchedule (api.support.builders.FixedDueDateSchedule)16 NoticePolicyBuilder (api.support.builders.NoticePolicyBuilder)16