Search in sources :

Example 76 with JsonResponse

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

the class RequestsApiTest method canPageRequests.

@Test
public void canPageRequests() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    createEntity(new RequestRequestBuilder().create(), requestStorageUrl());
    createEntity(new RequestRequestBuilder().create(), requestStorageUrl());
    createEntity(new RequestRequestBuilder().create(), requestStorageUrl());
    createEntity(new RequestRequestBuilder().create(), requestStorageUrl());
    createEntity(new RequestRequestBuilder().create(), requestStorageUrl());
    createEntity(new RequestRequestBuilder().create(), requestStorageUrl());
    createEntity(new RequestRequestBuilder().create(), requestStorageUrl());
    CompletableFuture<JsonResponse> firstPageCompleted = new CompletableFuture<>();
    CompletableFuture<JsonResponse> secondPageCompleted = new CompletableFuture<>();
    client.get(requestStorageUrl() + "?limit=4", TENANT_ID, ResponseHandler.json(firstPageCompleted));
    client.get(requestStorageUrl() + "?limit=4&offset=4", 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 requests: %s", firstPageResponse.getBody()), firstPageResponse.getStatusCode(), is(200));
    assertThat(String.format("Failed to get second page of requests: %s", secondPageResponse.getBody()), secondPageResponse.getStatusCode(), is(200));
    JsonObject firstPage = firstPageResponse.getJson();
    JsonObject secondPage = secondPageResponse.getJson();
    JsonArray firstPageRequests = firstPage.getJsonArray("requests");
    JsonArray secondPageRequests = secondPage.getJsonArray("requests");
    assertThat(firstPageRequests.size(), is(4));
    assertThat(firstPage.getInteger("totalRecords"), is(7));
    assertThat(secondPageRequests.size(), is(3));
    assertThat(secondPage.getInteger("totalRecords"), is(7));
}
Also used : JsonArray(io.vertx.core.json.JsonArray) RequestRequestBuilder(org.folio.rest.support.builders.RequestRequestBuilder) CompletableFuture(java.util.concurrent.CompletableFuture) JsonObject(io.vertx.core.json.JsonObject) JsonResponse(org.folio.rest.support.JsonResponse) Test(org.junit.Test)

Example 77 with JsonResponse

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

the class RequestsApiTest method canSearchRequestsByUserProxyId.

@Test
public void canSearchRequestsByUserProxyId() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
    UUID firstRequester = UUID.randomUUID();
    JsonObject j1 = new RequestRequestBuilder().withRequesterId(firstRequester).create();
    JsonObject j2 = new RequestRequestBuilder().withRequesterId(firstRequester).create();
    JsonObject j3 = new RequestRequestBuilder().withRequesterId(firstRequester).create();
    String userProxy1 = UUID.randomUUID().toString();
    String userProxy2 = UUID.randomUUID().toString();
    String userProxy3 = UUID.randomUUID().toString();
    j1.put("proxyUserId", userProxy1);
    j2.put("proxyUserId", userProxy2);
    j3.put("proxyUserId", userProxy3);
    createEntity(j1, requestStorageUrl());
    createEntity(j2, requestStorageUrl());
    createEntity(j3, requestStorageUrl());
    CompletableFuture<JsonResponse> getRequestsCompleted = new CompletableFuture<>();
    client.get(requestStorageUrl() + String.format("?query=proxyUserId=%s", userProxy1), 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(1));
    assertThat(wrappedRequests.getInteger("totalRecords"), is(1));
    CompletableFuture<JsonResponse> getRequestsCompleted2 = new CompletableFuture<>();
    String query = String.format("proxyUserId<>%s", UUID.randomUUID());
    client.get(requestStorageUrl() + "?query=" + URLEncoder.encode(query, UTF_8), TENANT_ID, ResponseHandler.json(getRequestsCompleted2));
    JsonResponse getRequestsResponse2 = getRequestsCompleted2.get(5, TimeUnit.SECONDS);
    assertThat(String.format("Failed to get requests: %s", getRequestsResponse2.getBody()), getRequestsResponse2.getStatusCode(), is(HttpURLConnection.HTTP_OK));
    JsonObject wrappedRequests2 = getRequestsResponse2.getJson();
    assertThat(wrappedRequests2.getJsonArray("requests").size(), is(3));
    assertThat(wrappedRequests2.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 78 with JsonResponse

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

the class RequestsApiTest method updateFailRequestsByUserProxyId.

@Test
public void updateFailRequestsByUserProxyId() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
    UUID requestId = UUID.randomUUID();
    JsonObject j1 = new RequestRequestBuilder().withId(requestId).create();
    String userProxy1 = UUID.randomUUID().toString();
    j1.put("proxyUserId", userProxy1);
    createEntity(j1, requestStorageUrl());
    // /////////// try to update with a bad proxId ////////////////////
    j1.put("proxyUserId", "12345");
    CompletableFuture<JsonResponse> createCompleted = new CompletableFuture<>();
    client.put(requestStorageUrl("/" + requestId), j1, TENANT_ID, ResponseHandler.json(createCompleted));
    JsonResponse putResponse = createCompleted.get(5, TimeUnit.SECONDS);
    assertThat(String.format("Failed to create request: %s", putResponse.getBody()), putResponse.getStatusCode(), is(422));
}
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 79 with JsonResponse

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

