use of org.folio.rest.support.builders.LoanRequestBuilder 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);
}
use of org.folio.rest.support.builders.LoanRequestBuilder in project mod-circulation-storage by folio-org.
the class AnonymizeLoansApiTest method beforeEach.
@Before
public void beforeEach() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
StorageTestSuite.deleteAll(InterfaceUrls.loanStorageUrl());
JsonObject loan1 = loansClient.create(new LoanRequestBuilder().withId(UUID.fromString(firstLoanId)).withItemId(UUID.randomUUID()).withUserId(UUID.randomUUID()).checkedOut().create()).getJson();
JsonObject loan2 = loansClient.create(new LoanRequestBuilder().withId(UUID.fromString(secondLoanId)).withItemId(UUID.randomUUID()).withUserId(UUID.randomUUID()).checkedOut().create()).getJson();
loansClient.replace(firstLoanId, LoanRequestBuilder.from(loan1).checkedIn());
loansClient.replace(secondLoanId, LoanRequestBuilder.from(loan2).checkedIn());
}
use of org.folio.rest.support.builders.LoanRequestBuilder in project mod-circulation-storage by folio-org.
the class LoansAnonymizationApiTest method shouldNotAnonymizeLoansHistoryForOtherUser.
@Test
public void shouldNotAnonymizeLoansHistoryForOtherUser() throws MalformedURLException, ExecutionException, InterruptedException, TimeoutException {
final UUID firstUserId = UUID.randomUUID();
final UUID secondUserId = UUID.randomUUID();
final IndividualResource loanForOtherUser = loansClient.create(new LoanRequestBuilder().closed().withUserId(firstUserId));
anonymizeLoansFor(secondUserId);
hasLoanHistoryForUser(firstUserId, loanForOtherUser.getId());
}
use of org.folio.rest.support.builders.LoanRequestBuilder in project mod-circulation-storage by folio-org.
the class LoansAnonymizationApiTest method shouldOnlyAnonymizeClosedLoansWhenBothArePresent.
@Test
public void shouldOnlyAnonymizeClosedLoansWhenBothArePresent() throws MalformedURLException, ExecutionException, InterruptedException, TimeoutException {
final UUID userId = UUID.randomUUID();
final LoanRequestBuilder loanForUser = new LoanRequestBuilder().withUserId(userId);
loansClient.create(loanForUser.closed().withItemId(UUID.randomUUID()).withId(UUID.randomUUID())).getId();
loansClient.create(loanForUser.closed().withItemId(UUID.randomUUID()).withId(UUID.randomUUID())).getId();
final String firstOpenLoanId = loansClient.create(loanForUser.open().withItemId(UUID.randomUUID()).withId(UUID.randomUUID())).getId();
final String secondOpenLoanId = loansClient.create(loanForUser.open().withItemId(UUID.randomUUID()).withId(UUID.randomUUID())).getId();
loansClient.create(loanForUser.closed().withItemId(UUID.randomUUID()).withId(UUID.randomUUID())).getId();
anonymizeLoansFor(userId);
hasOpenLoansForUser(userId, firstOpenLoanId, secondOpenLoanId);
assertThat("Anonymized loans should still be present", loansClient.getAll().getTotalRecords(), is(5));
}
use of org.folio.rest.support.builders.LoanRequestBuilder in project mod-circulation-storage by folio-org.
the class LoansAnonymizationApiTest method shouldNotAnonymizeLoanActionHistoryForOpenLoans.
@Test
public void shouldNotAnonymizeLoanActionHistoryForOpenLoans() throws MalformedURLException, ExecutionException, InterruptedException, TimeoutException {
final UUID userId = UUID.randomUUID();
final LoanRequestBuilder loanForUser = new LoanRequestBuilder().withUserId(userId);
final String firstOpenLoanId = loansClient.create(loanForUser.open().withItemId(UUID.randomUUID()).withId(UUID.randomUUID())).getId();
final String secondOpenLoanId = loansClient.create(loanForUser.open().withItemId(UUID.randomUUID()).withId(UUID.randomUUID())).getId();
anonymizeLoansFor(userId);
hasLoanHistoryForUser(userId, firstOpenLoanId, secondOpenLoanId);
}
Aggregations