Search in sources :

Example 16 with LoanRequestBuilder

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

the class LoansApiTest method canGetALoanById.

@Test
public void canGetALoanById() throws MalformedURLException, InterruptedException, ExecutionException, TimeoutException {
    UUID id = UUID.randomUUID();
    UUID itemId = UUID.randomUUID();
    UUID userId = UUID.randomUUID();
    UUID proxyUserId = UUID.randomUUID();
    JsonObject loanRequest = new LoanRequestBuilder().withId(id).withItemId(itemId).withUserId(userId).withProxyUserId(proxyUserId).withLoanDate(new DateTime(2016, 10, 15, 8, 26, 53, DateTimeZone.UTC)).open().withAction("checkedout").withItemStatus("Checked out").create();
    loansClient.create(loanRequest);
    JsonObject loan = loansClient.getById(id).getJson();
    assertThat("id does not match", loan.getString("id"), is(id.toString()));
    assertThat("user id does not match", loan.getString("userId"), is(userId.toString()));
    assertThat("proxy user id does not match", loan.getString("proxyUserId"), is(proxyUserId.toString()));
    assertThat("item id does not match", loan.getString("itemId"), is(itemId.toString()));
    assertThat("loan date does not match", loan.getString("loanDate"), is("2016-10-15T08:26:53.000Z"));
    assertThat("item status is not checked out", loan.getString("itemStatus"), is("Checked out"));
    assertThat(loan, isOpen());
}
Also used : LoanRequestBuilder(org.folio.rest.support.builders.LoanRequestBuilder) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 17 with LoanRequestBuilder

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

the class LoansApiTest method canCreateAnAlreadyClosedLoanWithoutUserId.

@Test
public void canCreateAnAlreadyClosedLoanWithoutUserId() throws InterruptedException, ExecutionException, TimeoutException, MalformedURLException {
    UUID id = UUID.randomUUID();
    JsonObject loanRequest = new LoanRequestBuilder().withId(id).withNoUserId().closed().create();
    final IndividualResource createLoanResponse = loansClient.create(loanRequest);
    JsonObject loan = createLoanResponse.getJson();
    assertThat(loan, isClosed());
    assertThat("should not have a user ID", loan.containsKey("userId"), is(false));
    assertCreateEventForLoan(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) Test(org.junit.Test)

Example 18 with LoanRequestBuilder

use of org.folio.rest.support.builders.LoanRequestBuilder 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 19 with LoanRequestBuilder

use of org.folio.rest.support.builders.LoanRequestBuilder 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 20 with LoanRequestBuilder

use of org.folio.rest.support.builders.LoanRequestBuilder 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

LoanRequestBuilder (org.folio.rest.support.builders.LoanRequestBuilder)46 Test (org.junit.Test)44 UUID (java.util.UUID)39 JsonObject (io.vertx.core.json.JsonObject)34 DateTime (org.joda.time.DateTime)18 IndividualResource (org.folio.rest.support.IndividualResource)17 JsonResponse (org.folio.rest.support.JsonResponse)16 CompletableFuture (java.util.concurrent.CompletableFuture)9 UUIDMatchers.isUUID (org.folio.rest.support.matchers.UUIDMatchers.isUUID)8 Matchers.containsString (org.hamcrest.Matchers.containsString)6 JsonArray (io.vertx.core.json.JsonArray)5 TextResponse (org.folio.rest.support.TextResponse)5 TRUE (java.lang.Boolean.TRUE)4 HttpURLConnection (java.net.HttpURLConnection)4 MalformedURLException (java.net.MalformedURLException)4 DateFormat (java.text.DateFormat)4 SimpleDateFormat (java.text.SimpleDateFormat)4 Date (java.util.Date)4 List (java.util.List)4 TimeZone (java.util.TimeZone)4