Search in sources :

Example 11 with LoanBuilder

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

the class LoanAPITests method cannotCreateALoanWithUnknownCheckInServicePointId.

@Test
void cannotCreateALoanWithUnknownCheckInServicePointId() {
    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);
    final UUID unknownServicePointId = UUID.randomUUID();
    final Response response = loansFixture.attemptToCreateLoan(new LoanBuilder().withId(id).withCheckinServicePointId(unknownServicePointId).closed().withUserId(userId).withItemId(itemId).withLoanDate(loanDate).withDueDate(dueDate), UNPROCESSABLE_ENTITY);
    assertThat(response.getJson(), hasErrorWith(allOf(hasMessage("Check In Service Point does not exist"), hasUUIDParameter("checkinServicePointId", unknownServicePointId))));
}
Also used : Response(org.folio.circulation.support.http.client.Response) LoanBuilder(api.support.builders.LoanBuilder) ZonedDateTime(java.time.ZonedDateTime) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 12 with LoanBuilder

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

the class LoanAPITests method cannotCreateOpenLoanAtSpecificLocationWithoutUserId.

@Test
void cannotCreateOpenLoanAtSpecificLocationWithoutUserId() {
    UUID loanId = UUID.randomUUID();
    final UUID itemId = itemsFixture.basedUponSmallAngryPlanet().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);
    val loanBuilder = new LoanBuilder().withId(loanId).withNoUserId().withItemId(itemId).withLoanDate(loanDate).withDueDate(dueDate).open();
    // Prepare loan
    UUID userId = usersFixture.charlotte().getId();
    loansFixture.createLoan(loanBuilder.withUserId(userId));
    Response response = loansFixture.attemptToCreateLoanAtSpecificLocation(loanId, loanBuilder);
    assertThat(response.getJson(), hasErrorWith(allOf(hasMessage("Open loan must have a user ID"), hasNullParameter("userId"))));
}
Also used : lombok.val(lombok.val) Response(org.folio.circulation.support.http.client.Response) LoanBuilder(api.support.builders.LoanBuilder) ZonedDateTime(java.time.ZonedDateTime) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 13 with LoanBuilder

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

the class LoanAPITests method canCreateMultipleLoansWithServicePoints.

@Test
void canCreateMultipleLoansWithServicePoints() {
    ZonedDateTime loanDate = ZonedDateTime.of(2017, 2, 27, 10, 23, 43, 0, UTC);
    ZonedDateTime dueDate = ZonedDateTime.of(2017, 3, 29, 10, 23, 43, 0, UTC);
    UUID checkinServicePointId = servicePointsFixture.cd1().getId();
    UUID checkoutServicePointId = servicePointsFixture.cd2().getId();
    UUID userId = usersFixture.charlotte().getId();
    UUID loan1Id = UUID.randomUUID();
    UUID item1Id = itemsFixture.basedUponDunkirk().getId();
    UUID loan2Id = UUID.randomUUID();
    UUID item2Id = itemsFixture.basedUponSmallAngryPlanet().getId();
    UUID loan3Id = UUID.randomUUID();
    UUID item3Id = itemsFixture.basedUponUprooted().getId();
    loansFixture.createLoan(new LoanBuilder().withId(loan1Id).open().withUserId(userId).withItemId(item1Id).withLoanDate(loanDate).withDueDate(dueDate).withCheckinServicePointId(checkinServicePointId).withCheckoutServicePointId(checkoutServicePointId));
    loansFixture.createLoan(new LoanBuilder().withId(loan2Id).open().withUserId(userId).withItemId(item2Id).withLoanDate(loanDate).withDueDate(dueDate).withCheckinServicePointId(checkinServicePointId).withCheckoutServicePointId(checkoutServicePointId));
    loansFixture.createLoan(new LoanBuilder().withId(loan3Id).open().withUserId(userId).withItemId(item3Id).withLoanDate(loanDate).withDueDate(dueDate).withCheckinServicePointId(checkinServicePointId).withCheckoutServicePointId(checkoutServicePointId));
    MultipleJsonRecords loanList = loansFixture.getAllLoans();
    loanList.forEach(loanJson -> {
        loanHasCheckinServicePointProperties(loanJson);
        loanHasCheckoutServicePointProperties(loanJson);
    });
}
Also used : MultipleJsonRecords(api.support.MultipleJsonRecords) LoanBuilder(api.support.builders.LoanBuilder) ZonedDateTime(java.time.ZonedDateTime) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 14 with LoanBuilder

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

the class LoanAPITests method canGetMultipleLoansWithoutUserId.

