Search in sources :

Example 11 with JsonResponse

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

the class LoansApiTest method canSearchByUserId.

@Test
public void canSearchByUserId() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
    UUID firstUserId = UUID.randomUUID();
    UUID secondUserId = UUID.randomUUID();
    String queryTemplate = InterfaceUrls.loanStorageUrl() + "?query=userId='%s'";
    loansClient.create(new LoanRequestBuilder().withUserId(firstUserId).create());
    loansClient.create(new LoanRequestBuilder().withUserId(firstUserId).create());
    loansClient.create(new LoanRequestBuilder().withUserId(firstUserId).create());
    loansClient.create(new LoanRequestBuilder().withUserId(firstUserId).create());
    loansClient.create(new LoanRequestBuilder().withUserId(secondUserId).create());
    loansClient.create(new LoanRequestBuilder().withUserId(secondUserId).create());
    loansClient.create(new LoanRequestBuilder().withUserId(secondUserId).create());
    CompletableFuture<JsonResponse> firstUserSearchCompleted = new CompletableFuture<>();
    CompletableFuture<JsonResponse> secondUserSeatchCompleted = new CompletableFuture<>();
    client.get(String.format(queryTemplate, firstUserId), StorageTestSuite.TENANT_ID, ResponseHandler.json(firstUserSearchCompleted));
    client.get(String.format(queryTemplate, secondUserId), StorageTestSuite.TENANT_ID, ResponseHandler.json(secondUserSeatchCompleted));
    JsonResponse firstPageResponse = firstUserSearchCompleted.get(5, TimeUnit.SECONDS);
    JsonResponse secondPageResponse = secondUserSeatchCompleted.get(5, TimeUnit.SECONDS);
    assertThat(String.format("Failed to get loans for first user: %s", firstPageResponse.getBody()), firstPageResponse.getStatusCode(), is(200));
    assertThat(String.format("Failed to get loans for second user: %s", secondPageResponse.getBody()), secondPageResponse.getStatusCode(), is(200));
    JsonObject firstPage = firstPageResponse.getJson();
    JsonObject secondPage = secondPageResponse.getJson();
    JsonArray firstPageLoans = firstPage.getJsonArray("loans");
    JsonArray secondPageLoans = secondPage.getJsonArray("loans");
    assertThat(firstPageLoans.size(), is(4));
    assertThat(firstPage.getInteger("totalRecords"), is(4));
    assertThat(secondPageLoans.size(), is(3));
    assertThat(secondPage.getInteger("totalRecords"), is(3));
}
Also used : JsonArray(io.vertx.core.json.JsonArray) CompletableFuture(java.util.concurrent.CompletableFuture) LoanRequestBuilder(org.folio.rest.support.builders.LoanRequestBuilder) JsonObject(io.vertx.core.json.JsonObject) Matchers.containsString(org.hamcrest.Matchers.containsString) UUID(java.util.UUID) JsonResponse(org.folio.rest.support.JsonResponse) Test(org.junit.Test)

Example 12 with JsonResponse

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

the class LoansApiTest method cannotCreateMultipleOpenLoansForSameItem.

@Test
public void cannotCreateMultipleOpenLoansForSameItem() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    UUID itemId = UUID.randomUUID();
    JsonObject firstLoanRequest = new LoanRequestBuilder().withItemId(itemId).open().create();
    loansClient.create(firstLoanRequest);
    JsonObject firstLoan = loansClient.getById(firstLoanRequest.getString("id")).getJson();
    JsonObject secondLoanRequest = new LoanRequestBuilder().withItemId(itemId).open().create();
    JsonResponse response = loansClient.attemptCreate(secondLoanRequest);
    assertThat(response, isValidationResponseWhich(hasMessage("Cannot have more than one open loan for the same item")));
    assertCreateEventForLoan(firstLoan);
    assertNoLoanEvent(secondLoanRequest.getString("id"));
}
Also used : LoanRequestBuilder(org.folio.rest.support.builders.LoanRequestBuilder) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) JsonResponse(org.folio.rest.support.JsonResponse) Test(org.junit.Test)

Example 13 with JsonResponse

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

the class LoansApiTest method canDeleteALoan.

@Test
public void canDeleteALoan() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    UUID id = UUID.randomUUID();
    IndividualResource loanResouce = loansClient.create(new LoanRequestBuilder().withId(id).create());
    loansClient.deleteById(id);
    JsonResponse getResponse = loansClient.attemptGetById(id);
    assertThat(getResponse, isNotFound());
    JsonObject loan = loanResouce.getJson();
    assertCreateEventForLoan(loan);
    assertRemoveEventForLoan(loan);
}
Also used : LoanRequestBuilder(org.folio.rest.support.builders.LoanRequestBuilder) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) IndividualResource(org.folio.rest.support.IndividualResource) JsonResponse(org.folio.rest.support.JsonResponse) Test(org.junit.Test)

Example 14 with JsonResponse

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

the class LoansApiTest method cannotProvideAdditionalPropertiesInLoanStatus.

@Test
public void cannotProvideAdditionalPropertiesInLoanStatus() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    UUID id = UUID.randomUUID();
    JsonObject requestWithAdditionalProperty = new LoanRequestBuilder().withId(id).create();
    requestWithAdditionalProperty.getJsonObject("status").put("somethingAdditional", "foo");
    JsonResponse response = loansClient.attemptCreate(requestWithAdditionalProperty);
    assertThat(response, isValidationResponseWhich(hasMessageContaining("Unrecognized field")));
    assertNoLoanEvent(id.toString());
}
Also used : LoanRequestBuilder(org.folio.rest.support.builders.LoanRequestBuilder) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) JsonResponse(org.folio.rest.support.JsonResponse) Test(org.junit.Test)

Example 15 with JsonResponse

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

the class LoansApiTest method cannotCreateALoanWithoutAction.

@Test
public void cannotCreateALoanWithoutAction() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
    JsonObject loanRequest = new LoanRequestBuilder().create();
    loanRequest.remove("action");
    JsonResponse response = loansClient.attemptCreate(loanRequest);
    assertThat(response, isValidationResponseWhich(allOf(// any server language
    anyOf(hasMessage("must not be null"), hasMessage("darf nicht null sein")), hasParameter("action", "null"))));
    assertNoLoanEvent(loanRequest.getString("id"));
}
Also used : LoanRequestBuilder(org.folio.rest.support.builders.LoanRequestBuilder) 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