Search in sources :

Example 21 with LoanBuilder

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

the class LoanAPITests method canCreateALoanWithSystemReturnDate.

@Test
void canCreateALoanWithSystemReturnDate() {
    UUID id = UUID.randomUUID();
    UUID itemId = itemsFixture.basedUponSmallAngryPlanet().getId();
    UUID userId = usersFixture.charlotte().getId();
    ZonedDateTime loanDate = ZonedDateTime.of(2017, 2, 27, 10, 23, 43, 0, UTC);
    ZonedDateTime dueDate = ZonedDateTime.of(2017, 3, 29, 10, 23, 43, 0, UTC);
    ZonedDateTime systemReturnDate = ZonedDateTime.of(2017, 4, 1, 12, 0, 0, 0, UTC);
    IndividualResource response = loansFixture.createLoan(new LoanBuilder().closed().withId(id).withUserId(userId).withItemId(itemId).withLoanDate(loanDate).withDueDate(dueDate).withSystemReturnDate(systemReturnDate));
    JsonObject loan = response.getJson();
    assertThat("systemReturnDate does not match", loan.getString("systemReturnDate"), isEquivalentTo(systemReturnDate));
}
Also used : LoanBuilder(api.support.builders.LoanBuilder) ZonedDateTime(java.time.ZonedDateTime) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) IndividualResource(api.support.http.IndividualResource) Test(org.junit.jupiter.api.Test)

Example 22 with LoanBuilder

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

the class LoanAPITests method cannotUpdateAnOpenLoanWithoutAUserId.

@Test
void cannotUpdateAnOpenLoanWithoutAUserId() {
    UUID itemId = itemsFixture.basedUponNod().getId();
    final IndividualResource jessica = usersFixture.jessica();
    IndividualResource loan = loansFixture.createLoan(new LoanBuilder().open().withUserId(jessica.getId()).withItemId(itemId));
    JsonObject updatedLoan = loan.copyJson();
    updatedLoan.remove("userId");
    Response putResponse = loansFixture.attemptToReplaceLoan(loan.getId(), updatedLoan);
    assertThat(putResponse.getJson(), hasErrorWith(allOf(hasMessage("Open loan must have a user ID"), hasNullParameter("userId"))));
}
Also used : Response(org.folio.circulation.support.http.client.Response) LoanBuilder(api.support.builders.LoanBuilder) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) IndividualResource(api.support.http.IndividualResource) Test(org.junit.jupiter.api.Test)

Example 23 with LoanBuilder

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

the class LoanLostDateTest method lostDateIsNotNullWhenBothLostDatesAreEqual.

@Test
void lostDateIsNotNullWhenBothLostDatesAreEqual() {
    final var lostDate = ClockUtil.getZonedDateTime();
    final var loan = new LoanBuilder().asDomainObject().ageOverdueItemToLost(lostDate).declareItemLost("Lost", lostDate);
    assertTrue(isSameMillis(lostDate, loan.getLostDate()));
}
Also used : LoanBuilder(api.support.builders.LoanBuilder) Test(org.junit.jupiter.api.Test)

Example 24 with LoanBuilder

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

the class OverduePeriodCalculatorServiceTest method countOverdueMinutesWithClosedDays.

@Test
void countOverdueMinutesWithClosedDays() throws ExecutionException, InterruptedException {
    final int expectedResult = 60 * 24 * 7 + 1;
    final ZonedDateTime systemTime = getZonedDateTime();
    Loan loan = new LoanBuilder().withDueDate(systemTime.minusMinutes(expectedResult)).asDomainObject();
    int actualResult = calculator.getOverdueMinutes(loan, systemTime, true).get().value();
    assertEquals(expectedResult, actualResult);
}
Also used : LoanBuilder(api.support.builders.LoanBuilder) ClockUtil.getZonedDateTime(org.folio.circulation.support.utils.ClockUtil.getZonedDateTime) ZonedDateTime(java.time.ZonedDateTime) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Example 25 with LoanBuilder

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

the class OverduePeriodCalculatorServiceTest method preconditionsCheckLoanHasNoDueDate.

@Test
void preconditionsCheckLoanHasNoDueDate() {
    ZonedDateTime systemTime = ClockUtil.getZonedDateTime();
    Loan loan = new LoanBuilder().asDomainObject();
    assertFalse(calculator.preconditionsAreMet(loan, systemTime, true));
}
Also used : LoanBuilder(api.support.builders.LoanBuilder) ClockUtil.getZonedDateTime(org.folio.circulation.support.utils.ClockUtil.getZonedDateTime) ZonedDateTime(java.time.ZonedDateTime) Test(org.junit.jupiter.api.Test) ParameterizedTest(org.junit.jupiter.params.ParameterizedTest)

Aggregations

LoanBuilder (api.support.builders.LoanBuilder)70 Test (org.junit.jupiter.api.Test)68 ZonedDateTime (java.time.ZonedDateTime)49 UUID (java.util.UUID)43 IndividualResource (api.support.http.IndividualResource)30 JsonObject (io.vertx.core.json.JsonObject)30 Response (org.folio.circulation.support.http.client.Response)24 LoanPolicyBuilder (api.support.builders.LoanPolicyBuilder)18 OverridingErrorHandler (org.folio.circulation.resources.handlers.error.OverridingErrorHandler)14 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)14 Loan (org.folio.circulation.domain.Loan)13 CirculationErrorHandler (org.folio.circulation.resources.handlers.error.CirculationErrorHandler)12 RequestQueue (org.folio.circulation.domain.RequestQueue)11 ClockUtil.getZonedDateTime (org.folio.circulation.support.utils.ClockUtil.getZonedDateTime)8 MultipleJsonRecords (api.support.MultipleJsonRecords)7 FixedDueDateSchedulesBuilder (api.support.builders.FixedDueDateSchedulesBuilder)7 lombok.val (lombok.val)7 UTC (java.time.ZoneOffset.UTC)6 MatcherAssert.assertThat (org.hamcrest.MatcherAssert.assertThat)6 AccountBuilder (api.support.builders.AccountBuilder)4