Search in sources :

Example 16 with LoanBuilder

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

the class LoanAPITests method canCreateClosedLoanInSpecificLocationWithoutUserId.

@Test
void canCreateClosedLoanInSpecificLocationWithoutUserId() {
    UUID loanId = UUID.randomUUID();
    UUID checkinServicePointId = servicePointsFixture.cd1().getId();
    UUID itemId = itemsFixture.basedUponSmallAngryPlanet().getId();
    LoanBuilder loanBuilder = new LoanBuilder().withId(loanId).withItemId(itemId).withCheckinServicePointId(checkinServicePointId).closed().withNoUserId();
    UUID userId = usersFixture.charlotte().getId();
    loansFixture.createLoan(loanBuilder.withUserId(userId));
    loansFixture.createLoanAtSpecificLocation(loanId, loanBuilder);
    final IndividualResource item = itemsClient.get(itemId);
    assertThat("Item status should be available", item.getJson().getJsonObject("status").getString("name"), is("Available"));
}
Also used : LoanBuilder(api.support.builders.LoanBuilder) UUID(java.util.UUID) IndividualResource(api.support.http.IndividualResource) Test(org.junit.jupiter.api.Test)

Example 17 with LoanBuilder

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

the class LoanAPITests method canCreateALoanWithoutStatus.

@Test
void canCreateALoanWithoutStatus() {
    UUID id = UUID.randomUUID();
    IndividualResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet(builder -> builder.withEnumeration("v.70:no.1-6").withChronology("1987:Jan.-June").withVolume("testVolume"));
    UUID itemId = smallAngryPlanet.getId();
    UUID userId = usersFixture.charlotte().getId();
    IndividualResource response = loansFixture.createLoan(new LoanBuilder().withId(id).withUserId(userId).withItemId(itemId).withNoStatus());
    JsonObject loan = response.getJson();
    assertThat("status is not open", loan.getJsonObject("status").getString("name"), is("Open"));
    assertThat("action is not checkedout", loan.getString("action"), is("checkedout"));
    loanHasLoanPolicyProperties(response.getJson(), loanPoliciesFixture.canCirculateRolling());
    assertThat("title is taken from item", loan.getJsonObject("item").containsKey("title"), is(true));
    assertThat("barcode is taken from item", loan.getJsonObject("item").containsKey("barcode"), is(true));
    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("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"));
    JsonObject item = itemsClient.getById(itemId).getJson();
    assertThat("item status is not checked out", item.getJsonObject("status").getString("name"), 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"));
    assertThat("item status snapshot in storage is not checked out", loansStorageClient.getById(id).getJson().getString("itemStatus"), is("Checked out"));
}
Also used : 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 18 with LoanBuilder

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

the class LoanAPITests method canCreateALoanAtASpecificLocation.

@Test
void canCreateALoanAtASpecificLocation() {
    UUID id = UUID.randomUUID();
    IndividualResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet(builder -> builder.withEnumeration("v.70:no.1-6").withChronology("1987:Jan.-June").withVolume("testVolume"));
    UUID itemId = smallAngryPlanet.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);
    val loanBuilder = new LoanBuilder().withId(id).open().withUserId(userId).withItemId(itemId).withLoanDate(loanDate).withDueDate(dueDate);
    // Prepare loan
    loansFixture.createLoan(loanBuilder.withUserId(userId));
    IndividualResource response = loansClient.createAtSpecificLocation(loanBuilder);
    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"));
    // TODO: Loan Policy should be stored - maybe only works for renewal, possible bug?
    // assertThat("last loan policy should be stored",
    // loan.getString("loanPolicyId"), is(APITestSuite.canCirculateRollingLoanPolicyId().toString()));
    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));
    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("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"));
    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"));
}
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)

Example 19 with LoanBuilder

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

the class LoanAPITests method canGetLoanWithoutOpenFeesFines.

@Test
void canGetLoanWithoutOpenFeesFines() {
    UUID id = UUID.randomUUID();
    UUID itemId = itemsFixture.basedUponSmallAngryPlanet().getId();
    IndividualResource 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));
    accountsClient.create(new AccountBuilder().feeFineStatusOpen().withLoan(response).feeFineStatusClosed().withRemainingFeeFine(150));
    JsonObject loan = loansFixture.getLoanById(id).getJson();
    assertLoanHasFeeFinesProperties(loan, 0);
}
Also used : LoanBuilder(api.support.builders.LoanBuilder) ZonedDateTime(java.time.ZonedDateTime) JsonObject(io.vertx.core.json.JsonObject) AccountBuilder(api.support.builders.AccountBuilder) UUID(java.util.UUID) IndividualResource(api.support.http.IndividualResource) Test(org.junit.jupiter.api.Test)

Example 20 with LoanBuilder

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

the class LoanAPITests method dueDateChangedEventIsPublishedOnCreate.

@Test
void dueDateChangedEventIsPublishedOnCreate() {
    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();
    IndividualResource 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();
    final var publishedEvents = Awaitility.await().atMost(1, TimeUnit.SECONDS).until(FakePubSub::getPublishedEvents, hasSize(2));
    final var event = publishedEvents.findFirst(byEventType("LOAN_DUE_DATE_CHANGED"));
    assertThat(event, isValidLoanDueDateChangedEvent(loan));
}
Also used : FakePubSub(api.support.fakes.FakePubSub) 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