Search in sources :

Example 86 with JsonResponse

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

the class PatronActionSessionAPITest method cannotGetPatronActionSessionStorageExpiredSessionPatronIds.

@Test
public void cannotGetPatronActionSessionStorageExpiredSessionPatronIds() throws InterruptedException, ExecutionException, TimeoutException, MalformedURLException {
    URL url = StorageTestSuite.storageUrl("/patron-action-session-storage/expired-session-patron-ids", "action_type", "Check-out", "session_inactivity_time_limit", "wrong date", "limit", Integer.toString(10));
    JsonResponse response = get(url);
    assertThat(response.getStatusCode(), is(422));
    assertThat(response.getJson().getJsonArray("errors").getJsonObject(0).getString("message"), is("Date cannot be parsed"));
}
Also used : URL(java.net.URL) JsonResponse(org.folio.rest.support.JsonResponse) Test(org.junit.Test)

Example 87 with JsonResponse

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

the class PatronActionSessionAPITest method cannotUpdateNonExistentActionSession.

@Test
public void cannotUpdateNonExistentActionSession() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    JsonObject nonExistPatronActionSession = createPatronActionSession("Check-out");
    JsonResponse response = assertRecordClient.attemptPutById(nonExistPatronActionSession);
    assertThat(response.getStatusCode(), is(404));
}
Also used : JsonObject(io.vertx.core.json.JsonObject) JsonResponse(org.folio.rest.support.JsonResponse) Test(org.junit.Test)

Example 88 with JsonResponse

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

the class PatronActionSessionAPITest method cannotGetPatronActionSessionStorageExpiredSessionPatronIdsWithWrongActionType.

@Test
public void cannotGetPatronActionSessionStorageExpiredSessionPatronIdsWithWrongActionType() throws InterruptedException, ExecutionException, TimeoutException, MalformedURLException {
    String firstPatronId = UUID.randomUUID().toString();
    createPatronActionSessionRecords(firstPatronId, "Check-in", DateTime.now().minusDays(2));
    URL url = StorageTestSuite.storageUrl("/patron-action-session-storage/expired-session-patron-ids", "action_type", "WrongType", "session_inactivity_time_limit", DateTime.now().minusDays(2).toString(ISODateTimeFormat.dateTime()), "limit", "10");
    JsonResponse response = get(url);
    assertThat(response.getStatusCode(), is(422));
    assertThat(response.getJson().getJsonArray("errors").getJsonObject(0).getString("message"), is("Invalid action type value"));
}
Also used : URL(java.net.URL) JsonResponse(org.folio.rest.support.JsonResponse) Test(org.junit.Test)

Example 89 with JsonResponse

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

the class PatronNoticePoliciesApiTest method canGetAllPatronNoticePolicies.