@Test
void canGetMultipleLoansWithoutUserId() {
    UUID smallAngryPlanetId = itemsFixture.basedUponSmallAngryPlanet().getId();
    UUID nodId = itemsFixture.basedUponNod().getId();
    UUID checkinServicePointId = servicePointsFixture.cd1().getId();
    UUID checkinServicePointId2 = servicePointsFixture.cd2().getId();
    LoanBuilder smallAngryPlanetLoanBuilder = new LoanBuilder().withItemId(smallAngryPlanetId).withCheckinServicePointId(checkinServicePointId).closed().withNoUserId();
    UUID userId = usersFixture.charlotte().getId();
    loansFixture.createLoan(smallAngryPlanetLoanBuilder.withUserId(userId));
    loansClient.createAtSpecificLocation(smallAngryPlanetLoanBuilder);
    LoanBuilder nodLoanBuilder = new LoanBuilder().withItemId(nodId).closed().withCheckinServicePointId(checkinServicePointId2).withNoUserId();
    loansFixture.createLoan(nodLoanBuilder.withUserId(userId));
    loansClient.createAtSpecificLocation(nodLoanBuilder);
    final MultipleJsonRecords multipleLoans = loansFixture.getAllLoans();
    assertThat("Should have two loans", multipleLoans.size(), is(2));
    multipleLoans.forEach(this::hasNoBorrowerProperties);
}
Also used : MultipleJsonRecords(api.support.MultipleJsonRecords) LoanBuilder(api.support.builders.LoanBuilder) UUID(java.util.UUID) Test(org.junit.jupiter.api.Test)

Example 15 with LoanBuilder

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

the class LoanAPITests method canCreateALoan.

@Test
void canCreateALoan() {
    UUID id = UUID.randomUUID();
    IndividualResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet(item -> item.withEnumeration("v.70:no.1-6").withChronology("1987:Jan.-June").withVolume("testVolume"));
    UUID itemId = smallAngryPlanet.getId();
    val user = usersFixture.charlotte();
    UUID userId = user.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);
    IndividualResource response = loansFixture.createLoan(new LoanBuilder().withId(id).open().withUserId(userId).withItemId(itemId).withLoanDate(loanDate).withDueDate(dueDate));
    JsonObject loan = response.getJson();
    assertThat("id does not match", loan.getString("id"), is(id.toString()));
    assertThat("user id does not match", loan.getString("userId"), is(userId.toString()));
    assertThat("item id does not match", loan.getString("itemId"), is(itemId.toString()));
    assertThat("loan date does not match", loan.getString("loanDate"), is("2017-02-27T10:23:43.000Z"));
    assertThat("status is not open", loan.getJsonObject("status").getString("name"), is("Open"));
    assertThat("action is not checkedout", loan.getString("action"), is("checkedout"));
    loanHasLoanPolicyProperties(loan, loanPoliciesFixture.canCirculateRolling());
    assertThat("ID is taken from item", loan.getJsonObject("item").getString("id"), is(itemId));
    assertThat("title is taken from instance", loan.getJsonObject("item").getString("title"), is("The Long Way to a Small, Angry Planet"));
    assertThat("barcode is taken from item", loan.getJsonObject("item").getString("barcode"), is("036000291452"));
    assertThat("call number is 123456", loan.getJsonObject("item").getString("callNumber"), is("123456"));
    assertThat(loan.getJsonObject("item").encode() + " contains 'materialType'", loan.getJsonObject("item").containsKey("materialType"), is(true));
    assertThat("materialType is book", loan.getJsonObject("item").getJsonObject("materialType").getString("name"), is("Book"));
    assertThat("item has contributors", loan.getJsonObject("item").containsKey("contributors"), is(true));
    assertThat("has item enumeration", loan.getJsonObject("item").getString("enumeration"), is("v.70:no.1-6"));
    assertThat("has item chronology", loan.getJsonObject("item").getString("chronology"), is("1987:Jan.-June"));
    assertThat("has item volume", loan.getJsonObject("item").getString("volume"), is("testVolume"));
    JsonArray contributors = loan.getJsonObject("item").getJsonArray("contributors");
    assertThat("item has a single contributor", contributors.size(), is(1));
    assertThat("Becky Chambers is a contributor", contributors.getJsonObject(0).getString("name"), is("Chambers, Becky"));
    assertThat("has item status", loan.getJsonObject("item").containsKey("status"), is(true));
    assertThat("status is taken from item", loan.getJsonObject("item").getJsonObject("status").getString("name"), is("Checked out"));
    assertThat("Should not have snapshot of item status, as current status is included", loan.containsKey("itemStatus"), is(false));
    assertThat("should have change metadata", loan.containsKey("metadata"), is(true));
    JsonObject changeMetadata = loan.getJsonObject("metadata");
    assertThat("change metadata should have created date", changeMetadata.containsKey("createdDate"), is(true));
    assertThat("change metadata should have updated date", changeMetadata.containsKey("updatedDate"), is(true));
    assertThat("due date does not match", loan.getString("dueDate"), isEquivalentTo(dueDate));
    JsonObject item = itemsClient.getById(itemId).getJson();
    assertThat("item status is not checked out", item.getJsonObject("status").getString("name"), is("Checked out"));
    assertThat("item status snapshot in storage is not checked out", loansStorageClient.getById(id).getJson().getString("itemStatus"), is("Checked out"));
    assertThat("has item enumeration", item.getString("enumeration"), is("v.70:no.1-6"));
    assertThat("has item chronology", item.getString("chronology"), is("1987:Jan.-June"));
    assertThat("has item volume", item.getString("volume"), is("testVolume"));
    loanHasExpectedProperties(loan, user);
}
Also used : lombok.val(lombok.val) JsonArray(io.vertx.core.json.JsonArray) 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)

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