use of org.folio.rest.support.builders.LoanRequestBuilder in project mod-circulation-storage by folio-org.
the class LoansApiTest method canCreateClosedLoanWhenOpenLoanForDifferentItem.
@Test
public void canCreateClosedLoanWhenOpenLoanForDifferentItem() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
UUID firstItemId = UUID.randomUUID();
UUID secondItemId = UUID.randomUUID();
JsonObject firstLoanRequest = new LoanRequestBuilder().withItemId(firstItemId).open().create();
loansClient.create(firstLoanRequest);
JsonObject firstLoan = loansClient.getById(firstLoanRequest.getString("id")).getJson();
JsonObject secondLoanRequest = new LoanRequestBuilder().withItemId(secondItemId).closed().create();
loansClient.create(secondLoanRequest);
JsonObject secondLoan = loansClient.getById(secondLoanRequest.getString("id")).getJson();
assertCreateEventForLoan(firstLoan);
assertCreateEventForLoan(secondLoan);
}
use of org.folio.rest.support.builders.LoanRequestBuilder in project mod-circulation-storage by folio-org.
the class LoansApiTest method canCloseALoanByReturningTheItem.
@Test
public void canCloseALoanByReturningTheItem() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
DateTime loanDate = new DateTime(2017, 3, 1, 13, 25, 46, 232, DateTimeZone.UTC);
final UUID userId = UUID.randomUUID();
IndividualResource loan = loansClient.create(new LoanRequestBuilder().withUserId(userId).withLoanDate(loanDate).withDueDate(loanDate.plus(Period.days(14))).create());
JsonObject createdLoan = loan.copyJson();
LoanRequestBuilder returnedLoan = LoanRequestBuilder.from(createdLoan).closed().withAction("checkedin").withItemStatus("Available").withReturnDate(new DateTime(2017, 3, 5, 14, 23, 41, DateTimeZone.UTC));
loansClient.replace(loan.getId(), returnedLoan);
JsonObject updatedLoan = loansClient.getById(UUID.fromString(loan.getId())).getJson();
assertThat(updatedLoan.getString("userId"), is(userId.toString()));
assertThat(updatedLoan.getString("returnDate"), is("2017-03-05T14:23:41.000Z"));
assertThat(updatedLoan, isClosed());
assertThat("item status is not available", updatedLoan.getString("itemStatus"), is("Available"));
assertThat("action is not checkedin", updatedLoan.getString("action"), is("checkedin"));
assertCreateEventForLoan(createdLoan);
assertUpdateEventForLoan(createdLoan, updatedLoan);
}
use of org.folio.rest.support.builders.LoanRequestBuilder in project mod-circulation-storage by folio-org.
the class LoansApiTest method cannotProvideAdditionalPropertiesInLoan.
@Test
public void cannotProvideAdditionalPropertiesInLoan() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
UUID id = UUID.randomUUID();
JsonObject requestWithAdditionalProperty = new LoanRequestBuilder().withId(id).create();
requestWithAdditionalProperty.put("somethingAdditional", "foo");
JsonResponse response = loansClient.attemptCreate(requestWithAdditionalProperty);
assertThat(response, isValidationResponseWhich(hasMessageContaining("Unrecognized field")));
assertNoLoanEvent(id.toString());
}
use of org.folio.rest.support.builders.LoanRequestBuilder in project mod-circulation-storage by folio-org.
the class LoansApiTest method canCreateALoan.
@Test
public void canCreateALoan() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
UUID id = UUID.randomUUID();
UUID itemId = UUID.randomUUID();
UUID itemLocationAtCheckOut = UUID.randomUUID();
UUID userId = UUID.randomUUID();
UUID proxyUserId = UUID.randomUUID();
UUID loanPolicyId = UUID.randomUUID();
DateTime expectedLostDate = DateTime.now();
UUID overdueFinePolicyId = UUID.randomUUID();
UUID lostItemPolicyId = UUID.randomUUID();
final DateTime claimedReturnedDate = DateTime.now(DateTimeZone.UTC);
final DateTime agedToLostDate = DateTime.now(DateTimeZone.UTC).minusDays(10);
DateTime dateLostItemShouldBeBilled = new DateTime(2017, 9, 27, 10, 23, 43, DateTimeZone.UTC);
JsonObject loanRequest = new LoanRequestBuilder().withId(id).withItemId(itemId).withUserId(userId).withProxyUserId(proxyUserId).withLoanDate(new DateTime(2017, 6, 27, 10, 23, 43, DateTimeZone.UTC)).open().withAction("checkedout").withItemStatus("Checked out").withDueDate(new DateTime(2017, 7, 27, 10, 23, 43, DateTimeZone.UTC)).withItemEffectiveLocationIdAtCheckOut(itemLocationAtCheckOut).withLoanPolicyId(loanPolicyId).withDeclaredLostDate(expectedLostDate).withOverdueFinePolicyId(overdueFinePolicyId).withLostItemPolicyId(lostItemPolicyId).withClaimedReturnedDate(claimedReturnedDate).withAgedToLostDelayedBilling(false, dateLostItemShouldBeBilled, agedToLostDate).create();
JsonObject loan = loansClient.create(loanRequest).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("proxy user id does not match", loan.getString("proxyUserId"), is(proxyUserId.toString()));
assertThat("item id does not match", loan.getString("itemId"), is(itemId.toString()));
assertThat("loan date does not match", loan.getString("loanDate"), is("2017-06-27T10:23:43.000Z"));
assertThat(loan, isOpen());
assertThat("action is not checked out", loan.getString("action"), is("checkedout"));
assertThat("item status is not checked out", loan.getString("itemStatus"), is("Checked out"));
assertThat("itemEffectiveLocationIdAtCheckOut does not match", loan.getString("itemEffectiveLocationIdAtCheckOut"), is(itemLocationAtCheckOut.toString()));
assertThat("loan policy should be set", loan.getString("loanPolicyId"), is(loanPolicyId.toString()));
assertThat("due date does not match", loan.getString("dueDate"), is("2017-07-27T10:23:43.000+00:00"));
assertThat("recall changed due date should be null", loan.getBoolean("dueDateChangedByRecall"), nullValue());
assertThat("Loan should have a declaredLostDate property", DateTime.parse(loansClient.getById(id).getJson().getString("declaredLostDate")).getMillis(), is(expectedLostDate.getMillis()));
assertThat("Overdue fine policy id should be set", loan.getString("overdueFinePolicyId"), is(overdueFinePolicyId.toString()));
assertThat("Lost item policy id should be set", loan.getString("lostItemPolicyId"), is(lostItemPolicyId.toString()));
assertThat(parse(loan.getString("claimedReturnedDate")), is(claimedReturnedDate));
final JsonObject agedToLostDelayedBilling = loan.getJsonObject("agedToLostDelayedBilling");
assertThat(agedToLostDelayedBilling.getBoolean("lostItemHasBeenBilled"), is(false));
assertThat(parse(agedToLostDelayedBilling.getString("dateLostItemShouldBeBilled")), is(dateLostItemShouldBeBilled));
assertThat(parse(agedToLostDelayedBilling.getString("agedToLostDate")), is(agedToLostDate));
assertCreateEventForLoan(loan);
}
use of org.folio.rest.support.builders.LoanRequestBuilder in project mod-circulation-storage by folio-org.
the class LoansApiTest method canCreateALoanWithDueDateChangedByRecallSet.
@Test
public void canCreateALoanWithDueDateChangedByRecallSet() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
UUID id = UUID.randomUUID();
UUID itemId = UUID.randomUUID();
UUID userId = UUID.randomUUID();
UUID proxyUserId = UUID.randomUUID();
UUID loanPolicyId = UUID.randomUUID();
JsonObject loanRequest = new LoanRequestBuilder().withId(id).withItemId(itemId).withUserId(userId).withProxyUserId(proxyUserId).withLoanDate(new DateTime(2017, 6, 27, 10, 23, 43, DateTimeZone.UTC)).open().withAction("checkedout").withItemStatus("Checked out").withDueDate(new DateTime(2017, 7, 27, 10, 23, 43, DateTimeZone.UTC)).withLoanPolicyId(loanPolicyId).withDueDateChangedByRecall(TRUE).create();
JsonObject loan = loansClient.create(loanRequest).getJson();
assertThat("recall changed due date is not true", loan.getBoolean("dueDateChangedByRecall"), is(TRUE));
assertCreateEventForLoan(loan);
}
Aggregations