@Test
public void canGetAllPatronNoticePolicies() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
    JsonObject firstPolicy = new JsonObject().put("name", "first policy");
    JsonObject secondPolicy = new JsonObject().put("name", "second policy");
    postPatronNoticePolicy(firstPolicy);
    postPatronNoticePolicy(secondPolicy);
    CompletableFuture<JsonResponse> getAllCompleted = new CompletableFuture<>();
    client.get(patronNoticePoliciesStorageUrl(), TENANT_ID, ResponseHandler.json(getAllCompleted));
    JsonResponse response = getAllCompleted.get(5, TimeUnit.SECONDS);
    assertThat("Failed to get all patron notice policies", response.getStatusCode(), is(200));
    JsonArray policies = response.getJson().getJsonArray("patronNoticePolicies");
    assertThat(policies.size(), is(2));
    assertThat(response.getJson().getInteger("totalRecords"), is(2));
    String[] names = policies.stream().map(JsonObject.class::cast).map(json -> json.getString("name")).toArray(String[]::new);
    assertThat(names, arrayContainingInAnyOrder(firstPolicy.getString("name"), secondPolicy.getString("name")));
}
Also used : JsonArray(io.vertx.core.json.JsonArray) CoreMatchers.is(org.hamcrest.CoreMatchers.is) ResponseHandler(org.folio.rest.support.ResponseHandler) JsonResponse(org.folio.rest.support.JsonResponse) JsonObject.mapFrom(io.vertx.core.json.JsonObject.mapFrom) TENANT_ID(org.folio.rest.api.StorageTestSuite.TENANT_ID) URL(java.net.URL) IsArrayContainingInAnyOrder.arrayContainingInAnyOrder(org.hamcrest.collection.IsArrayContainingInAnyOrder.arrayContainingInAnyOrder) TimeoutException(java.util.concurrent.TimeoutException) CompletableFuture(java.util.concurrent.CompletableFuture) ArrayList(java.util.ArrayList) PATRON_NOTICE_POLICY_TABLE(org.folio.rest.impl.PatronNoticePoliciesAPI.PATRON_NOTICE_POLICY_TABLE) JsonObject(io.vertx.core.json.JsonObject) RowSet(io.vertx.sqlclient.RowSet) MatcherAssert.assertThat(org.hamcrest.junit.MatcherAssert.assertThat) SendBy(org.folio.rest.jaxrs.model.SendBy) Before(org.junit.Before) SendOptions(org.folio.rest.jaxrs.model.SendOptions) CirculationRulesApiTest.rulesStorageUrl(org.folio.rest.api.CirculationRulesApiTest.rulesStorageUrl) MalformedURLException(java.net.MalformedURLException) TextResponse(org.folio.rest.support.TextResponse) Test(org.junit.Test) UUID(java.util.UUID) ApiTests(org.folio.rest.support.ApiTests) PostgresClient(org.folio.rest.persist.PostgresClient) ExecutionException(java.util.concurrent.ExecutionException) TimeUnit(java.util.concurrent.TimeUnit) NOT_FOUND(org.folio.rest.impl.PatronNoticePoliciesAPI.NOT_FOUND) JsonArray(io.vertx.core.json.JsonArray) List(java.util.List) Criterion(org.folio.rest.persist.Criteria.Criterion) PatronNoticePolicy(org.folio.rest.jaxrs.model.PatronNoticePolicy) Row(io.vertx.sqlclient.Row) STATUS_CODE_DUPLICATE_NAME(org.folio.rest.impl.PatronNoticePoliciesAPI.STATUS_CODE_DUPLICATE_NAME) LoanNotice(org.folio.rest.jaxrs.model.LoanNotice) CompletableFuture(java.util.concurrent.CompletableFuture) JsonObject(io.vertx.core.json.JsonObject) JsonResponse(org.folio.rest.support.JsonResponse) Test(org.junit.Test)

Example 90 with JsonResponse

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

the class PatronNoticePoliciesApiTest method canUpdatePatronNoticePolicy.

@Test
public void canUpdatePatronNoticePolicy() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
    JsonObject noticePolicy = new JsonObject().put("name", "sample policy");
    String id = postPatronNoticePolicy(noticePolicy).getJson().getString("id");
    JsonObject sendOptions = new JsonObject().put("sendWhen", "Request expiration");
    String templateId = UUID.randomUUID().toString();
    JsonObject requestNotice = new JsonObject().put("templateId", templateId).put("format", "Email").put("realTime", "true").put("sendOptions", sendOptions);
    noticePolicy.put("id", id).put("description", "new description").put("requestNotices", new JsonArray().add(requestNotice));
    JsonResponse response = putPatronNoticePolicy(noticePolicy);
    assertThat("Failed to update patron notice policy", response.getStatusCode(), is(204));
    JsonObject updatedPolicy = getPatronNoticePolicyById(id).getJson();
    JsonObject updatedRequestNotice = updatedPolicy.getJsonArray("requestNotices").getJsonObject(0);
    JsonObject updatedSendOptions = updatedRequestNotice.getJsonObject("sendOptions");
    assertThat(updatedPolicy.getString("description"), is("new description"));
    assertThat(updatedRequestNotice.getString("templateId"), is(templateId));
    assertThat(updatedRequestNotice.getString("format"), is("Email"));
    assertThat(updatedRequestNotice.getBoolean("realTime"), is(true));
    assertThat(updatedSendOptions.getString("sendWhen"), is("Request expiration"));
}
Also used : JsonArray(io.vertx.core.json.JsonArray) JsonObject(io.vertx.core.json.JsonObject) 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