use of org.folio.rest.support.IndividualResource in project mod-circulation-storage by folio-org.
the class LoansApiTest method cannotUpdateALoanWithInvalidDates.
@Test
public void cannotUpdateALoanWithInvalidDates() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
IndividualResource loan = loansClient.create(loanRequest());
JsonObject changedLoan = loan.copyJson();
changedLoan.put("loanDate", "bar");
changedLoan.put("returnDate", "foo");
final JsonResponse response = loansClient.attemptCreateOrReplace(loan.getId(), changedLoan);
assertThat(response, isBadRequest());
// TODO: Convert these to validation responses
assertThat(response.getBody(), containsString("loan date must be a date time (in RFC3339 format)"));
assertThat(response.getBody(), containsString("return date must be a date time (in RFC3339 format)"));
JsonObject created = loan.getJson();
assertCreateEventForLoan(created);
assertLoanEventCount(created.getString("id"), 1);
}
use of org.folio.rest.support.IndividualResource 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.IndividualResource in project mod-circulation-storage by folio-org.
the class CheckInStorageApiTest method canCreateCheckIn.
@Test
public void canCreateCheckIn() throws InterruptedException, ExecutionException, TimeoutException, MalformedURLException {
JsonObject checkInToCreate = createSampleCheckIn().create();
IndividualResource createResult = checkInClient.create(checkInToCreate);
assertThat(createResult.getJson(), is(checkInToCreate));
assertCreateEventForCheckIn(checkInToCreate);
}
use of org.folio.rest.support.IndividualResource in project mod-circulation-storage by folio-org.
the class RequestsApiTest method cannotUpdateRequestForSameItemToAnExistingPosition.
@Test
public void cannotUpdateRequestForSameItemToAnExistingPosition() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
UUID itemId = UUID.randomUUID();
createEntity(new RequestRequestBuilder().withItemId(itemId).withPosition(1).create(), requestStorageUrl());
final IndividualResource secondRequest = createEntity(new RequestRequestBuilder().withItemId(itemId).withPosition(2).create(), requestStorageUrl());
final JsonObject changedSecondRequest = secondRequest.getJson().put("position", 1);
CompletableFuture<JsonResponse> updateCompleted = new CompletableFuture<>();
client.put(requestStorageUrl(String.format("/%s", secondRequest.getId())), changedSecondRequest, TENANT_ID, ResponseHandler.json(updateCompleted));
JsonResponse response = updateCompleted.get(5, TimeUnit.SECONDS);
assertThat(response, isValidationResponseWhich(hasMessage("Cannot have more than one request with the same position in the queue")));
}
use of org.folio.rest.support.IndividualResource in project mod-circulation-storage by folio-org.
the class LoansApiTest method cannotReopenLoanWhenOpenLoanForSameItem.
@Test
public void cannotReopenLoanWhenOpenLoanForSameItem() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
UUID itemId = UUID.randomUUID();
JsonObject openLoanRequest = new LoanRequestBuilder().withItemId(itemId).open().create();
IndividualResource openLoan = loansClient.create(openLoanRequest);
JsonObject closedLoanRequest = new LoanRequestBuilder().withItemId(itemId).closed().create();
IndividualResource closedLoan = loansClient.create(closedLoanRequest);
JsonObject closed = closedLoan.getJson();
LoanRequestBuilder reopenLoanRequest = LoanRequestBuilder.from(closed).open();
JsonResponse replaceResponse = loansClient.attemptCreateOrReplace(closedLoan.getId(), reopenLoanRequest.create());
assertThat(replaceResponse, isValidationResponseWhich(hasMessage("Cannot have more than one open loan for the same item")));
assertCreateEventForLoan(openLoan.getJson());
assertCreateEventForLoan(closed);
assertLoanEventCount(closed.getString("id"), 1);
}
Aggregations