Search in sources :

Example 11 with IndividualResource

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

the class LoansApiTest method canSearchByLoanItemStatus.

@Test
public void canSearchByLoanItemStatus() throws Exception {
    final IndividualResource agedToLostLoan = loansClient.create(new LoanRequestBuilder().agedToLost());
    loansClient.create(new LoanRequestBuilder().lostAndPaid());
    final List<String> agedToLostLoans = loansClient.getMany("itemStatus==Aged to lost").getRecords().stream().map(json -> json.getString("id")).collect(Collectors.toList());
    assertThat(agedToLostLoans, hasSize(1));
    assertThat(agedToLostLoans, hasItem(agedToLostLoan.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)

Example 12 with IndividualResource

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

the class LoanPoliciesApiTest method createFixedDueDateSchedule.

private IndividualResource createFixedDueDateSchedule(String name, DateTime from, DateTime to, DateTime dueDate) throws Exception {
    UUID fddId = UUID.randomUUID();
    JsonObject fdd = FixedDueDateApiTest.createFixedDueDate(fddId.toString(), name, "desc");
    JsonObject fddSchedule = FixedDueDateApiTest.createSchedule(from.toString(), to.toString(), dueDate.toString());
    fdd.put(FixedDueDateApiTest.SCHEDULE_SECTION, new JsonArray().add(fddSchedule));
    CompletableFuture<JsonResponse> createCompleted = new CompletableFuture<>();
    client.post(FixedDueDateApiTest.dueDateURL(), fdd, StorageTestSuite.TENANT_ID, ResponseHandler.json(createCompleted));
    JsonResponse response = createCompleted.get(5, TimeUnit.SECONDS);
    assertThat(String.format("Failed to create due date: %s", response.getBody()), response, matchesCreated());
    return new IndividualResource(response);
}
Also used : JsonArray(io.vertx.core.json.JsonArray) 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)

Example 13 with IndividualResource

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

the class LoanPoliciesApiTest method cannotUseHoldAlternateRenewalLoanPeriodForFixedProfile.

@Test
public void cannotUseHoldAlternateRenewalLoanPeriodForFixedProfile() throws Exception {
    DateTime from = DateTime.now().minusMonths(3);
    DateTime to = DateTime.now().plusMonths(3);
    DateTime dueDate = to.plusDays(15);
    IndividualResource fixedDueDateSchedule = createFixedDueDateSchedule("semester_for_fixed_policy", from, to, dueDate);
    LoanPolicyRequestBuilder loanPolicy = emptyPolicy().fixed(fixedDueDateSchedule.getId()).withAlternateFixedDueDateScheduleId(fixedDueDateSchedule.getId()).withHoldsRenewalLoanPeriod(new Period().withDuration(1).withIntervalId(Period.IntervalId.DAYS));
    CompletableFuture<JsonResponse> createCompleted = new CompletableFuture<>();
    client.post(loanPolicyStorageUrl(), loanPolicy.create(), StorageTestSuite.TENANT_ID, ResponseHandler.json(createCompleted));
    JsonResponse postResponse = createCompleted.get(5, TimeUnit.SECONDS);
    assertThat(postResponse.getStatusCode(), is(422));
    assertThat(postResponse.getJson().getJsonArray("errors").getJsonObject(0).getString("message"), is("Alternate Renewal Loan Period for Holds is not allowed for policies with Fixed profile"));
}
Also used : LoanPolicyRequestBuilder(org.folio.rest.support.builders.LoanPolicyRequestBuilder) CompletableFuture(java.util.concurrent.CompletableFuture) org.folio.rest.support.matchers.periodJsonObjectMatcher.matchesPeriod(org.folio.rest.support.matchers.periodJsonObjectMatcher.matchesPeriod) Period(org.folio.rest.jaxrs.model.Period) IndividualResource(org.folio.rest.support.IndividualResource) DateTime(org.joda.time.DateTime) JsonResponse(org.folio.rest.support.JsonResponse) Test(org.junit.Test)

Example 14 with IndividualResource

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

the class CheckInStorageApiTest method canCreateRecordWithoutOptionalParameters.

@Test
public void canCreateRecordWithoutOptionalParameters() throws InterruptedException, ExecutionException, TimeoutException, MalformedURLException {
    JsonObject checkInToCreate = createSampleCheckIn().withItemStatusPriorToCheckIn(null).withItemLocationId(null).withRequestQueueSize(null).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 15 with IndividualResource

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

the class CheckInStorageApiTest method canCreateRecordWithoutId.

@Test
public void canCreateRecordWithoutId() throws InterruptedException, ExecutionException, TimeoutException, MalformedURLException {
    JsonObject checkInToCreate = createSampleCheckIn().withId(null).create();
    IndividualResource createResult = checkInClient.create(checkInToCreate);
    assertThat(createResult.getId(), notNullValue());
    assertThat(createResult.getJson(), hasSameProperties(checkInToCreate));
    assertCreateEventForCheckIn(checkInToCreate);
}
Also used : JsonObject(io.vertx.core.json.JsonObject) 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