use of org.folio.rest.support.JsonResponse in project mod-circulation-storage by folio-org.
the class PatronNoticePoliciesApiTest method canCreateAndUpdatePatronNoticePolicyWithLoanAgedToLostNotices.
@Test
public void canCreateAndUpdatePatronNoticePolicyWithLoanAgedToLostNotices() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
final PatronNoticePolicy patronNoticePolicy = new PatronNoticePolicy().withId(UUID.randomUUID().toString()).withName("Test policy").withActive(true).withDescription("Test policy description").withLoanNotices(new ArrayList<>(List.of(new LoanNotice().withName("Aged to lost UPON/AT").withRealTime(true).withFormat(LoanNotice.Format.EMAIL).withTemplateName("Aged to lost UPON/AT template").withTemplateId(UUID.randomUUID().toString()).withSendOptions(new SendOptions().withSendHow(SendOptions.SendHow.UPON_AT).withSendWhen(SendOptions.SendWhen.AGED_TO_LOST)), new LoanNotice().withName("Aged to lost AFTER/ONCE").withFrequency(LoanNotice.Frequency.ONE_TIME).withRealTime(true).withFormat(LoanNotice.Format.EMAIL).withTemplateName("Aged to lost AFTER/ONCE template").withTemplateId(UUID.randomUUID().toString()).withSendOptions(new SendOptions().withSendHow(SendOptions.SendHow.AFTER).withSendWhen(SendOptions.SendWhen.AGED_TO_LOST).withSendBy(new SendBy().withDuration(1).withIntervalId(SendBy.IntervalId.DAYS))))));
JsonResponse postResponse = postPatronNoticePolicy(mapFrom(patronNoticePolicy));
assertThat(postResponse.getStatusCode(), is(201));
patronNoticePolicy.getLoanNotices().add(new LoanNotice().withName("Aged to lost AFTER/RECURRING").withFrequency(LoanNotice.Frequency.RECURRING).withRealTime(true).withFormat(LoanNotice.Format.EMAIL).withTemplateName("Aged to lost AFTER/RECURRING template").withTemplateId(UUID.randomUUID().toString()).withSendOptions(new SendOptions().withSendHow(SendOptions.SendHow.AFTER).withSendWhen(SendOptions.SendWhen.AGED_TO_LOST).withSendBy(new SendBy().withDuration(1).withIntervalId(SendBy.IntervalId.DAYS)).withSendEvery(new SendBy().withDuration(2).withIntervalId(SendBy.IntervalId.HOURS))));
JsonResponse putResponse = putPatronNoticePolicy(mapFrom(patronNoticePolicy));
assertThat(putResponse.getStatusCode(), is(204));
}
use of org.folio.rest.support.JsonResponse in project mod-circulation-storage by folio-org.
the class PatronNoticePoliciesApiTest method cannotUpdateNonexistentPatronNoticePolicy.
@Test
public void cannotUpdateNonexistentPatronNoticePolicy() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
JsonObject nonexistentPolicy = new JsonObject().put("id", UUID.randomUUID().toString()).put("name", "nonexistentPolicy");
JsonResponse response = putPatronNoticePolicy(nonexistentPolicy);
assertThat(response.getStatusCode(), is(404));
}
use of org.folio.rest.support.JsonResponse in project mod-circulation-storage by folio-org.
the class PatronNoticePoliciesApiTest method canCreatePatronNoticePolicy.
@Test
public void canCreatePatronNoticePolicy() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
JsonObject sendOptions = new JsonObject().put("sendWhen", "Request expiration");
JsonObject requestNotice = new JsonObject().put("templateId", UUID.randomUUID().toString()).put("format", "Email").put("realTime", "true").put("sendOptions", sendOptions);
JsonObject manualDueDateChangeNotice = new JsonObject().put("templateId", UUID.randomUUID().toString()).put("format", "Email").put("realTime", "true").put("sendOptions", new JsonObject().put("sendWhen", "Manual due date change"));
JsonObject itemRecalledNotice = new JsonObject().put("templateId", UUID.randomUUID().toString()).put("format", "Email").put("realTime", "true").put("sendOptions", new JsonObject().put("sendWhen", "Item recalled"));
JsonObject agedToLostNotice = new JsonObject().put("templateId", UUID.randomUUID().toString()).put("format", "Email").put("realTime", "true").put("sendOptions", new JsonObject().put("sendWhen", "Aged to lost"));
JsonObject holdExpirationChangeNotice = new JsonObject().put("templateId", UUID.randomUUID().toString()).put("format", "Email").put("realTime", "true").put("sendOptions", new JsonObject().put("sendWhen", "Hold expiration"));
JsonObject oneTimeOverdueFineReturnedNotice = new JsonObject().put("templateId", UUID.randomUUID().toString()).put("format", "Email").put("realTime", true).put("frequency", "One time").put("sendOptions", new JsonObject().put("sendWhen", "Overdue fine returned").put("sendHow", "Upon At"));
JsonObject recurringOverdueFineRenewedNotice = new JsonObject().put("templateId", UUID.randomUUID().toString()).put("format", "Email").put("realTime", true).put("frequency", "Recurring").put("sendOptions", new JsonObject().put("sendWhen", "Overdue fine renewed").put("sendHow", "After").put("sendBy", new JsonObject().put("intervalId", "Days").put("duration", 1)).put("sendEvery", new JsonObject().put("intervalId", "Hours").put("duration", 6)));
JsonObject noticePolicy = new JsonObject().put("name", "sample policy").put("requestNotices", new JsonArray().add(requestNotice).add(holdExpirationChangeNotice)).put("loanNotices", new JsonArray().add(manualDueDateChangeNotice).add(itemRecalledNotice).add(agedToLostNotice)).put("feeFineNotices", new JsonArray().add(oneTimeOverdueFineReturnedNotice).add(recurringOverdueFineRenewedNotice));
JsonResponse response = postPatronNoticePolicy(noticePolicy);
assertThat("Failed to create patron notice policy", response.getStatusCode(), is(201));
}
use of org.folio.rest.support.JsonResponse in project mod-circulation-storage by folio-org.
the class LoanPoliciesApiTest method cannotGetLoanPolicyForUnknownId.
@Test
public void cannotGetLoanPolicyForUnknownId() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
JsonResponse getResponse = getById(UUID.randomUUID());
assertThat(getResponse, matchesNotFound());
}
use of org.folio.rest.support.JsonResponse in project mod-circulation-storage by folio-org.
the class LoanPoliciesApiTest method cannotUpdateWhenFixedIsRenewable.
@Test
public void cannotUpdateWhenFixedIsRenewable() throws Exception {
UUID id = UUID.randomUUID();
CompletableFuture<JsonResponse> completed = new CompletableFuture<>();
JsonObject loanPolicy = defaultRollingPolicy().withId(id).create();
createLoanPolicy(loanPolicy);
loanPolicy.getJsonObject("loansPolicy").put("profileId", "Fixed");
client.put(loanPolicyStorageUrl("/" + id), loanPolicy, StorageTestSuite.TENANT_ID, ResponseHandler.json(completed));
JsonResponse response = completed.get(5, TimeUnit.SECONDS);
String message = String.format("update when fixed is renewable, PUT request=%s, response=%s", loanPolicy.encodePrettily(), response.getJson().encodePrettily());
assertThat(message, response, matchesUnprocessableEntity());
assertThat(message, response.getJson(), hasErrorWith(hasMessageContaining("profile is Fixed")));
}
Aggregations