Search in sources :

Example 96 with LoanPolicyBuilder

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

the class LoanDueDatesAfterRecallTests method secondRecallRequestWithMGDTruncationInPlaceDoesNotChangeDueDate.

@Test
void secondRecallRequestWithMGDTruncationInPlaceDoesNotChangeDueDate() {
    final IndividualResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet();
    final IndividualResource requestServicePoint = servicePointsFixture.cd1();
    final IndividualResource steve = usersFixture.steve();
    final IndividualResource jessica = usersFixture.jessica();
    final IndividualResource charlotte = usersFixture.charlotte();
    final LoanPolicyBuilder canCirculateRollingPolicy = new LoanPolicyBuilder().withName("Can Circulate Rolling With Recalls").withDescription("Can circulate item With Recalls").rolling(Period.weeks(3)).unlimitedRenewals().renewFromSystemDate().withRecallsMinimumGuaranteedLoanPeriod(Period.weeks(2)).withRecallsRecallReturnInterval(Period.weeks(1));
    setFallbackPolicies(canCirculateRollingPolicy);
    final IndividualResource loan = checkOutFixture.checkOutByBarcode(smallAngryPlanet, steve, getZonedDateTime());
    final String originalDueDate = loan.getJson().getString("dueDate");
    requestsFixture.placeItemLevelHoldShelfRequest(smallAngryPlanet, jessica, getZonedDateTime(), requestServicePoint.getId(), "Recall");
    JsonObject storedLoan = loansStorageClient.getById(loan.getId()).getJson();
    final String recalledDueDate = storedLoan.getString("dueDate");
    assertThat("due date after recall should not be the original date", recalledDueDate, not(originalDueDate));
    final String expectedDueDate = formatDateTime(getZonedDateTime().plusWeeks(2));
    assertThat("due date after recall should be in 2 weeks", storedLoan.getString("dueDate"), is(expectedDueDate));
    setClock(Clock.offset(getClock(), Duration.ofDays(7)));
    requestsFixture.placeItemLevelHoldShelfRequest(smallAngryPlanet, charlotte, getZonedDateTime(), requestServicePoint.getId(), "Recall");
    storedLoan = loansStorageClient.getById(loan.getId()).getJson();
    assertThat("second recall should not change the due date (2 weeks)", storedLoan.getString("dueDate"), is(recalledDueDate));
}
Also used : JsonObject(io.vertx.core.json.JsonObject) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) IndividualResource(api.support.http.IndividualResource) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 97 with LoanPolicyBuilder

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

the class LoanDueDatesAfterRecallTests method initialLoanDueDateOnCreateWithPrexistingRequests.

@Test
void initialLoanDueDateOnCreateWithPrexistingRequests() {
    final IndividualResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet();
    final IndividualResource requestServicePoint = servicePointsFixture.cd1();
    final IndividualResource steve = usersFixture.steve();
    final IndividualResource jessica = usersFixture.jessica();
    final IndividualResource charlotte = usersFixture.charlotte();
    final LoanPolicyBuilder canCirculateRollingPolicy = new LoanPolicyBuilder().withName("Can Circulate Rolling With Recalls").withDescription("Can circulate item With Recalls").rolling(Period.weeks(3)).unlimitedRenewals().renewFromSystemDate().withClosedLibraryDueDateManagement(KEEP_THE_CURRENT_DUE_DATE.getValue()).withRecallsMinimumGuaranteedLoanPeriod(Period.weeks(2)).withRecallsRecallReturnInterval(Period.months(2));
    setFallbackPolicies(canCirculateRollingPolicy);
    checkOutFixture.checkOutByBarcode(smallAngryPlanet, charlotte, getZonedDateTime());
    requestsFixture.placeItemLevelHoldShelfRequest(smallAngryPlanet, steve, getZonedDateTime(), requestServicePoint.getId(), "Recall");
    requestsFixture.placeItemLevelHoldShelfRequest(smallAngryPlanet, jessica, getZonedDateTime(), requestServicePoint.getId(), "Recall");
    checkInFixture.checkInByBarcode(smallAngryPlanet);
    final IndividualResource loan = checkOutFixture.checkOutByBarcode(smallAngryPlanet, steve, getZonedDateTime());
    final JsonObject storedLoan = loansStorageClient.getById(loan.getId()).getJson();
    final String expectedDueDate = formatDateTime(ZonedDateTime.of(getZonedDateTime().plusMonths(2).toLocalDate(), LocalTime.MIDNIGHT.minusSeconds(1), getZoneId()));
    assertThat("due date should be in 2 months (recall return interval)", storedLoan.getString("dueDate"), is(expectedDueDate));
}
Also used : JsonObject(io.vertx.core.json.JsonObject) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) IndividualResource(api.support.http.IndividualResource) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 98 with LoanPolicyBuilder

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

