Search in sources :

Example 71 with JsonResponse

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

the class ScheduledNoticesAPITest method canGetScheduledNoticesCollectionByQuery.

@Test
public void canGetScheduledNoticesCollectionByQuery() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
    String templateId = UUID.randomUUID().toString();
    JsonObject noticeConfig1 = new JsonObject().put("timing", "Upon At").put("templateId", templateId).put("format", "Email");
    JsonObject noticeConfig2 = new JsonObject().put("timing", "Upon At").put("templateId", UUID.randomUUID().toString()).put("format", "Email");
    String nextRunTime = new DateTime(UTC).toString();
    postScheduledNotice(new JsonObject().put("nextRunTime", nextRunTime).put("triggeringEvent", "Request expiration").put("noticeConfig", noticeConfig1));
    postScheduledNotice(new JsonObject().put("nextRunTime", nextRunTime).put("triggeringEvent", "Hold expiration").put("noticeConfig", noticeConfig1));
    postScheduledNotice(new JsonObject().put("nextRunTime", nextRunTime).put("triggeringEvent", "Due date").put("noticeConfig", noticeConfig2));
    String query = "query=noticeConfig.templateId=" + templateId;
    CompletableFuture<JsonResponse> getCompleted = new CompletableFuture<>();
    client.get(scheduledNoticesStorageUrl("/scheduled-notices?" + query), TENANT_ID, ResponseHandler.json(getCompleted));
    JsonResponse response = getCompleted.get(5, SECONDS);
    ScheduledNotices scheduledNotices = response.getJson().mapTo(ScheduledNotices.class);
    assertThat(scheduledNotices.getScheduledNotices().size(), is(2));
    assertThat(scheduledNotices.getTotalRecords(), is(2));
}
Also used : ScheduledNotices(org.folio.rest.jaxrs.model.ScheduledNotices) CompletableFuture(java.util.concurrent.CompletableFuture) JsonObject(io.vertx.core.json.JsonObject) DateTime(org.joda.time.DateTime) JsonResponse(org.folio.rest.support.JsonResponse) Test(org.junit.Test)

Example 72 with JsonResponse

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

the class ScheduledNoticesAPITest method canGetScheduledNoticesCollection.

@Test
public void canGetScheduledNoticesCollection() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
    for (String triggeringEvent : ALL_TRIGGERING_EVENTS) {
        createScheduledNotice(triggeringEvent);
    }
    CompletableFuture<JsonResponse> getCompleted = new CompletableFuture<>();
    client.get(scheduledNoticesStorageUrl("/scheduled-notices"), TENANT_ID, ResponseHandler.json(getCompleted));
    JsonResponse response = getCompleted.get(5, SECONDS);
    ScheduledNotices scheduledNotices = response.getJson().mapTo(ScheduledNotices.class);
    assertThat(scheduledNotices.getScheduledNotices().size(), is(9));
    assertThat(scheduledNotices.getTotalRecords(), is(9));
}
Also used : ScheduledNotices(org.folio.rest.jaxrs.model.ScheduledNotices) CompletableFuture(java.util.concurrent.CompletableFuture) JsonResponse(org.folio.rest.support.JsonResponse) Test(org.junit.Test)

Example 73 with JsonResponse

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

the class ScheduledNoticesAPITest method canDeleteAllScheduledNotices.

