Search in sources :

Example 26 with LoanRequestBuilder

use of org.folio.rest.support.builders.LoanRequestBuilder in project mod-circulation-storage by folio-org.

the class LoansAnonymizationApiTest method shouldNotAnonymizeLoansForOtherUser.

@Test
public void shouldNotAnonymizeLoansForOtherUser() throws MalformedURLException, ExecutionException, InterruptedException, TimeoutException {
    final UUID firstUserId = UUID.randomUUID();
    final UUID secondUserId = UUID.randomUUID();
    final IndividualResource otherUsersLoan = loansClient.create(new LoanRequestBuilder().closed().withUserId(firstUserId));
    anonymizeLoansFor(secondUserId);
    final IndividualResource fetchedLoan = loansClient.getById(otherUsersLoan.getId());
    assertThat(fetchedLoan.getJson().getString("userId"), isUUID(firstUserId));
    assertThat("Anonymized loans should still be present", loansClient.getAll().getTotalRecords(), is(1));
}
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 27 with LoanRequestBuilder

use of org.folio.rest.support.builders.LoanRequestBuilder in project mod-circulation-storage by folio-org.

the class PatronActionSessionAPITest method beforeTest.

@Before
public void beforeTest() throws InterruptedException, ExecutionException, TimeoutException, MalformedURLException {
    CompletableFuture<RowSet<Row>> future = new CompletableFuture<>();
    PostgresClient.getInstance(StorageTestSuite.getVertx(), TENANT_ID).delete(PATRON_ACTION_SESSION, new Criterion(), del -> future.complete(del.result()));
    future.join();
    JsonObject loan = loansClient.create(new LoanRequestBuilder().withId(UUID.randomUUID()).withItemId(UUID.randomUUID()).withUserId(UUID.randomUUID()).closed().create()).getJson();
    existingLoanId = loan.getString("id");
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) Criterion(org.folio.rest.persist.Criteria.Criterion) LoanRequestBuilder(org.folio.rest.support.builders.LoanRequestBuilder) RowSet(io.vertx.sqlclient.RowSet) JsonObject(io.vertx.core.json.JsonObject) Before(org.junit.Before)

Example 28 with LoanRequestBuilder

use of org.folio.rest.support.builders.LoanRequestBuilder in project mod-circulation-storage by folio-org.

the class LoansApiTest method canCreateOpenLoanWhenClosedLoansForSameItem.

@Test
public void canCreateOpenLoanWhenClosedLoansForSameItem() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    UUID itemId = UUID.randomUUID();
    JsonObject closedLoanRequest = new LoanRequestBuilder().withItemId(itemId).closed().create();
    loansClient.create(closedLoanRequest);
    JsonObject closedLoan = loansClient.getById(closedLoanRequest.getString("id")).getJson();
    JsonObject openLoanRequest = new LoanRequestBuilder().withItemId(itemId).open().create();
    loansClient.create(openLoanRequest);
    JsonObject openLoan = loansClient.getById(openLoanRequest.getString("id")).getJson();
    assertCreateEventForLoan(closedLoan);
    assertCreateEventForLoan(openLoan);
}
Also used : LoanRequestBuilder(org.folio.rest.support.builders.LoanRequestBuilder) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) Test(org.junit.Test)

Example 29 with LoanRequestBuilder

use of org.folio.rest.support.builders.LoanRequestBuilder in project mod-circulation-storage by folio-org.

the class LoansApiTest method canCreateALoanWithoutAnId.

@Test
public void canCreateALoanWithoutAnId() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
    UUID itemId = UUID.randomUUID();
    UUID userId = UUID.randomUUID();
    UUID proxyUserId = UUID.randomUUID();
    JsonObject loanRequest = new LoanRequestBuilder().withNoId().withItemId(itemId).withUserId(userId).withProxyUserId(proxyUserId).withLoanDate(new DateTime(2017, 3, 20, 7, 21, 45, DateTimeZone.UTC)).open().withAction("checkedout").withItemStatus("Checked out").withDueDate(new DateTime(2017, 4, 20, 7, 21, 45, DateTimeZone.UTC)).create();
    JsonObject loan = loansClient.create(loanRequest).getJson();
    String newId = loan.getString("id");
    assertThat(newId, is(notNullValue()));
    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-03-20T07:21:45.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("due date does not match", loan.getString("dueDate"), is("2017-04-20T07:21:45.000+00:00"));
    assertCreateEventForLoan(loan);
}
Also used : LoanRequestBuilder(org.folio.rest.support.builders.LoanRequestBuilder) JsonObject(io.vertx.core.json.JsonObject) Matchers.containsString(org.hamcrest.Matchers.containsString) UUID(java.util.UUID) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 30 with LoanRequestBuilder

use of org.folio.rest.support.builders.LoanRequestBuilder in project mod-circulation-storage by folio-org.

the class LoansApiTest method canSearchByLoanAgedToLostItemHasBeenBilled.

