use of org.folio.rest.support.JsonResponse in project mod-circulation-storage by folio-org.
the class LoanPoliciesApiTest method canCreateALoanPolicy.
@Test
public void canCreateALoanPolicy() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
CompletableFuture<JsonResponse> createCompleted = new CompletableFuture<>();
UUID id = UUID.randomUUID();
JsonObject loanPolicyRequest = defaultRollingPolicy().withId(id).withName("Example Loan Policy").withDescription("An example loan policy").create();
client.post(loanPolicyStorageUrl(), loanPolicyRequest, StorageTestSuite.TENANT_ID, ResponseHandler.json(createCompleted));
JsonResponse response = createCompleted.get(5, TimeUnit.SECONDS);
assertThat(String.format("Failed to create loan policy: %s", response.getBody()), response, matchesCreated());
JsonObject representation = response.getJson();
assertThat(representation.getString("id"), is(id.toString()));
assertThat(representation.getString("name"), is("Example Loan Policy"));
assertThat(representation.getString("description"), is("An example loan policy"));
assertThat(representation.getBoolean("loanable"), is(true));
assertThat(representation.getBoolean("renewable"), is(true));
assertThat(representation.containsKey("loansPolicy"), is(true));
assertThat(representation.containsKey("metadata"), is(true));
JsonObject loansPolicy = representation.getJsonObject("loansPolicy");
assertThat(loansPolicy.getString("profileId"), is("Rolling"));
assertThat(loansPolicy.getJsonObject("period"), matchesPeriod(1, "Months"));
assertThat(loansPolicy.getString("closedLibraryDueDateManagementId"), is("CURRENT_DUE_DATE"));
assertThat(loansPolicy.getJsonObject("gracePeriod"), matchesPeriod(7, "Days"));
checkRequestManagementSection(representation);
assertThat(representation.containsKey("renewalsPolicy"), is(true));
JsonObject renewalsPolicy = representation.getJsonObject("renewalsPolicy");
assertThat(renewalsPolicy.getBoolean("unlimited"), is(true));
assertThat(renewalsPolicy.getString("renewFromId"), is("CURRENT_DUE_DATE"));
assertThat(renewalsPolicy.getBoolean("differentPeriod"), is(true));
assertThat(renewalsPolicy.getJsonObject("period"), matchesPeriod(30, "Days"));
}
use of org.folio.rest.support.JsonResponse 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);
}
use of org.folio.rest.support.JsonResponse 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);
}
use of org.folio.rest.support.JsonResponse in project mod-circulation-storage by folio-org.
the class LoansApiTest method shouldPopulateChangeMetadataProperties.
@Test
public void shouldPopulateChangeMetadataProperties() throws Exception {
UUID userId = UUID.randomUUID();
UUID itemId = UUID.randomUUID();
UUID id1 = UUID.randomUUID();
UUID id2 = UUID.randomUUID();
UUID id3 = UUID.randomUUID();
JsonObject j1 = new JsonObject().put("id", id1.toString()).put("userId", userId.toString()).put("itemId", itemId.toString()).put("action", "checkedout").put("loanDate", DateTime.parse("2017-03-06T16:04:43.000+02:00", ISODateTimeFormat.dateTime()).toString()).put("status", new JsonObject().put("name", "Closed"));
JsonObject j2 = new JsonObject().put("id", id2.toString()).put("userId", userId.toString()).put("itemId", itemId.toString()).put("action", "renewal").put("loanDate", DateTime.parse("2017-03-06T16:05:43.000+02:00", ISODateTimeFormat.dateTime()).toString()).put("status", new JsonObject().put("name", "Opened"));
JsonObject j3 = new JsonObject().put("id", id3.toString()).put("userId", userId.toString()).put("itemId", itemId.toString()).put("action", "renewal").put("loanDate", DateTime.parse("2017-03-06T16:05:43.000+02:00", ISODateTimeFormat.dateTime()).toString()).put("status", new JsonObject().put("name", "Opened"));
Metadata md = new Metadata();
md.setCreatedByUserId("af23adf0-61ba-4887-bf82-956c4aae2260");
md.setUpdatedByUserId("af23adf0-61ba-4887-bf82-956c4aae2260");
TimeZone tz = TimeZone.getTimeZone("UTC");
DateFormat df = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS+0000");
df.setTimeZone(tz);
Date d = new Date();
String nowAsISO = df.format(d);
md.setCreatedDate(d);
md.setUpdatedDate(d);
j3.put("metadata", JsonObject.mapFrom(md));
CompletableFuture<JsonResponse> create1 = new CompletableFuture<>();
CompletableFuture<JsonResponse> get1 = new CompletableFuture<>();
CompletableFuture<JsonResponse> create2 = new CompletableFuture<>();
CompletableFuture<JsonResponse> get2 = new CompletableFuture<>();
CompletableFuture<JsonResponse> create3 = new CompletableFuture<>();
CompletableFuture<JsonResponse> get3 = new CompletableFuture<>();
// /////////////post loan//////////////////////
client.post(InterfaceUrls.loanStorageUrl(), j1, StorageTestSuite.TENANT_ID, "af23adf0-61ba-4887-bf82-956c4aae2260", ResponseHandler.json(create1));
create1.get(5, TimeUnit.SECONDS);
// ////////////get loan/////////////////////
client.get(InterfaceUrls.loanStorageUrl("/" + id1.toString()), StorageTestSuite.TENANT_ID, ResponseHandler.json(get1));
JsonResponse response2 = get1.get(5, TimeUnit.SECONDS);
assertThat("Metadata section not populated correctly " + id1.toString(), response2.getJson().getJsonObject("metadata").getString("createdByUserId"), is("af23adf0-61ba-4887-bf82-956c4aae2260"));
// /////////////post loan//////////////////////
client.post(InterfaceUrls.loanStorageUrl(), j2, StorageTestSuite.TENANT_ID, null, ResponseHandler.json(create2));
create2.get(5, TimeUnit.SECONDS);
// ////////////get loan/////////////////////
client.get(InterfaceUrls.loanStorageUrl("/" + id2.toString()), StorageTestSuite.TENANT_ID, ResponseHandler.json(get2));
JsonResponse response4 = get2.get(5, TimeUnit.SECONDS);
assertThat("Metadata section not populated correctly " + id2.toString(), response4.getJson().getJsonObject("metadata"), not(nullValue()));
assertThat("Metadata section requires createdDate property " + id2.toString(), response4.getJson().getJsonObject("metadata").containsKey("createdDate"), not(nullValue()));
// /////////////post loan//////////////////////
client.post(InterfaceUrls.loanStorageUrl(), j3, StorageTestSuite.TENANT_ID, "af23adf0-61ba-4887-bf82-956c4aae2260", ResponseHandler.json(create3));
create3.get(5, TimeUnit.SECONDS);
// ////////////get loan/////////////////////
client.get(InterfaceUrls.loanStorageUrl("/" + id3.toString()), StorageTestSuite.TENANT_ID, ResponseHandler.json(get3));
JsonResponse response6 = get3.get(5, TimeUnit.SECONDS);
// server should overwrite the field so should not be equal to what was passed in
assertThat("Metadata section not populated correctly " + id3.toString(), response6.getJson().getJsonObject("metadata").getString("createdDate"), not(nowAsISO));
}
use of org.folio.rest.support.JsonResponse in project mod-circulation-storage by folio-org.
the class LoansApiTest method cannotCreateOpenLoanWithoutUserIdViaPut.
@Test
public void cannotCreateOpenLoanWithoutUserIdViaPut() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
final UUID loanId = UUID.randomUUID();
final LoanRequestBuilder loanRequest = new LoanRequestBuilder().withId(loanId).open().withNoUserId();
final JsonResponse putResponse = loansClient.attemptCreateOrReplace(loanId.toString(), loanRequest);
assertThat(putResponse, isValidationResponseWhich(hasMessage("Open loan must have a user ID")));
assertNoLoanEvent(loanId.toString());
}
Aggregations