Search in sources :

Example 26 with JsonResponse

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

the class LoanPoliciesApiTest method cannotCreateLoanPolicyWithItemLimitAboveMaximum.

@Test
public void cannotCreateLoanPolicyWithItemLimitAboveMaximum() 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("itemLimit", 10_000);
    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());
    JsonObject error = getErrorFromResponse(response);
    JsonObject parameters = error.getJsonArray("parameters").getJsonObject(0);
    assertThat(error.getString("message"), is("must be less than or equal to 9999"));
    assertThat(parameters.getString("key"), is("loansPolicy.itemLimit"));
    assertThat(parameters.getString("value"), is("10000"));
}
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 27 with JsonResponse

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

the class LoanPoliciesApiTest method cannotUseHoldAlternateRenewalLoanPeriodForFixedProfile.

@Test
public void cannotUseHoldAlternateRenewalLoanPeriodForFixedProfile() throws Exception {
    DateTime from = DateTime.now().minusMonths(3);
    DateTime to = DateTime.now().plusMonths(3);
    DateTime dueDate = to.plusDays(15);
    IndividualResource fixedDueDateSchedule = createFixedDueDateSchedule("semester_for_fixed_policy", from, to, dueDate);
    LoanPolicyRequestBuilder loanPolicy = emptyPolicy().fixed(fixedDueDateSchedule.getId()).withAlternateFixedDueDateScheduleId(fixedDueDateSchedule.getId()).withHoldsRenewalLoanPeriod(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("Alternate Renewal Loan Period for Holds is not allowed for policies with Fixed profile"));
}
Also used : LoanPolicyRequestBuilder(org.folio.rest.support.builders.LoanPolicyRequestBuilder) CompletableFuture(java.util.concurrent.CompletableFuture) org.folio.rest.support.matchers.periodJsonObjectMatcher.matchesPeriod(org.folio.rest.support.matchers.periodJsonObjectMatcher.matchesPeriod) Period(org.folio.rest.jaxrs.model.Period) IndividualResource(org.folio.rest.support.IndividualResource) DateTime(org.joda.time.DateTime) JsonResponse(org.folio.rest.support.JsonResponse) Test(org.junit.Test)

Example 28 with JsonResponse

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

the class LoanPoliciesApiTest method postLoanPolicyWith422.

/**
 * Assert that a POST of the loanPolicyRequest returns a 422 HTTP status code.
 * @return the body with the validation failure message
 */
private JsonObject postLoanPolicyWith422(JsonObject loanPolicyRequest) {
    try {
        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("Expected validation failure when creating loan policy: request=%s, response=%s", loanPolicyRequest.encodePrettily(), postResponse.getBody()), postResponse, matchesUnprocessableEntity());
        return postResponse.getJson();
    } catch (MalformedURLException | InterruptedException | ExecutionException | TimeoutException e) {
        throw new RuntimeException(e.getMessage() + ": " + loanPolicyRequest.encodePrettily(), e);
    }
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) MalformedURLException(java.net.MalformedURLException) ExecutionException(java.util.concurrent.ExecutionException) JsonResponse(org.folio.rest.support.JsonResponse) TimeoutException(java.util.concurrent.TimeoutException)

Example 29 with JsonResponse

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

the class LoanPoliciesApiTest method canDeleteALoanPolicy.

@Test
public void canDeleteALoanPolicy() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    CompletableFuture<JsonResponse> deleteCompleted = new CompletableFuture<>();
    UUID id = UUID.randomUUID();
    createLoanPolicy(defaultRollingPolicy().withId(id).create());
    client.delete(loanPolicyStorageUrl(String.format("/%s", id.toString())), StorageTestSuite.TENANT_ID, ResponseHandler.json(deleteCompleted));
    JsonResponse createResponse = deleteCompleted.get(5, TimeUnit.SECONDS);
    assertThat(String.format("Failed to delete loan policy: %s", createResponse.getBody()), createResponse, matchesNoContent());
    JsonResponse getResponse = getById(id);
    assertThat(String.format("Found a deleted loan policy: %s", getResponse.getBody()), getResponse, matchesNotFound());
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) UUID(java.util.UUID) JsonResponse(org.folio.rest.support.JsonResponse) Test(org.junit.Test)

Example 30 with JsonResponse

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

the class LoanPoliciesApiTest method canGetALoanPolicyById.

@Test
public void canGetALoanPolicyById() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    UUID id = UUID.randomUUID();
    createLoanPolicy(defaultRollingPolicy().withId(id).create());
    JsonResponse getResponse = getById(id);
    assertThat(String.format("Failed to get loan policy: %s", getResponse.getBody()), getResponse, matchesOk());
    JsonObject representation = getResponse.getJson();
    assertThat(representation.getString("id"), is(notNullValue()));
    assertThat(representation.getString("description"), is("An example loan policy"));
    assertThat(representation.getString("name"), is("Example Loan Policy"));
    assertThat(representation.getBoolean("loanable"), is(true));
    assertThat(representation.getBoolean("renewable"), is(true));
    assertThat(representation.containsKey("loansPolicy"), 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"));
    assertThat(loansPolicy.getJsonObject("openingTimeOffset"), matchesPeriod(3, "Hours"));
    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"));
}
Also used : 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