Search in sources :

Example 6 with IndividualResource

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

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

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

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

the class LoansApiTest method canCreateAnAlreadyClosedLoanWithoutUserId.

@Test
public void canCreateAnAlreadyClosedLoanWithoutUserId() throws InterruptedException, ExecutionException, TimeoutException, MalformedURLException {
    UUID id = UUID.randomUUID();
    JsonObject loanRequest = new LoanRequestBuilder().withId(id).withNoUserId().closed().create();
    final IndividualResource createLoanResponse = loansClient.create(loanRequest);
    JsonObject loan = createLoanResponse.getJson();
    assertThat(loan, isClosed());
    assertThat("should not have a user ID", loan.containsKey("userId"), is(false));
    assertCreateEventForLoan(loan);
}
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) Test(org.junit.Test)

Example 10 with IndividualResource

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

the class LoansApiTest method canDeleteALoan.

@Test
public void canDeleteALoan() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    UUID id = UUID.randomUUID();
    IndividualResource loanResouce = loansClient.create(new LoanRequestBuilder().withId(id).create());
    loansClient.deleteById(id);
    JsonResponse getResponse = loansClient.attemptGetById(id);
    assertThat(getResponse, isNotFound());
    JsonObject loan = loanResouce.getJson();
    assertCreateEventForLoan(loan);
    assertRemoveEventForLoan(loan);
}
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