Search in sources :

Example 11 with LoanRequestBuilder

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

the class LoansApiTest method omittedStatusFromReplacedLoanDefaultsToOpen.

@Test
public void omittedStatusFromReplacedLoanDefaultsToOpen() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    IndividualResource loan = loansClient.create(new LoanRequestBuilder().open().create());
    JsonObject createdLoan = loan.copyJson();
    LoanRequestBuilder returnedLoan = LoanRequestBuilder.from(createdLoan).withNoStatus();
    loansClient.replace(loan.getId(), returnedLoan);
    JsonObject updatedLoan = loansClient.getById(UUID.fromString(loan.getId())).getJson();
    assertThat(updatedLoan, isOpen());
    assertCreateEventForLoan(createdLoan);
    assertUpdateEventForLoan(createdLoan, updatedLoan);
}
Also used : LoanRequestBuilder(org.folio.rest.support.builders.LoanRequestBuilder) JsonObject(io.vertx.core.json.JsonObject) IndividualResource(org.folio.rest.support.IndividualResource) Test(org.junit.Test)

Example 12 with LoanRequestBuilder

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

the class LoansApiTest method canCreateAnAlreadyClosedLoan.

@Test
public void canCreateAnAlreadyClosedLoan() throws InterruptedException, ExecutionException, TimeoutException, MalformedURLException {
    UUID id = UUID.randomUUID();
    UUID itemId = UUID.randomUUID();
    UUID userId = UUID.randomUUID();
    UUID proxyUserId = UUID.randomUUID();
    DateTime loanDate = new DateTime(2017, 2, 27, 10, 23, 43, DateTimeZone.UTC);
    DateTime dueDate = new DateTime(2017, 3, 29, 10, 23, 43, DateTimeZone.UTC);
    DateTime returnDate = new DateTime(2017, 4, 1, 11, 35, 0, DateTimeZone.UTC);
    DateTime systemReturnDate = new DateTime(2017, 4, 1, 12, 0, 0, DateTimeZone.UTC);
    JsonObject loanRequest = new LoanRequestBuilder().withId(id).withUserId(userId).withProxyUserId(proxyUserId).withItemId(itemId).withLoanDate(loanDate).withDueDate(dueDate).withReturnDate(returnDate).withSystemReturnDate(systemReturnDate).closed().create();
    JsonObject loan = loansClient.create(loanRequest).getJson();
    assertThat("return date does not match", loan.getString("returnDate"), is("2017-04-01T11:35:00.000Z"));
    assertThat("system return date does not match", loan.getString("systemReturnDate"), is("2017-04-01T12:00:00.000+00:00"));
    assertCreateEventForLoan(loan);
}
Also used : LoanRequestBuilder(org.folio.rest.support.builders.LoanRequestBuilder) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 13 with LoanRequestBuilder

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

the class LoansApiTest method canSearchByLoanAgedToLostBillingDate.

@Test
public void canSearchByLoanAgedToLostBillingDate() throws Exception {
    final DateTime today = DateTime.now();
    final DateTime yesterday = today.minusDays(1);
    final DateTime tomorrow = today.plusDays(1);
    loansClient.create(new LoanRequestBuilder().withAgedToLostDelayedBilling(true, yesterday, DateTime.now()));
    final IndividualResource loanToBillTomorrow = loansClient.create(new LoanRequestBuilder().withAgedToLostDelayedBilling(false, tomorrow, DateTime.now()));
    final List<String> filteredLoans = loansClient.getMany(String.format("agedToLostDelayedBilling.dateLostItemShouldBeBilled > \"%s\"", today)).getRecords().stream().map(json -> json.getString("id")).collect(Collectors.toList());
    assertThat(filteredLoans, hasSize(1));
    assertThat(filteredLoans, hasItem(loanToBillTomorrow.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) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 14 with LoanRequestBuilder

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

the class LoansApiTest method canRenewALoan.

@Test
public void canRenewALoan() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    DateTime loanDate = new DateTime(2017, DateTimeConstants.MARCH, 1, 13, 25, 46, DateTimeZone.UTC);
    IndividualResource loan = loansClient.create(new LoanRequestBuilder().withLoanDate(loanDate).withDueDate(loanDate.plus(Period.days(14))).create());
    JsonObject createdLoan = loan.getJson();
    LoanRequestBuilder returnedLoan = LoanRequestBuilder.from(createdLoan).withDueDate(new DateTime(2017, DateTimeConstants.MARCH, 30, 13, 25, 46, DateTimeZone.UTC)).withAction("renewed").withActionComment("test action comment").withItemStatus("Checked out").withRenewalCount(1);
    loansClient.replace(loan.getId(), returnedLoan);
    JsonObject updatedLoan = loansClient.getById(UUID.fromString(loan.getId())).getJson();
    assertThat(updatedLoan.getString("dueDate"), is("2017-03-30T13:25:46.000+00:00"));
    assertThat(updatedLoan, isOpen());
    assertThat("action is not renewed", updatedLoan.getString("action"), is("renewed"));
    assertThat("action comment is incorrect", updatedLoan.getString("actionComment"), is("test action comment"));
    assertThat("renewal count is not 1", updatedLoan.getInteger("renewalCount"), is(1));
    assertThat("item status is not checked out", updatedLoan.getString("itemStatus"), is("Checked out"));
    assertCreateEventForLoan(createdLoan);
    assertUpdateEventForLoan(createdLoan, updatedLoan);
}
Also used : LoanRequestBuilder(org.folio.rest.support.builders.LoanRequestBuilder) JsonObject(io.vertx.core.json.JsonObject) IndividualResource(org.folio.rest.support.IndividualResource) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 15 with LoanRequestBuilder

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

the class LoansApiTest method cannotCreateMultipleOpenLoansForSameItem.

@Test
public void cannotCreateMultipleOpenLoansForSameItem() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    UUID itemId = UUID.randomUUID();
    JsonObject firstLoanRequest = new LoanRequestBuilder().withItemId(itemId).open().create();
    loansClient.create(firstLoanRequest);
    JsonObject firstLoan = loansClient.getById(firstLoanRequest.getString("id")).getJson();
    JsonObject secondLoanRequest = new LoanRequestBuilder().withItemId(itemId).open().create();
    JsonResponse response = loansClient.attemptCreate(secondLoanRequest);
    assertThat(response, isValidationResponseWhich(hasMessage("Cannot have more than one open loan for the same item")));
    assertCreateEventForLoan(firstLoan);
    assertNoLoanEvent(secondLoanRequest.getString("id"));
}
Also used : LoanRequestBuilder(org.folio.rest.support.builders.LoanRequestBuilder) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) JsonResponse(org.folio.rest.support.JsonResponse) 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