use of org.folio.rest.support.IndividualResource in project mod-circulation-storage by folio-org.
the class LoanPoliciesApiTest method createLoanPolicy.
private IndividualResource createLoanPolicy(JsonObject loanPolicyRequest) throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
CompletableFuture<JsonResponse> createCompleted = new CompletableFuture<>();
client.post(loanPolicyStorageUrl(), loanPolicyRequest, StorageTestSuite.TENANT_ID, ResponseHandler.json(createCompleted));
JsonResponse postResponse = createCompleted.get(5, TimeUnit.SECONDS);
assertThat(String.format("Failed to create loan policy: %s", postResponse.getBody()), postResponse, matchesCreated());
return new IndividualResource(postResponse);
}
use of org.folio.rest.support.IndividualResource in project mod-circulation-storage by folio-org.
the class LoansApiTest method canRemoveUserIdFromClosedLoan.
@Test
public void canRemoveUserIdFromClosedLoan() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
DateTime loanDate = new DateTime(2017, 3, 1, 13, 25, 46, 232, DateTimeZone.UTC);
final UUID loanId = UUID.randomUUID();
final UUID userId = UUID.randomUUID();
IndividualResource loan = loansClient.create(new LoanRequestBuilder().withId(loanId).withUserId(userId).withLoanDate(loanDate).withDueDate(loanDate.plus(Period.days(14))).open().create());
final LoanRequestBuilder closedLoanRequest = LoanRequestBuilder.from(loan.getJson()).closed();
loansClient.replace(loanId.toString(), closedLoanRequest);
final IndividualResource closedLoan = loansClient.getById(loanId);
final LoanRequestBuilder anonymisedLoanRequest = LoanRequestBuilder.from(closedLoan.getJson()).withNoUserId();
loansClient.replace(loanId.toString(), anonymisedLoanRequest);
final IndividualResource anonymisedLoan = loansClient.getById(loanId);
assertThat(anonymisedLoan.getJson(), isClosed());
assertThat("Should not have a user ID", anonymisedLoan.getJson().containsKey("userId"), is(false));
assertCreateEventForLoan(loan.getJson());
assertUpdateEventForLoan(closedLoan.getJson(), anonymisedLoan.getJson());
}
use of org.folio.rest.support.IndividualResource in project mod-circulation-storage by folio-org.
the class LoansApiTest method cannotRemoveUserIdFromOpenLoan.
@Test
public void cannotRemoveUserIdFromOpenLoan() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
final UUID loanId = UUID.randomUUID();
final UUID userId = UUID.randomUUID();
IndividualResource loan = loansClient.create(new LoanRequestBuilder().withId(loanId).withUserId(userId).open().create());
final LoanRequestBuilder loanRequestWithoutId = LoanRequestBuilder.from(loan.getJson()).withNoUserId();
final JsonResponse putResponse = loansClient.attemptCreateOrReplace(loanId.toString(), loanRequestWithoutId);
assertThat(putResponse, isValidationResponseWhich(hasMessage("Open loan must have a user ID")));
assertCreateEventForLoan(loan.getJson());
assertLoanEventCount(loanId.toString(), 1);
}
use of org.folio.rest.support.IndividualResource in project mod-circulation-storage by folio-org.
the class LoansApiTest method returnDateIsMandatoryForClosedLoans.
@Test
@Ignore("Should conditional field validation be done in a storage module?")
public void returnDateIsMandatoryForClosedLoans() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
DateTime loanDate = new DateTime(2017, 3, 1, 13, 25, 46, 232, DateTimeZone.UTC);
IndividualResource loan = loansClient.create(new LoanRequestBuilder().withLoanDate(loanDate).withDueDate(loanDate.plus(Period.days(14))).create());
LoanRequestBuilder returnedLoan = LoanRequestBuilder.from(loan.copyJson()).closed();
CompletableFuture<TextResponse> putCompleted = new CompletableFuture<>();
client.put(InterfaceUrls.loanStorageUrl(String.format("/%s", loan.getId())), returnedLoan.create(), StorageTestSuite.TENANT_ID, ResponseHandler.text(putCompleted));
TextResponse response = putCompleted.get(5, TimeUnit.SECONDS);
assertThat(String.format("Should have failed to update loan: %s", response.getBody()), response.getStatusCode(), is(HttpURLConnection.HTTP_BAD_REQUEST));
assertThat(response.getBody(), containsString("return date is mandatory to close a loan"));
}
use of org.folio.rest.support.IndividualResource in project mod-circulation-storage by folio-org.
the class LoansApiTest method canSearchByLoanStatus.
@Test
public void canSearchByLoanStatus() throws Exception {
final IndividualResource openLoan = loansClient.create(new LoanRequestBuilder().checkedOut());
loansClient.create(new LoanRequestBuilder().checkedIn());
final List<String> openLoans = loansClient.getMany("status.name==Open").getRecords().stream().map(json -> json.getString("id")).collect(Collectors.toList());
assertThat(openLoans, hasSize(1));
assertThat(openLoans, hasItem(openLoan.getId()));
}
Aggregations