Search in sources :

Example 76 with IndividualResource

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

the class RequestsApiTest method updatedRequestHasUpdatedMetadata.

@Test
public void updatedRequestHasUpdatedMetadata() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    UUID id = UUID.randomUUID();
    JsonObject request = new RequestRequestBuilder().withId(id).create();
    IndividualResource createResponse = createEntity(request, requestStorageUrl());
    JsonObject createdRequest = createResponse.getJson();
    JsonObject createdMetadata = createdRequest.getJsonObject(METADATA_PROPERTY);
    CompletableFuture<TextResponse> updateCompleted = new CompletableFuture<>();
    String updaterId = UUID.randomUUID().toString();
    DateTime requestMade = DateTime.now();
    client.put(requestStorageUrl(String.format("/%s", id)), request, TENANT_ID, updaterId, ResponseHandler.text(updateCompleted));
    TextResponse response = updateCompleted.get(5, TimeUnit.SECONDS);
    assertThat(String.format("Failed to update request: %s", response.getBody()), response.getStatusCode(), is(HttpURLConnection.HTTP_NO_CONTENT));
    JsonObject updatedRequest = getById(requestStorageUrl(String.format("/%s", id)));
    assertThat("Request should have metadata property", updatedRequest.containsKey(METADATA_PROPERTY), is(true));
    JsonObject metadata = updatedRequest.getJsonObject(METADATA_PROPERTY);
    assertThat("Request should have same created user", metadata.getString("createdByUserId"), is(createdMetadata.getString("createdByUserId")));
    assertThat("Request should have same created date", metadata.getString("createdDate"), is(createdMetadata.getString("createdDate")));
    assertThat("Request should have updated user", metadata.getString("updatedByUserId"), is(updaterId));
    assertThat("Request should have updated date close to when request was made", metadata.getString("updatedDate"), is(withinSecondsAfter(Seconds.seconds(2), requestMade)));
    assertThat("Request should have updated date different to original updated date", metadata.getString("updatedDate"), is(not(createdMetadata.getString("updatedDate"))));
    assertUpdateEventForRequest(createdRequest, updatedRequest);
}
Also used : RequestRequestBuilder(org.folio.rest.support.builders.RequestRequestBuilder) CompletableFuture(java.util.concurrent.CompletableFuture) JsonObject(io.vertx.core.json.JsonObject) TextResponse(org.folio.rest.support.TextResponse) UUID(java.util.UUID) IndividualResource(org.folio.rest.support.IndividualResource) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 77 with IndividualResource

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

the class PatronActionSessionAPITest method canUpdatePatronActiveSession.

@Test
public void canUpdatePatronActiveSession() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    JsonObject request = createPatronActionSession("Check-out");
    String id = assertRecordClient.create(request).getJson().getString("id");
    request.put("loanId", existingLoanId).put("actionType", "Check-in");
    JsonResponse response = assertRecordClient.attemptPutById(request);
    assertThat("Failed to update patron active session", response.getStatusCode(), is(204));
    IndividualResource updatedPatronActionSession = assertRecordClient.getById(id);
    assertThat(updatedPatronActionSession.getJson().getString("loanId"), is(existingLoanId));
    assertThat(updatedPatronActionSession.getJson().getString("actionType"), is("Check-in"));
}
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 78 with IndividualResource

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

the class PatronActionSessionAPITest method canGetPatronActionSession.

@Test
public void canGetPatronActionSession() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    JsonObject session = createPatronActionSession("Check-out");
    String id = assertRecordClient.create(session).getJson().getString("id");
    IndividualResource individualResource = assertRecordClient.getById(id);
    assertThat(individualResource.getJson().getString("id"), is(id));
    assertThat(individualResource.getJson().getString("patronId"), is(session.getString("patronId")));
}
Also used : JsonObject(io.vertx.core.json.JsonObject) IndividualResource(org.folio.rest.support.IndividualResource) Test(org.junit.Test)

Example 79 with IndividualResource

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

the class LoanPoliciesApiTest method cannotUseRenewalsPeriodForFixedProfile.

@Test
public void cannotUseRenewalsPeriodForFixedProfile() throws Exception {
    DateTime from = DateTime.now().minusMonths(3);
    DateTime to = DateTime.now().plusMonths(3);
    DateTime dueDate = to.plusDays(15);
    IndividualResource fixedDueDateSchedule = createFixedDueDateSchedule("semester fixed policy test", from, to, dueDate);
    LoanPolicyRequestBuilder loanPolicy = emptyPolicy().fixed(fixedDueDateSchedule.getId()).withAlternateFixedDueDateScheduleId(fixedDueDateSchedule.getId()).withName("test").withRenewalPeriod(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("Period in RenewalsPolicy 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 80 with IndividualResource

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

the class LoansApiTest method canSearchByLoanAgedToLostItemHasBeenBilled.

@Test
public void canSearchByLoanAgedToLostItemHasBeenBilled() throws Exception {
    final IndividualResource billedLoan = loansClient.create(new LoanRequestBuilder().withAgedToLostDelayedBilling(true, DateTime.now(), DateTime.now()));
    loansClient.create(new LoanRequestBuilder().withAgedToLostDelayedBilling(false, DateTime.now(), DateTime.now()));
    final List<String> billedLoans = loansClient.getMany("agedToLostDelayedBilling.lostItemHasBeenBilled==true").getRecords().stream().map(json -> json.getString("id")).collect(Collectors.toList());
    assertThat(billedLoans, hasSize(1));
    assertThat(billedLoans, hasItem(billedLoan.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