Search in sources :

Example 16 with JsonResponse

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

the class LoansApiTest method canFilterByLoanStatus.

@Test
public void canFilterByLoanStatus() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
    UUID userId = UUID.randomUUID();
    String queryTemplate = "query=userId=%s+and+status.name=%s";
    loansClient.create(loanRequest(userId, "Open"));
    loansClient.create(loanRequest(userId, "Open"));
    loansClient.create(loanRequest(userId, "Closed"));
    loansClient.create(loanRequest(userId, "Closed"));
    loansClient.create(loanRequest(userId, "Closed"));
    loansClient.create(loanRequest(userId, "Closed"));
    CompletableFuture<JsonResponse> openSearchComppleted = new CompletableFuture<>();
    CompletableFuture<JsonResponse> closedSearchCompleted = new CompletableFuture<>();
    client.get(InterfaceUrls.loanStorageUrl(), String.format(queryTemplate, userId, "Open"), StorageTestSuite.TENANT_ID, ResponseHandler.json(openSearchComppleted));
    client.get(InterfaceUrls.loanStorageUrl(), String.format(queryTemplate, userId, "Closed"), StorageTestSuite.TENANT_ID, ResponseHandler.json(closedSearchCompleted));
    JsonResponse openLoansResponse = openSearchComppleted.get(5, TimeUnit.SECONDS);
    JsonResponse closedLoansResponse = closedSearchCompleted.get(5, TimeUnit.SECONDS);
    assertThat(String.format("Failed to get open loans: %s", openLoansResponse.getBody()), openLoansResponse.getStatusCode(), is(200));
    assertThat(String.format("Failed to get closed loans: %s", closedLoansResponse.getBody()), closedLoansResponse.getStatusCode(), is(200));
    JsonObject openLoans = openLoansResponse.getJson();
    JsonObject closedLoans = closedLoansResponse.getJson();
    JsonArray firstPageLoans = openLoans.getJsonArray("loans");
    JsonArray secondPageLoans = closedLoans.getJsonArray("loans");
    assertThat(firstPageLoans.size(), is(2));
    assertThat(openLoans.getInteger("totalRecords"), is(2));
    assertThat(secondPageLoans.size(), is(4));
    assertThat(closedLoans.getInteger("totalRecords"), is(4));
}
Also used : JsonArray(io.vertx.core.json.JsonArray) CompletableFuture(java.util.concurrent.CompletableFuture) JsonObject(io.vertx.core.json.JsonObject) Matchers.containsString(org.hamcrest.Matchers.containsString) UUID(java.util.UUID) JsonResponse(org.folio.rest.support.JsonResponse) Test(org.junit.Test)

Example 17 with JsonResponse

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

the class LoansApiTest method cannotCreateALoanWithInvalidDates.

@Test
public void cannotCreateALoanWithInvalidDates() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
    JsonObject loanRequest = new LoanRequestBuilder().create();
    loanRequest.put("loanDate", "foo").put("returnDate", "bar");
    JsonResponse response = loansClient.attemptCreate(loanRequest);
    assertThat(String.format("Creating the loan should fail: %s", response.getBody()), response.getStatusCode(), is(HttpURLConnection.HTTP_BAD_REQUEST));
    assertThat(response.getBody(), containsString("loan date must be a date time (in RFC3339 format)"));
    assertThat(response.getBody(), containsString("return date must be a date time (in RFC3339 format)"));
    assertNoLoanEvent(loanRequest.getString("id"));
}
Also used : LoanRequestBuilder(org.folio.rest.support.builders.LoanRequestBuilder) JsonObject(io.vertx.core.json.JsonObject) JsonResponse(org.folio.rest.support.JsonResponse) Test(org.junit.Test)

Example 18 with JsonResponse

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

the class PatronNoticePoliciesApiTest method cannotCreatePatronNoticePolicyWithNotUniqueName.

@Test
public void cannotCreatePatronNoticePolicyWithNotUniqueName() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
    JsonObject noticePolicy = new JsonObject().put("name", "sample policy");
    postPatronNoticePolicy(noticePolicy);
    JsonResponse response = postPatronNoticePolicy(noticePolicy);
    String code = response.getJson().getJsonArray("errors").getJsonObject(0).getString("code");
    assertThat(response.getStatusCode(), is(422));
    assertThat(code, is(STATUS_CODE_DUPLICATE_NAME));
}
Also used : JsonObject(io.vertx.core.json.JsonObject) JsonResponse(org.folio.rest.support.JsonResponse) Test(org.junit.Test)

Example 19 with JsonResponse

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

the class PatronNoticePoliciesApiTest method cannotDeleteNonexistentPatronNoticePolicyId.

@Test
public void cannotDeleteNonexistentPatronNoticePolicyId() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
    String id = UUID.randomUUID().toString();
    JsonResponse response = deletePatronNoticePolicy(id);
    assertThat(response.getStatusCode(), is(404));
    assertThat(response.getBody(), is(NOT_FOUND));
}
Also used : JsonResponse(org.folio.rest.support.JsonResponse) Test(org.junit.Test)

Example 20 with JsonResponse

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

the class PatronNoticePoliciesApiTest method cannotDeleteInUsePatronNoticePolicy.

@Test
public void cannotDeleteInUsePatronNoticePolicy() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    String inUsePolicyId = "16b88363-0d93-464a-967a-ad5ad0f9187c";
    String rulesAsText = "priority: t, s, c, b, a, m, g" + "fallback-policy: l 43198de5-f56a-4a53-a0bd-5a324418967a r 4c6e1fb0-2ef1-4666-bd15-f9190ff89060 " + "n 122b3d2b-4788-4f1e-9117-56daa91cb75c m 1a54b431-2e4f-452d-9cae-9cee66c9a892: " + "l d9cd0bed-1b49-4b5e-a7bd-064b8d177231 r 334e5a9e-94f9-4673-8d1d-ab552863886b n " + inUsePolicyId;
    JsonObject circulationRules = new JsonObject().put("rulesAsText", rulesAsText);
    CompletableFuture<TextResponse> putCompleted = new CompletableFuture<>();
    client.put(rulesStorageUrl(), circulationRules, TENANT_ID, ResponseHandler.text(putCompleted));
    putCompleted.get(5, TimeUnit.SECONDS);
    JsonResponse response = deletePatronNoticePolicy(inUsePolicyId);
    String message = response.getBody();
    assertThat(response.getStatusCode(), is(400));
    assertThat(message, is("Cannot delete in use notice policy"));
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) JsonObject(io.vertx.core.json.JsonObject) TextResponse(org.folio.rest.support.TextResponse) 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