@Test
public void canDeleteAllScheduledNotices() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    createScheduledNotice(org.folio.rest.jaxrs.model.NoticeConfig.Timing.BEFORE, ONE_DAY_PERIOD, UUID.randomUUID().toString(), EMAIL);
    createScheduledNotice(org.folio.rest.jaxrs.model.NoticeConfig.Timing.AFTER, ONE_MONTH_PERIOD, UUID.randomUUID().toString(), org.folio.rest.jaxrs.model.NoticeConfig.Format.SMS);
    CompletableFuture<Response> deleteCompleted = new CompletableFuture<>();
    client.delete(scheduledNoticesStorageUrl("/scheduled-notices"), TENANT_ID, ResponseHandler.empty(deleteCompleted));
    deleteCompleted.get(5, SECONDS);
    CompletableFuture<JsonResponse> getCompleted = new CompletableFuture<>();
    client.get(scheduledNoticesStorageUrl("/scheduled-notices"), TENANT_ID, ResponseHandler.json(getCompleted));
    JsonResponse response = getCompleted.get(5, SECONDS);
    ScheduledNotices scheduledNotices = response.getJson().mapTo(ScheduledNotices.class);
    assertThat(scheduledNotices.getScheduledNotices().size(), is(0));
    assertThat(scheduledNotices.getTotalRecords(), is(0));
}
Also used : JsonResponse(org.folio.rest.support.JsonResponse) Response(org.folio.rest.support.Response) ScheduledNotices(org.folio.rest.jaxrs.model.ScheduledNotices) CompletableFuture(java.util.concurrent.CompletableFuture) JsonResponse(org.folio.rest.support.JsonResponse) Test(org.junit.Test)

Example 74 with JsonResponse

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

the class RequestsApiTest method canSortRequestsByAscendingPosition.

@Test
public void canSortRequestsByAscendingPosition() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException, UnsupportedEncodingException {
    UUID itemId = UUID.randomUUID();
    // Deliberately create requests out of order to demonstrate sorting,
    // should not happen under normal circumstances
    createEntity(new RequestRequestBuilder().withItemId(itemId).withPosition(2).create(), requestStorageUrl()).getId();
    createEntity(new RequestRequestBuilder().withItemId(itemId).withPosition(1).create(), requestStorageUrl()).getId();
    createEntity(new RequestRequestBuilder().withItemId(itemId).withPosition(4).create(), requestStorageUrl()).getId();
    createEntity(new RequestRequestBuilder().withItemId(itemId).withPosition(3).create(), requestStorageUrl()).getId();
    CompletableFuture<JsonResponse> getRequestsCompleted = new CompletableFuture<>();
    String query = URLEncoder.encode(String.format("itemId==%s sortBy position/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<Integer> sortedPositions = requests.stream().map(request -> request.getInteger("position")).collect(Collectors.toList());
    assertThat(sortedPositions, contains(1, 2, 3, 4));
}
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) JsonResponse(org.folio.rest.support.JsonResponse) Test(org.junit.Test)

Example 75 with JsonResponse

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

the class RequestsApiTest method createdRequestHasCreationMetadata.

@Test
public void createdRequestHasCreationMetadata() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    CompletableFuture<JsonResponse> createCompleted = new CompletableFuture<>();
    String creatorId = UUID.randomUUID().toString();
    DateTime requestMade = DateTime.now();
    client.post(requestStorageUrl(), new RequestRequestBuilder().create(), TENANT_ID, creatorId, ResponseHandler.json(createCompleted));
    JsonResponse postResponse = createCompleted.get(5, TimeUnit.SECONDS);
    assertThat(String.format("Failed to create request: %s", postResponse.getBody()), postResponse.getStatusCode(), is(HTTP_CREATED));
    JsonObject createdRequest = postResponse.getJson();
    assertThat("Request should have metadata property", createdRequest.containsKey(METADATA_PROPERTY), is(true));
    JsonObject metadata = createdRequest.getJsonObject(METADATA_PROPERTY);
    assertThat("Request should have created user", metadata.getString("createdByUserId"), is(creatorId));
    assertThat("Request should have created date close to when request was made", metadata.getString("createdDate"), is(withinSecondsAfter(Seconds.seconds(2), requestMade)));
    // RAML-Module-Builder also populates updated information at creation time
    assertThat("Request should have updated user", metadata.getString("updatedByUserId"), is(creatorId));
    assertThat("Request should have update date close to when request was made", metadata.getString("updatedDate"), is(withinSecondsAfter(Seconds.seconds(2), requestMade)));
    assertCreateEventForRequest(createdRequest);
}
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) DateTime(org.joda.time.DateTime) 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