Search in sources :

Example 81 with JsonResponse

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

the class RequestsApiTest method canSearchForRequestsForAnItem.

@Test
public void canSearchForRequestsForAnItem() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
    UUID itemId = UUID.randomUUID();
    UUID otherItemId = UUID.randomUUID();
    createEntity(new RequestRequestBuilder().withItemId(itemId).withPosition(1).create(), requestStorageUrl());
    createEntity(new RequestRequestBuilder().withItemId(itemId).withPosition(2).create(), requestStorageUrl());
    createEntity(new RequestRequestBuilder().withItemId(otherItemId).withPosition(1).create(), requestStorageUrl());
    CompletableFuture<JsonResponse> getRequestsCompleted = new CompletableFuture<>();
    client.get(requestStorageUrl() + String.format("?query=itemId==%s", itemId), TENANT_ID, ResponseHandler.json(getRequestsCompleted));
    JsonResponse getRequestsResponse = getRequestsCompleted.get(5, TimeUnit.SECONDS);
    assertThat(String.format("Failed to get requests: %s", getRequestsResponse.getBody()), getRequestsResponse.getStatusCode(), is(HttpURLConnection.HTTP_OK));
    JsonObject wrappedRequests = getRequestsResponse.getJson();
    assertThat(wrappedRequests.getJsonArray("requests").size(), is(2));
    assertThat(wrappedRequests.getInteger("totalRecords"), is(2));
}
Also used : RequestRequestBuilder(org.folio.rest.support.builders.RequestRequestBuilder) 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 82 with JsonResponse

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

the class RequestsApiTest method canSearchForRequestsByRequesterId.

@Test
public void canSearchForRequestsByRequesterId() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
    UUID firstRequester = UUID.randomUUID();
    UUID secondRequester = UUID.randomUUID();
    createEntity(new RequestRequestBuilder().withRequesterId(firstRequester).create(), requestStorageUrl());
    createEntity(new RequestRequestBuilder().withRequesterId(firstRequester).create(), requestStorageUrl());
    createEntity(new RequestRequestBuilder().withRequesterId(secondRequester).create(), requestStorageUrl());
    createEntity(new RequestRequestBuilder().withRequesterId(firstRequester).create(), requestStorageUrl());
    createEntity(new RequestRequestBuilder().withRequesterId(firstRequester).create(), requestStorageUrl());
    createEntity(new RequestRequestBuilder().withRequesterId(secondRequester).create(), requestStorageUrl());
    createEntity(new RequestRequestBuilder().withRequesterId(secondRequester).create(), requestStorageUrl());
    CompletableFuture<JsonResponse> getRequestsCompleted = new CompletableFuture<>();
    client.get(requestStorageUrl() + String.format("?query=requesterId=%s", secondRequester), TENANT_ID, ResponseHandler.json(getRequestsCompleted));
    JsonResponse getRequestsResponse = getRequestsCompleted.get(5, TimeUnit.SECONDS);
    assertThat(String.format("Failed to get requests: %s", getRequestsResponse.getBody()), getRequestsResponse.getStatusCode(), is(HttpURLConnection.HTTP_OK));
    JsonObject wrappedRequests = getRequestsResponse.getJson();
    assertThat(wrappedRequests.getJsonArray("requests").size(), is(3));
    assertThat(wrappedRequests.getInteger("totalRecords"), is(3));
}
Also used : RequestRequestBuilder(org.folio.rest.support.builders.RequestRequestBuilder) 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 83 with JsonResponse

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

the class PatronActionSessionAPITest method getExpiredPatronSessions.

private JsonArray getExpiredPatronSessions(String actionType, int limit, DateTime lastActionDateLimit) throws InterruptedException, ExecutionException, TimeoutException, MalformedURLException {
    String actionTypeFilter = actionType != null ? actionType : "";
    URL url = StorageTestSuite.storageUrl("/patron-action-session-storage/expired-session-patron-ids", "action_type", actionTypeFilter, "session_inactivity_time_limit", lastActionDateLimit.toString(ISODateTimeFormat.dateTime()), "limit", Integer.toString(limit));
    JsonResponse response = get(url);
    assertThat(response, isOk());
    return response.getJson().getJsonArray("expiredSessions");
}
Also used : URL(java.net.URL) JsonResponse(org.folio.rest.support.JsonResponse)

Example 84 with JsonResponse

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

the class PatronActionSessionAPITest method get.

private JsonResponse get(URL url) throws InterruptedException, ExecutionException, TimeoutException {
    final CompletableFuture<JsonResponse> getCompleted = new CompletableFuture<>();
    this.client.get(url, StorageTestSuite.TENANT_ID, ResponseHandler.json(getCompleted));
    final JsonResponse response = getCompleted.get(5, TimeUnit.SECONDS);
    return response;
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) JsonResponse(org.folio.rest.support.JsonResponse)

Example 85 with JsonResponse

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

the class PatronActionSessionAPITest method canUpdatePatronActiveSession.

@Test
public void canUpdatePatronActiveSession() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    JsonObject request = createPatronActionSession("Check-out");
    String id = assertRecordClient.create(request).getJson().getString("id");
    request.put("loanId", existingLoanId).put("actionType", "Check-in");
    JsonResponse response = assertRecordClient.attemptPutById(request);
    assertThat("Failed to update patron active session", response.getStatusCode(), is(204));
    IndividualResource updatedPatronActionSession = assertRecordClient.getById(id);
    assertThat(updatedPatronActionSession.getJson().getString("loanId"), is(existingLoanId));
    assertThat(updatedPatronActionSession.getJson().getString("actionType"), is("Check-in"));
}
Also used : JsonObject(io.vertx.core.json.JsonObject) IndividualResource(org.folio.rest.support.IndividualResource) 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