Search in sources :

Example 66 with LoanBuilder

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

the class LoanAPITests method barcodeIsNotIncludedWhenItemDoesNotHaveOne.

@Test
void barcodeIsNotIncludedWhenItemDoesNotHaveOne() {
    UUID id = UUID.randomUUID();
    UUID itemId = itemsFixture.basedUponSmallAngryPlanet(ItemBuilder::withNoBarcode).getId();
    UUID userId = usersFixture.charlotte().getId();
    loansFixture.createLoan(new LoanBuilder().withId(id).withUserId(userId).withItemId(itemId).withLoanDate(ZonedDateTime.of(2016, 10, 15, 8, 26, 53, 0, UTC)).withStatus("Open"));
    Response getResponse = loansClient.getById(id);
    assertThat(format("Failed to get loan: %s", getResponse.getBody()), getResponse.getStatusCode(), is(HttpURLConnection.HTTP_OK));
    JsonObject loan = getResponse.getJson();
    assertThat("barcode is not taken from item", loan.getJsonObject("item").containsKey("barcode"), is(false));
}
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) Test(org.junit.jupiter.api.Test)

Example 67 with LoanBuilder

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

the class LoanAPITests method cannotCreateOpenLoanForUnknownRequestingUser.

@Test
void cannotCreateOpenLoanForUnknownRequestingUser() {
    UUID loanId = UUID.randomUUID();
    final UUID itemId = itemsFixture.basedUponSmallAngryPlanet().getId();
    final UUID unknownUserId = UUID.randomUUID();
    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 Response response = loansFixture.attemptToCreateLoan(new LoanBuilder().withId(loanId).withUserId(unknownUserId).withItemId(itemId).withLoanDate(loanDate).withDueDate(dueDate).open(), UNPROCESSABLE_ENTITY);
    assertThat(response.getJson(), hasErrorWith(allOf(hasMessage("user is not found"), hasUUIDParameter("userId", unknownUserId))));
}
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 68 with LoanBuilder

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

the class LoanAPITests method cannotCreateLoanThatIsNotOpenOrClosed.

@Test
void cannotCreateLoanThatIsNotOpenOrClosed() {
    IndividualResource smallAngryPlanet = itemsFixture.basedUponSmallAngryPlanet();
    IndividualResource jessica = usersFixture.jessica();
    final Response response = loansFixture.attemptToCreateLoan(new LoanBuilder().withStatus("Unknown Status").withItemId(smallAngryPlanet.getId()).withUserId(jessica.getId()), UNPROCESSABLE_ENTITY);
    assertThat(response.getJson(), hasErrorWith(hasMessage("Loan status must be \"Open\" or \"Closed\"")));
}
Also used : Response(org.folio.circulation.support.http.client.Response) LoanBuilder(api.support.builders.LoanBuilder) IndividualResource(api.support.http.IndividualResource) Test(org.junit.jupiter.api.Test)

Example 69 with LoanBuilder

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

the class LoanAPITests method cannotCreateALoanForUnknownItem.

@Test
void cannotCreateALoanForUnknownItem() {
    UUID id = UUID.randomUUID();
    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 unknownItemId = UUID.randomUUID();
    final Response response = loansFixture.attemptToCreateLoan(new LoanBuilder().open().withId(id).withUserId(userId).withItemId(unknownItemId).withLoanDate(loanDate).withDueDate(dueDate), UNPROCESSABLE_ENTITY);
    assertThat(response.getJson(), hasErrorWith(allOf(hasMessage(format("No item with ID %s could be found", unknownItemId)), hasUUIDParameter("itemId", unknownItemId))));
}
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 70 with LoanBuilder

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

the class LoanAPITests method multipleClosedLoansHaveNoBorrowerInformation.

@Test
void multipleClosedLoansHaveNoBorrowerInformation() {
    UUID smallAngryPlanetId = itemsFixture.basedUponSmallAngryPlanet().getId();
    UUID nodId = itemsFixture.basedUponNod().getId();
    UUID checkinServicePointId = servicePointsFixture.cd1().getId();
    UUID checkinServicePointId2 = servicePointsFixture.cd2().getId();
    final IndividualResource user = usersFixture.jessica();
    LoanBuilder loan1Builder = new LoanBuilder().withItemId(smallAngryPlanetId).withCheckinServicePointId(checkinServicePointId).closed().withUserId(user.getId());
    // Prepare loan
    loansFixture.createLoan(loan1Builder);
    final IndividualResource loan1 = loansClient.createAtSpecificLocation(loan1Builder);
    LoanBuilder loan2Builder = new LoanBuilder().withItemId(nodId).closed().withCheckinServicePointId(checkinServicePointId2).withUserId(user.getId());
    // Prepare loan
    loansFixture.createLoan(loan2Builder);
    final IndividualResource loan2 = loansClient.createAtSpecificLocation(loan2Builder);
    JsonObject updatedLoanRequest = loan1.copyJson();
    updatedLoanRequest.getJsonObject("status").put("name", "Closed");
    updatedLoanRequest.remove("userId");
    loansClient.replace(loan1.getId(), updatedLoanRequest);
    updatedLoanRequest = loan2.copyJson();
    updatedLoanRequest.getJsonObject("status").put("name", "Closed");
    updatedLoanRequest.remove("userId");
    loansClient.replace(loan2.getId(), updatedLoanRequest);
    MultipleJsonRecords loans = loansFixture.getAllLoans();
    loans.forEach(this::hasNoBorrowerProperties);
}
Also used : MultipleJsonRecords(api.support.MultipleJsonRecords) 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)

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