the class LoanDueDatesAfterRecallTests method pagedItemRecalledThenLoanedAndNextRecallDoesNotChangeDueDate.

@Test
void pagedItemRecalledThenLoanedAndNextRecallDoesNotChangeDueDate() {
    final IndividualResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet();
    final IndividualResource requestServicePoint = servicePointsFixture.cd1();
    final IndividualResource jessica = usersFixture.jessica();
    final IndividualResource charlotte = usersFixture.charlotte();
    final IndividualResource james = usersFixture.james();
    final LoanPolicyBuilder canCirculateRollingPolicy = new LoanPolicyBuilder().withName("Can Circulate Rolling With Recalls").withDescription("Can circulate item With Recalls").rolling(Period.weeks(3)).unlimitedRenewals().renewFromSystemDate().withRecallsMinimumGuaranteedLoanPeriod(Period.weeks(2)).withRecallsRecallReturnInterval(Period.weeks(1));
    setFallbackPolicies(canCirculateRollingPolicy);
    requestsFixture.placeItemLevelHoldShelfRequest(smallAngryPlanet, jessica, getZonedDateTime(), requestServicePoint.getId(), "Page");
    requestsFixture.placeItemLevelHoldShelfRequest(smallAngryPlanet, james, getZonedDateTime(), requestServicePoint.getId(), "Recall");
    final IndividualResource loan = checkOutFixture.checkOutByBarcode(smallAngryPlanet, jessica, getZonedDateTime());
    // Recalled is applied when loaned, so the due date should be 2 weeks, not 3 weeks
    final String expectedDueDate = formatDateTime(getZonedDateTime().plusWeeks(2));
    JsonObject storedLoan = loansStorageClient.getById(loan.getId()).getJson();
    final String recalledDueDate = storedLoan.getString("dueDate");
    assertThat("due date after recall should be 2 weeks", recalledDueDate, is(expectedDueDate));
    setClock(Clock.offset(getClock(), Duration.ofDays(1)));
    requestsFixture.placeItemLevelHoldShelfRequest(smallAngryPlanet, charlotte, getZonedDateTime(), requestServicePoint.getId(), "Recall");
    storedLoan = loansStorageClient.getById(loan.getId()).getJson();
    assertThat("second recall should not change the due date", storedLoan.getString("dueDate"), is(recalledDueDate));
}
Also used : JsonObject(io.vertx.core.json.JsonObject) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) IndividualResource(api.support.http.IndividualResource) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 99 with LoanPolicyBuilder

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

the class LoanDueDatesAfterRecallTests method recallRequestWithMGDAndRDValuesChangesDueDateToMGD.