the class RequestsApiTest method canSortRequestsByAscendingRequestDate.

@Test
public void canSortRequestsByAscendingRequestDate() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException, UnsupportedEncodingException {
    UUID itemId = UUID.randomUUID();
    createEntity(new RequestRequestBuilder().withItemId(itemId).withRequestDate(new DateTime(2018, 2, 14, 15, 10, 54, DateTimeZone.UTC)).withPosition(1).create(), requestStorageUrl()).getId();
    createEntity(new RequestRequestBuilder().withItemId(itemId).withRequestDate(new DateTime(2017, 11, 24, 12, 31, 27, DateTimeZone.UTC)).withPosition(2).create(), requestStorageUrl()).getId();
    createEntity(new RequestRequestBuilder().withItemId(itemId).withRequestDate(new DateTime(2018, 2, 4, 15, 10, 54, DateTimeZone.UTC)).withPosition(3).create(), requestStorageUrl()).getId();
    createEntity(new RequestRequestBuilder().withItemId(itemId).withRequestDate(new DateTime(2018, 1, 12, 12, 31, 27, DateTimeZone.UTC)).withPosition(4).create(), requestStorageUrl()).getId();
    CompletableFuture<JsonResponse> getRequestsCompleted = new CompletableFuture<>();
    String query = URLEncoder.encode(String.format("itemId==%s sortBy requestDate/sort.ascending", itemId), UTF_8);
    client.get(requestStorageUrl() + String.format("?query=%s", query), 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();
    List<JsonObject> requests = JsonArrayHelper.toList(wrappedRequests.getJsonArray("requests"));
    assertThat(requests.size(), is(4));
    assertThat(wrappedRequests.getInteger("totalRecords"), is(4));
    List<String> sortedRequestDates = requests.stream().map(request -> request.getString("requestDate")).collect(Collectors.toList());
    assertThat(sortedRequestDates, contains("2017-11-24T12:31:27.000+00:00", "2018-01-12T12:31:27.000+00:00", "2018-02-04T15:10:54.000+00:00", "2018-02-14T15:10:54.000+00:00"));
}
Also used : CLOSED_UNFILLED(org.folio.rest.support.builders.RequestRequestBuilder.CLOSED_UNFILLED) HttpURLConnection(java.net.HttpURLConnection) ResponseHandler(org.folio.rest.support.ResponseHandler) ValidationResponseMatchers.isValidationResponseWhich(org.folio.rest.support.matchers.ValidationResponseMatchers.isValidationResponseWhich) JsonResponse(org.folio.rest.support.JsonResponse) Response(org.folio.rest.support.Response) ResourceClient(org.folio.rest.support.clients.ResourceClient) DateTimeZone(org.joda.time.DateTimeZone) TENANT_ID(org.folio.rest.api.StorageTestSuite.TENANT_ID) IsIterableContainingInOrder.contains(org.hamcrest.collection.IsIterableContainingInOrder.contains) URL(java.net.URL) TimeoutException(java.util.concurrent.TimeoutException) Autowired(org.springframework.beans.factory.annotation.Autowired) OPEN_NOT_YET_FILLED(org.folio.rest.support.builders.RequestRequestBuilder.OPEN_NOT_YET_FILLED) Matchers.hasItems(org.hamcrest.Matchers.hasItems) JsonArrayHelper(org.folio.rest.support.JsonArrayHelper) SpringMethodRule(org.springframework.test.context.junit4.rules.SpringMethodRule) TextDateTimeMatcher.equivalentTo(org.folio.rest.support.matchers.TextDateTimeMatcher.equivalentTo) TextDateTimeMatcher.withinSecondsAfter(org.folio.rest.support.matchers.TextDateTimeMatcher.withinSecondsAfter) IsNull.nullValue(org.hamcrest.core.IsNull.nullValue) Seconds(org.joda.time.Seconds) Arrays.asList(java.util.Arrays.asList) After(org.junit.After) Is.is(org.hamcrest.core.Is.is) JsonObject(io.vertx.core.json.JsonObject) JUnitParamsRunner(junitparams.JUnitParamsRunner) ClassRule(org.junit.ClassRule) OPEN_IN_TRANSIT(org.folio.rest.support.builders.RequestRequestBuilder.OPEN_IN_TRANSIT) StringUtil(org.folio.util.StringUtil) ISODateTimeFormat(org.joda.time.format.ISODateTimeFormat) ValidationErrorMatchers.hasMessageContaining(org.folio.rest.support.matchers.ValidationErrorMatchers.hasMessageContaining) TextResponse(org.folio.rest.support.TextResponse) UUID(java.util.UUID) Collectors(java.util.stream.Collectors) CLOSED_CANCELLED(org.folio.rest.support.builders.RequestRequestBuilder.CLOSED_CANCELLED) List(java.util.List) CLOSED_FILLED(org.folio.rest.support.builders.RequestRequestBuilder.CLOSED_FILLED) CLOSED_PICKUP_EXPIRED(org.folio.rest.support.builders.RequestRequestBuilder.CLOSED_PICKUP_EXPIRED) ValidationErrorMatchers.hasErrorWith(org.folio.rest.support.matchers.ValidationErrorMatchers.hasErrorWith) CqlQuery.fromTemplate(org.folio.rest.support.clients.CqlQuery.fromTemplate) UnsupportedEncodingException(java.io.UnsupportedEncodingException) Parameters(junitparams.Parameters) Tags(org.folio.rest.jaxrs.model.Tags) CoreMatchers.not(org.hamcrest.CoreMatchers.not) RunWith(org.junit.runner.RunWith) CompletableFuture(java.util.concurrent.CompletableFuture) IndividualResource(org.folio.rest.support.IndividualResource) RequestItemSummary(org.folio.rest.support.builders.RequestItemSummary) DomainEventAssertions.assertNoRequestEvent(org.folio.rest.support.matchers.DomainEventAssertions.assertNoRequestEvent) RequestRequestBuilder(org.folio.rest.support.builders.RequestRequestBuilder) OPEN_AWAITING_DELIVERY(org.folio.rest.support.builders.RequestRequestBuilder.OPEN_AWAITING_DELIVERY) Matchers.hasSize(org.hamcrest.Matchers.hasSize) SpringClassRule(org.springframework.test.context.junit4.rules.SpringClassRule) MatcherAssert.assertThat(org.hamcrest.MatcherAssert.assertThat) MatcherAssert(org.hamcrest.junit.MatcherAssert) DomainEventAssertions.assertRemoveEventForRequest(org.folio.rest.support.matchers.DomainEventAssertions.assertRemoveEventForRequest) TestContextConfiguration(org.folio.rest.support.spring.TestContextConfiguration) Before(org.junit.Before) DomainEventAssertions.assertUpdateEventForRequest(org.folio.rest.support.matchers.DomainEventAssertions.assertUpdateEventForRequest) MalformedURLException(java.net.MalformedURLException) UTF_8(java.nio.charset.StandardCharsets.UTF_8) DomainEventAssertions.assertCreateEventForRequest(org.folio.rest.support.matchers.DomainEventAssertions.assertCreateEventForRequest) DateTime(org.joda.time.DateTime) RequestDto(org.folio.rest.support.dto.RequestDto) Test(org.junit.Test) ValidationErrorMatchers.hasMessage(org.folio.rest.support.matchers.ValidationErrorMatchers.hasMessage) ApiTests(org.folio.rest.support.ApiTests) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) JsonArray(io.vertx.core.json.JsonArray) URLEncoder(java.net.URLEncoder) Matchers.hasItem(org.hamcrest.Matchers.hasItem) Rule(org.junit.Rule) OPEN_AWAITING_PICKUP(org.folio.rest.support.builders.RequestRequestBuilder.OPEN_AWAITING_PICKUP) HTTP_CREATED(java.net.HttpURLConnection.HTTP_CREATED) IsNull.notNullValue(org.hamcrest.core.IsNull.notNullValue) ContextConfiguration(org.springframework.test.context.ContextConfiguration) CqlQuery.exactMatch(org.folio.rest.support.clients.CqlQuery.exactMatch) RequestRequestBuilder(org.folio.rest.support.builders.RequestRequestBuilder) CompletableFuture(java.util.concurrent.CompletableFuture) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) DateTime(org.joda.time.DateTime) JsonResponse(org.folio.rest.support.JsonResponse) Test(org.junit.Test)

