Search in sources :

Example 31 with LoanRequestBuilder

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

the class LoansApiTest method canCreateClosedLoanWhenOpenLoanForDifferentItem.

@Test
public void canCreateClosedLoanWhenOpenLoanForDifferentItem() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    UUID firstItemId = UUID.randomUUID();
    UUID secondItemId = UUID.randomUUID();
    JsonObject firstLoanRequest = new LoanRequestBuilder().withItemId(firstItemId).open().create();
    loansClient.create(firstLoanRequest);
    JsonObject firstLoan = loansClient.getById(firstLoanRequest.getString("id")).getJson();
    JsonObject secondLoanRequest = new LoanRequestBuilder().withItemId(secondItemId).closed().create();
    loansClient.create(secondLoanRequest);
    JsonObject secondLoan = loansClient.getById(secondLoanRequest.getString("id")).getJson();
    assertCreateEventForLoan(firstLoan);
    assertCreateEventForLoan(secondLoan);
}
Also used : LoanRequestBuilder(org.folio.rest.support.builders.LoanRequestBuilder) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) Test(org.junit.Test)

Example 32 with LoanRequestBuilder

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

the class LoansApiTest method canCloseALoanByReturningTheItem.

@Test
public void canCloseALoanByReturningTheItem() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    DateTime loanDate = new DateTime(2017, 3, 1, 13, 25, 46, 232, DateTimeZone.UTC);
    final UUID userId = UUID.randomUUID();
    IndividualResource loan = loansClient.create(new LoanRequestBuilder().withUserId(userId).withLoanDate(loanDate).withDueDate(loanDate.plus(Period.days(14))).create());
    JsonObject createdLoan = loan.copyJson();
    LoanRequestBuilder returnedLoan = LoanRequestBuilder.from(createdLoan).closed().withAction("checkedin").withItemStatus("Available").withReturnDate(new DateTime(2017, 3, 5, 14, 23, 41, DateTimeZone.UTC));
    loansClient.replace(loan.getId(), returnedLoan);
    JsonObject updatedLoan = loansClient.getById(UUID.fromString(loan.getId())).getJson();
    assertThat(updatedLoan.getString("userId"), is(userId.toString()));
    assertThat(updatedLoan.getString("returnDate"), is("2017-03-05T14:23:41.000Z"));
    assertThat(updatedLoan, isClosed());
    assertThat("item status is not available", updatedLoan.getString("itemStatus"), is("Available"));
    assertThat("action is not checkedin", updatedLoan.getString("action"), is("checkedin"));
    assertCreateEventForLoan(createdLoan);
    assertUpdateEventForLoan(createdLoan, updatedLoan);
}
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) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 33 with LoanRequestBuilder

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

the class LoansApiTest method cannotProvideAdditionalPropertiesInLoan.

@Test
public void cannotProvideAdditionalPropertiesInLoan() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    UUID id = UUID.randomUUID();
    JsonObject requestWithAdditionalProperty = new LoanRequestBuilder().withId(id).create();
    requestWithAdditionalProperty.put("somethingAdditional", "foo");
    JsonResponse response = loansClient.attemptCreate(requestWithAdditionalProperty);
    assertThat(response, isValidationResponseWhich(hasMessageContaining("Unrecognized field")));
    assertNoLoanEvent(id.toString());
}
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)

Example 34 with LoanRequestBuilder

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

the class LoansApiTest method canCreateALoan.

