Search in sources :

Example 1 with IndividualResource

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

the class LoanPoliciesApiTest method createLoanPolicy.

private IndividualResource createLoanPolicy(JsonObject loanPolicyRequest) throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
    CompletableFuture<JsonResponse> createCompleted = new CompletableFuture<>();
    client.post(loanPolicyStorageUrl(), loanPolicyRequest, StorageTestSuite.TENANT_ID, ResponseHandler.json(createCompleted));
    JsonResponse postResponse = createCompleted.get(5, TimeUnit.SECONDS);
    assertThat(String.format("Failed to create loan policy: %s", postResponse.getBody()), postResponse, matchesCreated());
    return new IndividualResource(postResponse);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) IndividualResource(org.folio.rest.support.IndividualResource) JsonResponse(org.folio.rest.support.JsonResponse)

Example 2 with IndividualResource

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

the class LoansApiTest method canRemoveUserIdFromClosedLoan.

@Test
public void canRemoveUserIdFromClosedLoan() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    DateTime loanDate = new DateTime(2017, 3, 1, 13, 25, 46, 232, DateTimeZone.UTC);
    final UUID loanId = UUID.randomUUID();
    final UUID userId = UUID.randomUUID();
    IndividualResource loan = loansClient.create(new LoanRequestBuilder().withId(loanId).withUserId(userId).withLoanDate(loanDate).withDueDate(loanDate.plus(Period.days(14))).open().create());
    final LoanRequestBuilder closedLoanRequest = LoanRequestBuilder.from(loan.getJson()).closed();
    loansClient.replace(loanId.toString(), closedLoanRequest);
    final IndividualResource closedLoan = loansClient.getById(loanId);
    final LoanRequestBuilder anonymisedLoanRequest = LoanRequestBuilder.from(closedLoan.getJson()).withNoUserId();
    loansClient.replace(loanId.toString(), anonymisedLoanRequest);
    final IndividualResource anonymisedLoan = loansClient.getById(loanId);
    assertThat(anonymisedLoan.getJson(), isClosed());
    assertThat("Should not have a user ID", anonymisedLoan.getJson().containsKey("userId"), is(false));
    assertCreateEventForLoan(loan.getJson());
    assertUpdateEventForLoan(closedLoan.getJson(), anonymisedLoan.getJson());
}
Also used : LoanRequestBuilder(org.folio.rest.support.builders.LoanRequestBuilder) UUID(java.util.UUID) IndividualResource(org.folio.rest.support.IndividualResource) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 3 with IndividualResource

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

the class LoansApiTest method cannotRemoveUserIdFromOpenLoan.

@Test
public void cannotRemoveUserIdFromOpenLoan() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    final UUID loanId = UUID.randomUUID();
    final UUID userId = UUID.randomUUID();
    IndividualResource loan = loansClient.create(new LoanRequestBuilder().withId(loanId).withUserId(userId).open().create());
    final LoanRequestBuilder loanRequestWithoutId = LoanRequestBuilder.from(loan.getJson()).withNoUserId();
    final JsonResponse putResponse = loansClient.attemptCreateOrReplace(loanId.toString(), loanRequestWithoutId);
    assertThat(putResponse, isValidationResponseWhich(hasMessage("Open loan must have a user ID")));
    assertCreateEventForLoan(loan.getJson());
    assertLoanEventCount(loanId.toString(), 1);
}
Also used : LoanRequestBuilder(org.folio.rest.support.builders.LoanRequestBuilder) UUID(java.util.UUID) IndividualResource(org.folio.rest.support.IndividualResource) JsonResponse(org.folio.rest.support.JsonResponse) Test(org.junit.Test)

Example 4 with IndividualResource

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

the class LoansApiTest method returnDateIsMandatoryForClosedLoans.

@Test
@Ignore("Should conditional field validation be done in a storage module?")
public void returnDateIsMandatoryForClosedLoans() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    DateTime loanDate = new DateTime(2017, 3, 1, 13, 25, 46, 232, DateTimeZone.UTC);
    IndividualResource loan = loansClient.create(new LoanRequestBuilder().withLoanDate(loanDate).withDueDate(loanDate.plus(Period.days(14))).create());
    LoanRequestBuilder returnedLoan = LoanRequestBuilder.from(loan.copyJson()).closed();
    CompletableFuture<TextResponse> putCompleted = new CompletableFuture<>();
    client.put(InterfaceUrls.loanStorageUrl(String.format("/%s", loan.getId())), returnedLoan.create(), StorageTestSuite.TENANT_ID, ResponseHandler.text(putCompleted));
    TextResponse response = putCompleted.get(5, TimeUnit.SECONDS);
    assertThat(String.format("Should have failed to update loan: %s", response.getBody()), response.getStatusCode(), is(HttpURLConnection.HTTP_BAD_REQUEST));
    assertThat(response.getBody(), containsString("return date is mandatory to close a loan"));
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) LoanRequestBuilder(org.folio.rest.support.builders.LoanRequestBuilder) TextResponse(org.folio.rest.support.TextResponse) IndividualResource(org.folio.rest.support.IndividualResource) DateTime(org.joda.time.DateTime) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 5 with IndividualResource

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

the class LoansApiTest method canSearchByLoanStatus.

@Test
public void canSearchByLoanStatus() throws Exception {
    final IndividualResource openLoan = loansClient.create(new LoanRequestBuilder().checkedOut());
    loansClient.create(new LoanRequestBuilder().checkedIn());
    final List<String> openLoans = loansClient.getMany("status.name==Open").getRecords().stream().map(json -> json.getString("id")).collect(Collectors.toList());
    assertThat(openLoans, hasSize(1));
    assertThat(openLoans, hasItem(openLoan.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) 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