Search in sources :

Example 91 with JsonResponse

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));
}
Also used : SendBy(org.folio.rest.jaxrs.model.SendBy) LoanNotice(org.folio.rest.jaxrs.model.LoanNotice) SendOptions(org.folio.rest.jaxrs.model.SendOptions) JsonResponse(org.folio.rest.support.JsonResponse) PatronNoticePolicy(org.folio.rest.jaxrs.model.PatronNoticePolicy) Test(org.junit.Test)

Example 92 with JsonResponse

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));
}
Also used : JsonObject(io.vertx.core.json.JsonObject) JsonResponse(org.folio.rest.support.JsonResponse) Test(org.junit.Test)

Example 93 with JsonResponse

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));
}
Also used : JsonArray(io.vertx.core.json.JsonArray) JsonObject(io.vertx.core.json.JsonObject) JsonResponse(org.folio.rest.support.JsonResponse) Test(org.junit.Test)

Example 94 with JsonResponse

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());
}
Also used : JsonResponse(org.folio.rest.support.JsonResponse) Test(org.junit.Test)

Example 95 with JsonResponse

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")));
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) JsonResponse(org.folio.rest.support.JsonResponse) Test(org.junit.Test)

Aggregations

JsonResponse (org.folio.rest.support.JsonResponse)156 Test (org.junit.Test)133 JsonObject (io.vertx.core.json.JsonObject)91 CompletableFuture (java.util.concurrent.CompletableFuture)91 UUID (java.util.UUID)52 RequestRequestBuilder (org.folio.rest.support.builders.RequestRequestBuilder)20 JsonArray (io.vertx.core.json.JsonArray)19 RequestPolicy (org.folio.rest.jaxrs.model.RequestPolicy)18 IndividualResource (org.folio.rest.support.IndividualResource)15 LoanRequestBuilder (org.folio.rest.support.builders.LoanRequestBuilder)12 URL (java.net.URL)11 RequestType (org.folio.rest.jaxrs.model.RequestType)10 RequestPreference (org.folio.rest.jaxrs.model.RequestPreference)9 StaffSlipRequestBuilder (org.folio.rest.support.builders.StaffSlipRequestBuilder)9 Response (org.folio.rest.support.Response)8 ResponseHandler (org.folio.rest.support.ResponseHandler)8 DateTime (org.joda.time.DateTime)7 MalformedURLException (java.net.MalformedURLException)6 ExecutionException (java.util.concurrent.ExecutionException)6 TimeoutException (java.util.concurrent.TimeoutException)6