Search in sources :

Example 36 with LoanRequestBuilder

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

the class LoansApiTest method cannotCreateMultipleOpenLoansForSameItemViaPutToSpecificLocation.

@Test
public void cannotCreateMultipleOpenLoansForSameItemViaPutToSpecificLocation() 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();
    UUID secondLoanId = UUID.randomUUID();
    JsonObject secondLoanRequest = new LoanRequestBuilder().withId(secondLoanId).withItemId(itemId).open().create();
    JsonResponse createResponse = loansClient.attemptCreateOrReplace(secondLoanId.toString(), secondLoanRequest);
    assertThat(createResponse, isValidationResponseWhich(hasMessage("Cannot have more than one open loan for the same item")));
    assertCreateEventForLoan(firstLoan);
    assertNoLoanEvent(secondLoanId.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 37 with LoanRequestBuilder

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

the class LoansApiTest method cannotCreateOpenLoanWithoutUserId.

@Test
public void cannotCreateOpenLoanWithoutUserId() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    final UUID loanId = UUID.randomUUID();
    final LoanRequestBuilder loanRequest = new LoanRequestBuilder().withId(loanId).open().withNoUserId();
    final JsonResponse putResponse = loansClient.attemptCreate(loanRequest);
    assertThat(putResponse, isValidationResponseWhich(hasMessage("Open loan must have a user ID")));
    assertNoLoanEvent(loanId.toString());
}
Also used : LoanRequestBuilder(org.folio.rest.support.builders.LoanRequestBuilder) UUID(java.util.UUID) JsonResponse(org.folio.rest.support.JsonResponse) Test(org.junit.Test)

Example 38 with LoanRequestBuilder

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

the class LoansApiTest method canCreateALoanWithOnlyRequiredProperties.

@Test
public void canCreateALoanWithOnlyRequiredProperties() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
    UUID id = UUID.randomUUID();
    JsonObject loanRequest = new LoanRequestBuilder().withId(id).withNoStatus().withNoItemStatus().withLoanDate(new DateTime(2017, 3, 5, 14, 23, 41, DateTimeZone.UTC)).withAction("checkedout").create();
    loansClient.create(loanRequest);
    JsonObject loan = loansClient.getById(id).getJson();
    assertThat("id does not match", loan.getString("id"), is(id.toString()));
    assertThat(loan, isOpen());
    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 39 with LoanRequestBuilder

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

the class LoansApiTest method canCreateMultipleClosedLoansForSameItem.

@Test
public void canCreateMultipleClosedLoansForSameItem() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    UUID itemId = UUID.randomUUID();
    JsonObject firstLoanRequest = new LoanRequestBuilder().withItemId(itemId).closed().create();
    loansClient.create(firstLoanRequest);
    JsonObject firstLoan = loansClient.getById(firstLoanRequest.getString("id")).getJson();
    JsonObject secondLoanRequest = new LoanRequestBuilder().withItemId(itemId).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 40 with LoanRequestBuilder

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

the class LoansApiTest method canCreateALoanAtViaPutToSpecificLocation.

@Test
public void canCreateALoanAtViaPutToSpecificLocation() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
    UUID id = UUID.randomUUID();
    UUID itemId = UUID.randomUUID();
    UUID userId = UUID.randomUUID();
    UUID proxyUserId = UUID.randomUUID();
    JsonObject loanRequest = new LoanRequestBuilder().withId(id).withItemId(itemId).withUserId(userId).withProxyUserId(proxyUserId).withLoanDate(new DateTime(2017, 2, 27, 21, 14, 43, DateTimeZone.UTC)).open().withAction("checkedout").withItemStatus("Checked out").withDueDate(new DateTime(2017, 3, 29, 21, 14, 43, DateTimeZone.UTC)).create();
    loansClient.createAtSpecificLocation(id, loanRequest);
    JsonObject loan = loansClient.getById(id).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-02-27T21:14:43.000Z"));
    assertThat(loan, isOpen());
    assertThat("action is not checked out", loan.getString("action"), is("checkedout"));
    assertThat("due date does not match", loan.getString("dueDate"), is("2017-03-29T21:14:43.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)

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