Search in sources :

Example 81 with IndividualResource

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

the class LoansApiTest method cannotUpdateALoanWithInvalidDates.

@Test
public void cannotUpdateALoanWithInvalidDates() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    IndividualResource loan = loansClient.create(loanRequest());
    JsonObject changedLoan = loan.copyJson();
    changedLoan.put("loanDate", "bar");
    changedLoan.put("returnDate", "foo");
    final JsonResponse response = loansClient.attemptCreateOrReplace(loan.getId(), changedLoan);
    assertThat(response, isBadRequest());
    // TODO: Convert these to validation responses
    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)"));
    JsonObject created = loan.getJson();
    assertCreateEventForLoan(created);
    assertLoanEventCount(created.getString("id"), 1);
}
Also used : JsonObject(io.vertx.core.json.JsonObject) IndividualResource(org.folio.rest.support.IndividualResource) JsonResponse(org.folio.rest.support.JsonResponse) Test(org.junit.Test)

Example 82 with IndividualResource

use of org.folio.rest.support.IndividualResource 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 83 with IndividualResource

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

the class CheckInStorageApiTest method canCreateCheckIn.

@Test
public void canCreateCheckIn() throws InterruptedException, ExecutionException, TimeoutException, MalformedURLException {
    JsonObject checkInToCreate = createSampleCheckIn().create();
    IndividualResource createResult = checkInClient.create(checkInToCreate);
    assertThat(createResult.getJson(), is(checkInToCreate));
    assertCreateEventForCheckIn(checkInToCreate);
}
Also used : JsonObject(io.vertx.core.json.JsonObject) IndividualResource(org.folio.rest.support.IndividualResource) Test(org.junit.Test)

Example 84 with IndividualResource

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

the class RequestsApiTest method cannotUpdateRequestForSameItemToAnExistingPosition.

@Test
public void cannotUpdateRequestForSameItemToAnExistingPosition() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    UUID itemId = UUID.randomUUID();
    createEntity(new RequestRequestBuilder().withItemId(itemId).withPosition(1).create(), requestStorageUrl());
    final IndividualResource secondRequest = createEntity(new RequestRequestBuilder().withItemId(itemId).withPosition(2).create(), requestStorageUrl());
    final JsonObject changedSecondRequest = secondRequest.getJson().put("position", 1);
    CompletableFuture<JsonResponse> updateCompleted = new CompletableFuture<>();
    client.put(requestStorageUrl(String.format("/%s", secondRequest.getId())), changedSecondRequest, TENANT_ID, ResponseHandler.json(updateCompleted));
    JsonResponse response = updateCompleted.get(5, TimeUnit.SECONDS);
    assertThat(response, isValidationResponseWhich(hasMessage("Cannot have more than one request with the same position in the queue")));
}
Also used : RequestRequestBuilder(org.folio.rest.support.builders.RequestRequestBuilder) CompletableFuture(java.util.concurrent.CompletableFuture) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) IndividualResource(org.folio.rest.support.IndividualResource) JsonResponse(org.folio.rest.support.JsonResponse) Test(org.junit.Test)

Example 85 with IndividualResource

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

the class LoansApiTest method cannotReopenLoanWhenOpenLoanForSameItem.

@Test
public void cannotReopenLoanWhenOpenLoanForSameItem() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    UUID itemId = UUID.randomUUID();
    JsonObject openLoanRequest = new LoanRequestBuilder().withItemId(itemId).open().create();
    IndividualResource openLoan = loansClient.create(openLoanRequest);
    JsonObject closedLoanRequest = new LoanRequestBuilder().withItemId(itemId).closed().create();
    IndividualResource closedLoan = loansClient.create(closedLoanRequest);
    JsonObject closed = closedLoan.getJson();
    LoanRequestBuilder reopenLoanRequest = LoanRequestBuilder.from(closed).open();
    JsonResponse replaceResponse = loansClient.attemptCreateOrReplace(closedLoan.getId(), reopenLoanRequest.create());
    assertThat(replaceResponse, isValidationResponseWhich(hasMessage("Cannot have more than one open loan for the same item")));
    assertCreateEventForLoan(openLoan.getJson());
    assertCreateEventForLoan(closed);
    assertLoanEventCount(closed.getString("id"), 1);
}
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) JsonResponse(org.folio.rest.support.JsonResponse) Test(org.junit.Test)

Aggregations

IndividualResource (org.folio.rest.support.IndividualResource)89 Test (org.junit.Test)73 JsonObject (io.vertx.core.json.JsonObject)44 UUID (java.util.UUID)37 Response (org.folio.rest.support.Response)20 CompletableFuture (java.util.concurrent.CompletableFuture)19 JsonArray (io.vertx.core.json.JsonArray)17 JsonResponse (org.folio.rest.support.JsonResponse)17 LoanRequestBuilder (org.folio.rest.support.builders.LoanRequestBuilder)17 DateTime (org.joda.time.DateTime)12 PrecedingSucceedingTitle (org.folio.rest.api.entities.PrecedingSucceedingTitle)11 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)11 TextResponse (org.folio.rest.support.TextResponse)7 ItemRequestBuilder (org.folio.rest.support.builders.ItemRequestBuilder)7 InstancesBatchResponse (org.folio.rest.jaxrs.model.InstancesBatchResponse)6 JsonErrorResponse (org.folio.rest.support.JsonErrorResponse)6 TRUE (java.lang.Boolean.TRUE)4 HttpURLConnection (java.net.HttpURLConnection)4 MalformedURLException (java.net.MalformedURLException)4 DateFormat (java.text.DateFormat)4