@Test
public void canSearchByLoanAgedToLostItemHasBeenBilled() throws Exception {
    final IndividualResource billedLoan = loansClient.create(new LoanRequestBuilder().withAgedToLostDelayedBilling(true, DateTime.now(), DateTime.now()));
    loansClient.create(new LoanRequestBuilder().withAgedToLostDelayedBilling(false, DateTime.now(), DateTime.now()));
    final List<String> billedLoans = loansClient.getMany("agedToLostDelayedBilling.lostItemHasBeenBilled==true").getRecords().stream().map(json -> json.getString("id")).collect(Collectors.toList());
    assertThat(billedLoans, hasSize(1));
    assertThat(billedLoans, hasItem(billedLoan.getId()));
}
Also used : HttpURLConnection(java.net.HttpURLConnection) ResponseHandler(org.folio.rest.support.ResponseHandler) ValidationResponseMatchers.isValidationResponseWhich(org.folio.rest.support.matchers.ValidationResponseMatchers.isValidationResponseWhich) JsonResponse(org.folio.rest.support.JsonResponse) DateTimeZone(org.joda.time.DateTimeZone) DomainEventAssertions.assertLoanEventCount(org.folio.rest.support.matchers.DomainEventAssertions.assertLoanEventCount) Date(java.util.Date) AssertingRecordClient(org.folio.rest.support.http.AssertingRecordClient) TimeoutException(java.util.concurrent.TimeoutException) LoanRequestBuilder(org.folio.rest.support.builders.LoanRequestBuilder) IsNull.nullValue(org.hamcrest.core.IsNull.nullValue) After(org.junit.After) Is.is(org.hamcrest.core.Is.is) JsonObject(io.vertx.core.json.JsonObject) Metadata(org.folio.rest.jaxrs.model.Metadata) HttpResponseStatusCodeMatchers.isNotFound(org.folio.rest.support.matchers.HttpResponseStatusCodeMatchers.isNotFound) LoanMatchers.isClosed(org.folio.rest.support.matchers.LoanMatchers.isClosed) DateFormat(java.text.DateFormat) IsNot.not(org.hamcrest.core.IsNot.not) MatcherAssert.assertThat(org.hamcrest.junit.MatcherAssert.assertThat) ISODateTimeFormat(org.joda.time.format.ISODateTimeFormat) ValidationErrorMatchers.hasMessageContaining(org.folio.rest.support.matchers.ValidationErrorMatchers.hasMessageContaining) Matchers.allOf(org.hamcrest.Matchers.allOf) TimeZone(java.util.TimeZone) DomainEventAssertions.assertUpdateEventForLoan(org.folio.rest.support.matchers.DomainEventAssertions.assertUpdateEventForLoan) DomainEventAssertions.assertCreateEventForLoan(org.folio.rest.support.matchers.DomainEventAssertions.assertCreateEventForLoan) TextResponse(org.folio.rest.support.TextResponse) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) List(java.util.List) Matchers.anyOf(org.hamcrest.Matchers.anyOf) TRUE(java.lang.Boolean.TRUE) Matchers.containsString(org.hamcrest.Matchers.containsString) DateTime.parse(org.joda.time.DateTime.parse) SimpleDateFormat(java.text.SimpleDateFormat) DomainEventAssertions.assertRemoveEventForLoan(org.folio.rest.support.matchers.DomainEventAssertions.assertRemoveEventForLoan) CompletableFuture(java.util.concurrent.CompletableFuture) IndividualResource(org.folio.rest.support.IndividualResource) DomainEventAssertions.assertNoLoanEvent(org.folio.rest.support.matchers.DomainEventAssertions.assertNoLoanEvent) HttpResponseStatusCodeMatchers.isBadRequest(org.folio.rest.support.matchers.HttpResponseStatusCodeMatchers.isBadRequest) ValidationErrorMatchers.hasParameter(org.folio.rest.support.matchers.ValidationErrorMatchers.hasParameter) Matchers.hasSize(org.hamcrest.Matchers.hasSize) InterfaceUrls(org.folio.rest.support.http.InterfaceUrls) Before(org.junit.Before) Period(org.joda.time.Period) MalformedURLException(java.net.MalformedURLException) DateTime(org.joda.time.DateTime) Test(org.junit.Test) ValidationErrorMatchers.hasMessage(org.folio.rest.support.matchers.ValidationErrorMatchers.hasMessage) ApiTests(org.folio.rest.support.ApiTests) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) LoanMatchers.isOpen(org.folio.rest.support.matchers.LoanMatchers.isOpen) JsonArray(io.vertx.core.json.JsonArray) Matchers.hasItem(org.hamcrest.Matchers.hasItem) Ignore(org.junit.Ignore) IsNull.notNullValue(org.hamcrest.core.IsNull.notNullValue) DateTimeConstants(org.joda.time.DateTimeConstants) LoanRequestBuilder(org.folio.rest.support.builders.LoanRequestBuilder) Matchers.containsString(org.hamcrest.Matchers.containsString) IndividualResource(org.folio.rest.support.IndividualResource) 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