@Test
public void canCreateALoan() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
    UUID id = UUID.randomUUID();
    UUID itemId = UUID.randomUUID();
    UUID itemLocationAtCheckOut = UUID.randomUUID();
    UUID userId = UUID.randomUUID();
    UUID proxyUserId = UUID.randomUUID();
    UUID loanPolicyId = UUID.randomUUID();
    DateTime expectedLostDate = DateTime.now();
    UUID overdueFinePolicyId = UUID.randomUUID();
    UUID lostItemPolicyId = UUID.randomUUID();
    final DateTime claimedReturnedDate = DateTime.now(DateTimeZone.UTC);
    final DateTime agedToLostDate = DateTime.now(DateTimeZone.UTC).minusDays(10);
    DateTime dateLostItemShouldBeBilled = new DateTime(2017, 9, 27, 10, 23, 43, DateTimeZone.UTC);
    JsonObject loanRequest = new LoanRequestBuilder().withId(id).withItemId(itemId).withUserId(userId).withProxyUserId(proxyUserId).withLoanDate(new DateTime(2017, 6, 27, 10, 23, 43, DateTimeZone.UTC)).open().withAction("checkedout").withItemStatus("Checked out").withDueDate(new DateTime(2017, 7, 27, 10, 23, 43, DateTimeZone.UTC)).withItemEffectiveLocationIdAtCheckOut(itemLocationAtCheckOut).withLoanPolicyId(loanPolicyId).withDeclaredLostDate(expectedLostDate).withOverdueFinePolicyId(overdueFinePolicyId).withLostItemPolicyId(lostItemPolicyId).withClaimedReturnedDate(claimedReturnedDate).withAgedToLostDelayedBilling(false, dateLostItemShouldBeBilled, agedToLostDate).create();
    JsonObject loan = loansClient.create(loanRequest).getJson();
    assertThat("id does not match", loan.getString("id"), is(id.toString()));
    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-06-27T10:23:43.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("itemEffectiveLocationIdAtCheckOut does not match", loan.getString("itemEffectiveLocationIdAtCheckOut"), is(itemLocationAtCheckOut.toString()));
    assertThat("loan policy should be set", loan.getString("loanPolicyId"), is(loanPolicyId.toString()));
    assertThat("due date does not match", loan.getString("dueDate"), is("2017-07-27T10:23:43.000+00:00"));
    assertThat("recall changed due date should be null", loan.getBoolean("dueDateChangedByRecall"), nullValue());
    assertThat("Loan should have a declaredLostDate property", DateTime.parse(loansClient.getById(id).getJson().getString("declaredLostDate")).getMillis(), is(expectedLostDate.getMillis()));
    assertThat("Overdue fine policy id should be set", loan.getString("overdueFinePolicyId"), is(overdueFinePolicyId.toString()));
    assertThat("Lost item policy id should be set", loan.getString("lostItemPolicyId"), is(lostItemPolicyId.toString()));
    assertThat(parse(loan.getString("claimedReturnedDate")), is(claimedReturnedDate));
    final JsonObject agedToLostDelayedBilling = loan.getJsonObject("agedToLostDelayedBilling");
    assertThat(agedToLostDelayedBilling.getBoolean("lostItemHasBeenBilled"), is(false));
    assertThat(parse(agedToLostDelayedBilling.getString("dateLostItemShouldBeBilled")), is(dateLostItemShouldBeBilled));
    assertThat(parse(agedToLostDelayedBilling.getString("agedToLostDate")), is(agedToLostDate));
    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 35 with LoanRequestBuilder

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

the class LoansApiTest method canCreateALoanWithDueDateChangedByRecallSet.

@Test
public void canCreateALoanWithDueDateChangedByRecallSet() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
    UUID id = UUID.randomUUID();
    UUID itemId = UUID.randomUUID();
    UUID userId = UUID.randomUUID();
    UUID proxyUserId = UUID.randomUUID();
    UUID loanPolicyId = UUID.randomUUID();
    JsonObject loanRequest = new LoanRequestBuilder().withId(id).withItemId(itemId).withUserId(userId).withProxyUserId(proxyUserId).withLoanDate(new DateTime(2017, 6, 27, 10, 23, 43, DateTimeZone.UTC)).open().withAction("checkedout").withItemStatus("Checked out").withDueDate(new DateTime(2017, 7, 27, 10, 23, 43, DateTimeZone.UTC)).withLoanPolicyId(loanPolicyId).withDueDateChangedByRecall(TRUE).create();
    JsonObject loan = loansClient.create(loanRequest).getJson();
    assertThat("recall changed due date is not true", loan.getBoolean("dueDateChangedByRecall"), is(TRUE));
    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)

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