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));
}
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));
}
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));
}
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));
}
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);
}
Aggregations