Search in sources :

Example 41 with LoanRequestBuilder

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);
}
Also used : LoanRequestBuilder(org.folio.rest.support.builders.LoanRequestBuilder) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) IndividualResource(org.folio.rest.support.IndividualResource) JsonResponse(org.folio.rest.support.JsonResponse) Test(org.junit.Test)

Example 42 with LoanRequestBuilder

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());
}
Also used : LoanRequestBuilder(org.folio.rest.support.builders.LoanRequestBuilder) JsonObject(io.vertx.core.json.JsonObject) Before(org.junit.Before)

Example 43 with LoanRequestBuilder

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());
}
Also used : LoanRequestBuilder(org.folio.rest.support.builders.LoanRequestBuilder) UUIDMatchers.isUUID(org.folio.rest.support.matchers.UUIDMatchers.isUUID) UUID(java.util.UUID) IndividualResource(org.folio.rest.support.IndividualResource) Test(org.junit.Test)

Example 44 with LoanRequestBuilder

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));
}
Also used : LoanRequestBuilder(org.folio.rest.support.builders.LoanRequestBuilder) UUIDMatchers.isUUID(org.folio.rest.support.matchers.UUIDMatchers.isUUID) UUID(java.util.UUID) Test(org.junit.Test)

Example 45 with LoanRequestBuilder

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);
}
Also used : LoanRequestBuilder(org.folio.rest.support.builders.LoanRequestBuilder) UUIDMatchers.isUUID(org.folio.rest.support.matchers.UUIDMatchers.isUUID) UUID(java.util.UUID) Test(org.junit.Test)

Aggregations

LoanRequestBuilder (org.folio.rest.support.builders.LoanRequestBuilder)46 Test (org.junit.Test)44 UUID (java.util.UUID)39 JsonObject (io.vertx.core.json.JsonObject)34 DateTime (org.joda.time.DateTime)18 IndividualResource (org.folio.rest.support.IndividualResource)17 JsonResponse (org.folio.rest.support.JsonResponse)16 CompletableFuture (java.util.concurrent.CompletableFuture)9 UUIDMatchers.isUUID (org.folio.rest.support.matchers.UUIDMatchers.isUUID)8 Matchers.containsString (org.hamcrest.Matchers.containsString)6 JsonArray (io.vertx.core.json.JsonArray)5 TextResponse (org.folio.rest.support.TextResponse)5 TRUE (java.lang.Boolean.TRUE)4 HttpURLConnection (java.net.HttpURLConnection)4 MalformedURLException (java.net.MalformedURLException)4 DateFormat (java.text.DateFormat)4 SimpleDateFormat (java.text.SimpleDateFormat)4 Date (java.util.Date)4 List (java.util.List)4 TimeZone (java.util.TimeZone)4