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);
}
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"));
}
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")));
}
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"));
}
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()));
}
Aggregations