@Test
void recallRequestWithMGDAndRDValuesChangesDueDateToMGD() {
    final IndividualResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet();
    final IndividualResource requestServicePoint = servicePointsFixture.cd1();
    final IndividualResource steve = usersFixture.steve();
    final IndividualResource jessica = usersFixture.jessica();
    final LoanPolicyBuilder canCirculateRollingPolicy = new LoanPolicyBuilder().withName("Can Circulate Rolling With Recalls").withDescription("Can circulate item With Recalls").rolling(Period.weeks(3)).unlimitedRenewals().renewFromSystemDate().withRecallsMinimumGuaranteedLoanPeriod(Period.weeks(2)).withRecallsRecallReturnInterval(Period.weeks(1));
    setFallbackPolicies(canCirculateRollingPolicy);
    // We use the loan date to calculate the MGD
    final ZonedDateTime loanDate = getZonedDateTime();
    final IndividualResource loan = checkOutFixture.checkOutByBarcode(smallAngryPlanet, steve, loanDate);
    final String originalDueDate = loan.getJson().getString("dueDate");
    requestsFixture.placeItemLevelHoldShelfRequest(smallAngryPlanet, jessica, getZonedDateTime(), requestServicePoint.getId(), "Recall");
    final JsonObject storedLoan = loansStorageClient.getById(loan.getId()).getJson();
    assertThat("due date should not be the original due date", storedLoan.getString("dueDate"), not(originalDueDate));
    final String expectedDueDate = formatDateTime(loanDate.plusWeeks(2));
    assertThat("due date should be in 2 weeks (minumum guaranteed loan period)", storedLoan.getString("dueDate"), is(expectedDueDate));
}
Also used : ZonedDateTime(java.time.ZonedDateTime) ClockUtil.getZonedDateTime(org.folio.circulation.support.utils.ClockUtil.getZonedDateTime) JsonObject(io.vertx.core.json.JsonObject) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) IndividualResource(api.support.http.IndividualResource) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 100 with LoanPolicyBuilder

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

the class LoanDueDatesAfterRecallTests method secondRecallRequestWithRDTruncationInPlaceAndLoanOverdueDoesNotChangeDueDate.

@Test
void secondRecallRequestWithRDTruncationInPlaceAndLoanOverdueDoesNotChangeDueDate() {
    final IndividualResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet();
    final IndividualResource requestServicePoint = servicePointsFixture.cd1();
    final IndividualResource steve = usersFixture.steve();
    final IndividualResource jessica = usersFixture.jessica();
    final IndividualResource charlotte = usersFixture.charlotte();
    final LoanPolicyBuilder canCirculateRollingPolicy = new LoanPolicyBuilder().withName("Can Circulate Rolling With Recalls").withDescription("Can circulate item With Recalls").rolling(Period.weeks(3)).unlimitedRenewals().renewFromSystemDate().withRecallsMinimumGuaranteedLoanPeriod(Period.weeks(2)).withRecallsRecallReturnInterval(Period.months(2));
    setFallbackPolicies(canCirculateRollingPolicy);
    final IndividualResource loan = checkOutFixture.checkOutByBarcode(smallAngryPlanet, steve, getZonedDateTime());
    final String originalDueDate = loan.getJson().getString("dueDate");
    requestsFixture.placeItemLevelHoldShelfRequest(smallAngryPlanet, jessica, getZonedDateTime(), requestServicePoint.getId(), "Recall");
    JsonObject storedLoan = loansStorageClient.getById(loan.getId()).getJson();
    final String recalledDueDate = storedLoan.getString("dueDate");
    assertThat("due date after recall should not be the original date", recalledDueDate, not(originalDueDate));
    final String expectedDueDate = formatDateTime(getZonedDateTime().plusMonths(2));
    assertThat("due date after recall should be in 2 months", storedLoan.getString("dueDate"), is(expectedDueDate));
    // Move the fixed clock so that the loan is now overdue
    setClock(Clock.offset(getClock(), Duration.ofDays(70)));
    requestsFixture.placeItemLevelHoldShelfRequest(smallAngryPlanet, charlotte, getZonedDateTime(), requestServicePoint.getId(), "Recall");
    storedLoan = loansStorageClient.getById(loan.getId()).getJson();
    assertThat("second recall should not change the due date (2 months)", storedLoan.getString("dueDate"), is(recalledDueDate));
}
Also used : JsonObject(io.vertx.core.json.JsonObject) LoanPolicyBuilder(api.support.builders.LoanPolicyBuilder) IndividualResource(api.support.http.IndividualResource) 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