Search in sources :

Example 96 with JsonResponse

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

the class LoanPoliciesApiTest method getById.

private JsonResponse getById(UUID id) throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
    URL getInstanceUrl = loanPolicyStorageUrl(String.format("/%s", id));
    CompletableFuture<JsonResponse> getCompleted = new CompletableFuture<>();
    client.get(getInstanceUrl, StorageTestSuite.TENANT_ID, ResponseHandler.json(getCompleted));
    return getCompleted.get(5, TimeUnit.SECONDS);
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) URL(java.net.URL) JsonResponse(org.folio.rest.support.JsonResponse)

Example 97 with JsonResponse

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

the class LoanPoliciesApiTest method canPageLoanPolicies.

@Test
public void canPageLoanPolicies() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    createLoanPolicy(defaultRollingPolicy().create());
    createLoanPolicy(defaultRollingPolicy().create());
    createLoanPolicy(defaultRollingPolicy().create());
    createLoanPolicy(defaultRollingPolicy().create());
    createLoanPolicy(defaultRollingPolicy().create());
    createLoanPolicy(defaultRollingPolicy().create());
    createLoanPolicy(defaultRollingPolicy().create());
    CompletableFuture<JsonResponse> firstPageCompleted = new CompletableFuture<>();
    CompletableFuture<JsonResponse> secondPageCompleted = new CompletableFuture<>();
    client.get(loanPolicyStorageUrl() + "?limit=4", StorageTestSuite.TENANT_ID, ResponseHandler.json(firstPageCompleted));
    client.get(loanPolicyStorageUrl() + "?limit=4&offset=4", StorageTestSuite.TENANT_ID, ResponseHandler.json(secondPageCompleted));
    JsonResponse firstPageResponse = firstPageCompleted.get(5, TimeUnit.SECONDS);
    JsonResponse secondPageResponse = secondPageCompleted.get(5, TimeUnit.SECONDS);
    MatcherAssert.assertThat(String.format("Failed to get first page of loan policies: %s", firstPageResponse.getBody()), firstPageResponse.getStatusCode(), is(200));
    MatcherAssert.assertThat(String.format("Failed to get second page of loans policies: %s", secondPageResponse.getBody()), secondPageResponse.getStatusCode(), is(200));
    JsonObject firstPage = firstPageResponse.getJson();
    JsonObject secondPage = secondPageResponse.getJson();
    JsonArray firstPageLoans = firstPage.getJsonArray("loanPolicies");
    JsonArray secondPageLoans = secondPage.getJsonArray("loanPolicies");
    MatcherAssert.assertThat(firstPageLoans.size(), is(4));
    MatcherAssert.assertThat(firstPage.getInteger("totalRecords"), is(7));
    MatcherAssert.assertThat(secondPageLoans.size(), is(3));
    MatcherAssert.assertThat(secondPage.getInteger("totalRecords"), is(7));
}
Also used : JsonArray(io.vertx.core.json.JsonArray) CompletableFuture(java.util.concurrent.CompletableFuture) JsonObject(io.vertx.core.json.JsonObject) JsonResponse(org.folio.rest.support.JsonResponse) Test(org.junit.Test)

Example 98 with JsonResponse

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

the class LoanPoliciesApiTest method cannotCreateLoanPolicyWithItemLimitBelowMinimum.

@Test
public void cannotCreateLoanPolicyWithItemLimitBelowMinimum() 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", 0);
    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 greater than or equal to 1"));
    assertThat(parameters.getString("key"), is("loansPolicy.itemLimit"));
    assertThat(parameters.getString("value"), is("0"));
}
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 99 with JsonResponse

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

the class LoanPoliciesApiTest method cannotUseRenewalsPeriodForFixedProfile.

@Test
public void cannotUseRenewalsPeriodForFixedProfile() throws Exception {
    DateTime from = DateTime.now().minusMonths(3);
    DateTime to = DateTime.now().plusMonths(3);
    DateTime dueDate = to.plusDays(15);
    IndividualResource fixedDueDateSchedule = createFixedDueDateSchedule("semester fixed policy test", from, to, dueDate);
    LoanPolicyRequestBuilder loanPolicy = emptyPolicy().fixed(fixedDueDateSchedule.getId()).withAlternateFixedDueDateScheduleId(fixedDueDateSchedule.getId()).withName("test").withRenewalPeriod(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("Period in RenewalsPolicy 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 100 with JsonResponse

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

the class LoanPoliciesApiTest method canCreateALoanPolicyWithoutAnId.

@Test
public void canCreateALoanPolicyWithoutAnId() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    CompletableFuture<JsonResponse> createCompleted = new CompletableFuture<>();
    JsonObject loanPolicyRequest = defaultRollingPolicy().withNoId().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(notNullValue()));
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) JsonObject(io.vertx.core.json.JsonObject) 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