Search in sources :

Example 21 with JsonResponse

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

the class PatronNoticePoliciesApiTest method canGetPatronNoticePolicy.

@Test
public void canGetPatronNoticePolicy() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
    JsonObject noticePolicy = new JsonObject().put("name", "sample policy");
    String id = postPatronNoticePolicy(noticePolicy).getJson().getString("id");
    CompletableFuture<JsonResponse> getCompleted = new CompletableFuture<>();
    client.get(patronNoticePoliciesStorageUrl("/" + id), TENANT_ID, ResponseHandler.json(getCompleted));
    JsonResponse response = getCompleted.get(5, TimeUnit.SECONDS);
    assertThat(response.getStatusCode(), is(200));
    assertThat(response.getJson().getString("id"), is(id));
    assertThat(response.getJson().getString("name"), is(noticePolicy.getString("name")));
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) JsonObject(io.vertx.core.json.JsonObject) JsonResponse(org.folio.rest.support.JsonResponse) Test(org.junit.Test)

Example 22 with JsonResponse

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

the class PatronNoticePoliciesApiTest method cannotUpdatePatronNoticePolicyWithNotValidSendHow.

@Test
public void cannotUpdatePatronNoticePolicyWithNotValidSendHow() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    JsonObject sendOptions = new JsonObject().put("sendWhen", "Renewed").put("sendHow", "Before");
    JsonObject loanNotice = new JsonObject().put("templateId", UUID.randomUUID().toString()).put("format", "Email").put("realTime", "true").put("sendOptions", sendOptions);
    JsonObject noticePolicy = createNoticePolicyWithLoanNotice(loanNotice);
    JsonResponse response = putPatronNoticePolicy(noticePolicy);
    assertThat(response.getStatusCode(), is(422));
    assertThat(response.getJson().getJsonArray("errors").getJsonObject(0).getString("message"), is("This option is not valid for selected Triggering event"));
}
Also used : JsonObject(io.vertx.core.json.JsonObject) JsonResponse(org.folio.rest.support.JsonResponse) Test(org.junit.Test)

Example 23 with JsonResponse

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

the class RequestBatchAPITest method cannotInjectSqlThroughRequestId.

@Test
public void cannotInjectSqlThroughRequestId() throws Exception {
    UUID itemId = UUID.randomUUID();
    JsonObject firstRequest = createRequestForItemAtPosition(itemId, 1);
    JsonObject firstRequestCopy = firstRequest.copy();
    firstRequestCopy.put("id", "1'; DELETE FROM request where id::text is not '1");
    JsonResponse reorderResponse = attemptReorderRequests(ResponseHandler::json, new ReorderRequest(firstRequestCopy, 3));
    assertValidationError(reorderResponse, containsString("must match"));
    assertRequestsNotUpdated(itemId, firstRequest);
}
Also used : ResponseHandler(org.folio.rest.support.ResponseHandler) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) JsonResponse(org.folio.rest.support.JsonResponse) Test(org.junit.Test)

Example 24 with JsonResponse

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

the class LoanPoliciesApiTest method cannotCreateALoanPolicyWithAdditionalPropertiesInLoanPolicy.

@Test
public void cannotCreateALoanPolicyWithAdditionalPropertiesInLoanPolicy() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
    CompletableFuture<JsonResponse> createCompleted = new CompletableFuture<>();
    UUID id = UUID.randomUUID();
    JsonObject loanPolicyRequest = defaultRollingPolicy().withId(id).withName("Example Loan Policy").withDescription("An example loan policy").create();
    loanPolicyRequest.getJsonObject("loansPolicy").put("anAdditionalProperty", "blah");
    client.post(loanPolicyStorageUrl(), loanPolicyRequest, StorageTestSuite.TENANT_ID, ResponseHandler.json(createCompleted));
    JsonResponse response = createCompleted.get(5, TimeUnit.SECONDS);
    assertThat(String.format("Should fail to create loan policy: %s", response.getBody()), response, matchesUnprocessableEntity());
}
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)

Example 25 with JsonResponse

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

the class LoanPoliciesApiTest method createFixedDueDateSchedule.

private IndividualResource createFixedDueDateSchedule(String name, DateTime from, DateTime to, DateTime dueDate) throws Exception {
    UUID fddId = UUID.randomUUID();
    JsonObject fdd = FixedDueDateApiTest.createFixedDueDate(fddId.toString(), name, "desc");
    JsonObject fddSchedule = FixedDueDateApiTest.createSchedule(from.toString(), to.toString(), dueDate.toString());
    fdd.put(FixedDueDateApiTest.SCHEDULE_SECTION, new JsonArray().add(fddSchedule));
    CompletableFuture<JsonResponse> createCompleted = new CompletableFuture<>();
    client.post(FixedDueDateApiTest.dueDateURL(), fdd, StorageTestSuite.TENANT_ID, ResponseHandler.json(createCompleted));
    JsonResponse response = createCompleted.get(5, TimeUnit.SECONDS);
    assertThat(String.format("Failed to create due date: %s", response.getBody()), response, matchesCreated());
    return new IndividualResource(response);
}
Also used : JsonArray(io.vertx.core.json.JsonArray) CompletableFuture(java.util.concurrent.CompletableFuture) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) IndividualResource(org.folio.rest.support.IndividualResource) JsonResponse(org.folio.rest.support.JsonResponse)

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