Example 80 with JsonResponse

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

the class RequestsApiTest method cannotCreateTitleLevelRequestIfOneOfItemIdAndHoldingsRecordIdIsNotPresent.

@Test
@Parameters({ "holdingsRecordId", "itemId" })
public void cannotCreateTitleLevelRequestIfOneOfItemIdAndHoldingsRecordIdIsNotPresent(String propertyToRemove) throws MalformedURLException, ExecutionException, InterruptedException, TimeoutException {
    String requestLevel = "Title";
    CompletableFuture<JsonResponse> createCompleted = new CompletableFuture<>();
    JsonObject request = new RequestRequestBuilder().recall().toHoldShelf().withRequestLevel(requestLevel).create();
    request.remove(propertyToRemove);
    client.post(requestStorageUrl(), request, TENANT_ID, ResponseHandler.json(createCompleted));
    JsonObject response = createCompleted.get(5, TimeUnit.SECONDS).getJson();
    assertThat(response, hasErrorWith(hasMessageContaining("Title level request must have both itemId and holdingsRecordId or neither")));
}
Also used : CompletableFuture(java.util.concurrent.CompletableFuture) RequestRequestBuilder(org.folio.rest.support.builders.RequestRequestBuilder) JsonObject(io.vertx.core.json.JsonObject) JsonResponse(org.folio.rest.support.JsonResponse) Parameters(junitparams.Parameters) 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