Search in sources :

Example 21 with LoanRequestBuilder

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

the class LoansApiTest method canSearchByLoanItemStatus.

@Test
public void canSearchByLoanItemStatus() throws Exception {
    final IndividualResource agedToLostLoan = loansClient.create(new LoanRequestBuilder().agedToLost());
    loansClient.create(new LoanRequestBuilder().lostAndPaid());
    final List<String> agedToLostLoans = loansClient.getMany("itemStatus==Aged to lost").getRecords().stream().map(json -> json.getString("id")).collect(Collectors.toList());
    assertThat(agedToLostLoans, hasSize(1));
    assertThat(agedToLostLoans, hasItem(agedToLostLoan.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)

Example 22 with LoanRequestBuilder

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

the class LoansApiTest method cannotCreateALoanWithInvalidDates.

@Test
public void cannotCreateALoanWithInvalidDates() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
    JsonObject loanRequest = new LoanRequestBuilder().create();
    loanRequest.put("loanDate", "foo").put("returnDate", "bar");
    JsonResponse response = loansClient.attemptCreate(loanRequest);
    assertThat(String.format("Creating the loan should fail: %s", response.getBody()), response.getStatusCode(), is(HttpURLConnection.HTTP_BAD_REQUEST));
    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)"));
    assertNoLoanEvent(loanRequest.getString("id"));
}
Also used : LoanRequestBuilder(org.folio.rest.support.builders.LoanRequestBuilder) JsonObject(io.vertx.core.json.JsonObject) JsonResponse(org.folio.rest.support.JsonResponse) Test(org.junit.Test)

Example 23 with LoanRequestBuilder

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

the class LoansAnonymizationApiTest method shouldAnonymizeSingleClosedLoanForUser.

@Test
public void shouldAnonymizeSingleClosedLoanForUser() throws MalformedURLException, ExecutionException, InterruptedException, TimeoutException {
    final UUID userId = UUID.randomUUID();
    final IndividualResource loan = loansClient.create(new LoanRequestBuilder().closed().withUserId(userId));
    anonymizeLoansFor(userId);
    final IndividualResource fetchedLoan = loansClient.getById(loan.getId());
    assertThat("Should no longer have a user ID", fetchedLoan.getJson().containsKey("userId"), is(false));
    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 24 with LoanRequestBuilder

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

the class LoansAnonymizationApiTest method shouldAnonymizeSingleClosedLoanHistoryForUser.

@Test
public void shouldAnonymizeSingleClosedLoanHistoryForUser() throws MalformedURLException, ExecutionException, InterruptedException, TimeoutException {
    final UUID userId = UUID.randomUUID();
    final IndividualResource loan = loansClient.create(new LoanRequestBuilder().open().withUserId(userId));
    loansClient.replace(loan.getId(), LoanRequestBuilder.from(loan.getJson()).withReturnDate(DateTime.now()).closed());
    anonymizeLoansFor(userId);
    final MultipleRecords<JsonObject> historyRecords = getLoanActionHistoryForUser(userId);
    assertThat("Should be no history records for user", historyRecords.getRecords().size(), is(0));
    assertThat("Should be no history records for user", historyRecords.getTotalRecords(), is(0));
}
Also used : LoanRequestBuilder(org.folio.rest.support.builders.LoanRequestBuilder) JsonObject(io.vertx.core.json.JsonObject) UUIDMatchers.isUUID(org.folio.rest.support.matchers.UUIDMatchers.isUUID) UUID(java.util.UUID) IndividualResource(org.folio.rest.support.IndividualResource) Test(org.junit.Test)

Example 25 with LoanRequestBuilder

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

the class LoansAnonymizationApiTest method shouldNotAnonymizeOpenLoans.

@Test
public void shouldNotAnonymizeOpenLoans() 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);
    hasOpenLoansForUser(userId, firstOpenLoanId, secondOpenLoanId);
    assertThat("Anonymized loans should still be present", loansClient.getAll().getTotalRecords(), is(2));
}
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