Search in sources :

Example 16 with ItemRequestBuilder

use of api.support.builders.ItemRequestBuilder in project mod-inventory by folio-org.

the class ItemApiExamples method canCreateAnItemWithoutBarcode.

@Test
public void canCreateAnItemWithoutBarcode() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    UUID holdingId = createInstanceAndHolding();
    IndividualResource postResponse = itemsClient.create(new ItemRequestBuilder().forHolding(holdingId).withNoBarcode());
    JsonObject createdItem = itemsClient.getById(postResponse.getId()).getJson();
    assertThat(createdItem.containsKey("barcode"), is(false));
}
Also used : JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) IndividualResource(org.folio.inventory.support.http.client.IndividualResource) ItemRequestBuilder(api.support.builders.ItemRequestBuilder) Test(org.junit.Test)

Example 17 with ItemRequestBuilder

use of api.support.builders.ItemRequestBuilder in project mod-inventory by folio-org.

the class ItemApiExamples method canCreateAnItemWithACirculationNote.

@Test
public void canCreateAnItemWithACirculationNote() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    JsonObject createdInstance = createInstance(smallAngryPlanet(UUID.randomUUID()));
    UUID holdingId = holdingsStorageClient.create(new HoldingRequestBuilder().forInstance(UUID.fromString(createdInstance.getString("id")))).getId();
    JsonObject user = new JsonObject().put(ID_KEY, USER_ID).put(PERSONAL_KEY, new JsonObject().put(LAST_NAME_KEY, "Smith").put(FIRST_NAME_KEY, "John"));
    JsonObject createdUser = usersClient.create(user).getJson();
    DateTime requestMade = DateTime.now();
    IndividualResource postResponse = itemsClient.create(new ItemRequestBuilder().forHolding(holdingId).withBarcode("645398607547").temporarilyInReadingRoom().canCirculate().temporarilyCourseReserves().withCheckInNote());
    JsonObject createdItem = itemsClient.getById(postResponse.getId()).getJson();
    assertThat(createdItem.containsKey("id"), is(true));
    assertThat(createdItem.getString("title"), is("Long Way to a Small Angry Planet"));
    assertThat(createdItem.getString("barcode"), is("645398607547"));
    assertThat(createdItem.getJsonObject("status").getString("name"), is("Available"));
    JsonObject materialType = createdItem.getJsonObject("materialType");
    assertThat(materialType.getString("id"), CoreMatchers.is(ApiTestSuite.getBookMaterialType()));
    assertThat(materialType.getString("name"), is("Book"));
    JsonObject permanentLoanType = createdItem.getJsonObject("permanentLoanType");
    JsonObject temporaryLoanType = createdItem.getJsonObject("temporaryLoanType");
    assertThat(permanentLoanType.getString("id"), is(ApiTestSuite.getCanCirculateLoanType()));
    assertThat(permanentLoanType.getString("name"), is("Can Circulate"));
    assertThat(temporaryLoanType.getString("id"), is(ApiTestSuite.getCourseReserveLoanType()));
    assertThat(temporaryLoanType.getString("name"), is("Course Reserves"));
    assertThat("Item should not have permanent location", createdItem.containsKey("permanentLocation"), is(false));
    assertThat(createdItem.getJsonObject("temporaryLocation").getString("name"), is("Reading Room"));
    JsonObject checkInNote = createdItem.getJsonArray(CIRCULATION_NOTES_KEY).getJsonObject(0);
    JsonObject source = checkInNote.getJsonObject(SOURCE_KEY);
    assertThat(checkInNote.getString(NOTE_TYPE_KEY), is("Check in"));
    assertThat(checkInNote.getString(NOTE_KEY), is("Please read this note before checking in the item"));
    assertThat(checkInNote.getBoolean(STAFF_ONLY_KEY), is(false));
    assertThat(checkInNote.getString(DATE_KEY), withinSecondsAfter(Seconds.seconds(2), requestMade));
    assertThat(source.getString(ID_KEY), is(createdUser.getString(ID_KEY)));
    assertThat(source.getJsonObject(PERSONAL_KEY).getString(LAST_NAME_KEY), is(source.getJsonObject(PERSONAL_KEY).getString(LAST_NAME_KEY)));
    assertThat(source.getJsonObject(PERSONAL_KEY).getString(FIRST_NAME_KEY), is(source.getJsonObject(PERSONAL_KEY).getString(FIRST_NAME_KEY)));
    selfLinkRespectsWayResourceWasReached(createdItem);
    selfLinkShouldBeReachable(createdItem);
}
Also used : HoldingRequestBuilder(api.support.builders.HoldingRequestBuilder) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) IndividualResource(org.folio.inventory.support.http.client.IndividualResource) ItemRequestBuilder(api.support.builders.ItemRequestBuilder) DateTime(org.joda.time.DateTime) Test(org.junit.Test)

Example 18 with ItemRequestBuilder

use of api.support.builders.ItemRequestBuilder in project mod-inventory by folio-org.

the class ItemApiExamples method cannotCreateAnItemWithoutStatus.

@Test
public void cannotCreateAnItemWithoutStatus() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    UUID holdingId = createInstanceAndHolding();
    JsonObject item = new ItemRequestBuilder().forHolding(holdingId).create();
    item.remove("status");
    final var createCompleted = okapiClient.post(items(""), item);
    Response createResponse = createCompleted.toCompletableFuture().get(5, SECONDS);
    assertThat(createResponse, hasValidationError("Status is a required field", "status", null));
}
Also used : Response(org.folio.inventory.support.http.client.Response) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) ItemRequestBuilder(api.support.builders.ItemRequestBuilder) Test(org.junit.Test)

Example 19 with ItemRequestBuilder

use of api.support.builders.ItemRequestBuilder in project mod-inventory by folio-org.

the class ItemApiExamples method canPageAllItems.

@Test
public void canPageAllItems() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    JsonObject smallAngryInstance = createInstance(smallAngryPlanet(UUID.randomUUID()));
    UUID smallAngryHoldingId = holdingsStorageClient.create(new HoldingRequestBuilder().forInstance(UUID.fromString(smallAngryInstance.getString("id"))).withCallNumber(CALL_NUMBER).withCallNumberSuffix(CALL_NUMBER_SUFFIX).withCallNumberPrefix(CALL_NUMBER_PREFIX).withCallNumberTypeId(CALL_NUMBER_TYPE_ID)).getId();
    itemsClient.create(new ItemRequestBuilder().forHolding(smallAngryHoldingId).book().canCirculate().withBarcode("645398607547"));
    itemsClient.create(new ItemRequestBuilder().forHolding(smallAngryHoldingId).book().courseReserves().withBarcode("175848607547"));
    JsonObject girlOnTheTrainInstance = createInstance(girlOnTheTrain(UUID.randomUUID()));
    UUID girlOnTheTrainHoldingId = holdingsStorageClient.create(new HoldingRequestBuilder().forInstance(UUID.fromString(girlOnTheTrainInstance.getString("id"))).withCallNumber(CALL_NUMBER).withCallNumberSuffix(CALL_NUMBER_SUFFIX).withCallNumberPrefix(CALL_NUMBER_PREFIX).withCallNumberTypeId(CALL_NUMBER_TYPE_ID)).getId();
    itemsClient.create(new ItemRequestBuilder().forHolding(girlOnTheTrainHoldingId).dvd().canCirculate().temporarilyCourseReserves().withBarcode("645334645247"));
    JsonObject nodInstance = createInstance(nod(UUID.randomUUID()));
    UUID nodHoldingId = holdingsStorageClient.create(new HoldingRequestBuilder().forInstance(UUID.fromString(nodInstance.getString("id"))).withCallNumber(CALL_NUMBER).withCallNumberSuffix(CALL_NUMBER_SUFFIX).withCallNumberPrefix(CALL_NUMBER_PREFIX).withCallNumberTypeId(CALL_NUMBER_TYPE_ID)).getId();
    itemsClient.create(new ItemRequestBuilder().forHolding(nodHoldingId).book().courseReserves().withBarcode("564566456546"));
    itemsClient.create(new ItemRequestBuilder().forHolding(nodHoldingId).book().courseReserves().withBarcode("943209584495"));
    final var firstPageGetCompleted = okapiClient.get(ApiRoot.items("limit=3"));
    final var secondPageGetCompleted = okapiClient.get(ApiRoot.items("limit=3&offset=3"));
    Response firstPageResponse = firstPageGetCompleted.toCompletableFuture().get(5, SECONDS);
    Response secondPageResponse = secondPageGetCompleted.toCompletableFuture().get(5, SECONDS);
    assertThat(firstPageResponse.getStatusCode(), is(200));
    assertThat(secondPageResponse.getStatusCode(), is(200));
    List<JsonObject> firstPageItems = JsonArrayHelper.toList(firstPageResponse.getJson().getJsonArray("items"));
    assertThat(firstPageItems.size(), is(3));
    assertThat(firstPageResponse.getJson().getInteger("totalRecords"), is(5));
    List<JsonObject> secondPageItems = JsonArrayHelper.toList(secondPageResponse.getJson().getJsonArray("items"));
    assertThat(secondPageItems.size(), is(2));
    assertThat(secondPageResponse.getJson().getInteger("totalRecords"), is(5));
    firstPageItems.forEach(ItemApiExamples::selfLinkRespectsWayResourceWasReached);
    firstPageItems.forEach(this::selfLinkShouldBeReachable);
    firstPageItems.forEach(ItemApiExamples::hasConsistentMaterialType);
    firstPageItems.forEach(ItemApiExamples::hasConsistentPermanentLoanType);
    firstPageItems.forEach(ItemApiExamples::hasConsistentTemporaryLoanType);
    firstPageItems.forEach(ItemApiExamples::hasStatus);
    firstPageItems.forEach(ItemApiExamples::hasConsistentPermanentLocation);
    firstPageItems.forEach(ItemApiExamples::hasConsistentTemporaryLocation);
    firstPageItems.forEach(this::assertCallNumbers);
    secondPageItems.forEach(ItemApiExamples::selfLinkRespectsWayResourceWasReached);
    secondPageItems.forEach(this::selfLinkShouldBeReachable);
    secondPageItems.forEach(ItemApiExamples::hasConsistentMaterialType);
    secondPageItems.forEach(ItemApiExamples::hasConsistentPermanentLoanType);
    secondPageItems.forEach(ItemApiExamples::hasConsistentTemporaryLoanType);
    secondPageItems.forEach(ItemApiExamples::hasStatus);
    secondPageItems.forEach(ItemApiExamples::hasConsistentPermanentLocation);
    secondPageItems.forEach(ItemApiExamples::hasConsistentTemporaryLocation);
    secondPageItems.forEach(this::assertCallNumbers);
}
Also used : Response(org.folio.inventory.support.http.client.Response) HoldingRequestBuilder(api.support.builders.HoldingRequestBuilder) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) ItemRequestBuilder(api.support.builders.ItemRequestBuilder) Test(org.junit.Test)

Example 20 with ItemRequestBuilder

use of api.support.builders.ItemRequestBuilder in project mod-inventory by folio-org.

the class ItemApiExamples method canUpdateExistingItem.

@Test
public void canUpdateExistingItem() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
    UUID TRANSIT_DESTINATION_SERVICE_POINT_ID_FOR_CREATE = UUID.randomUUID();
    UUID TRANSIT_DESTINATION_SERVICE_POINT_ID_FOR_UPDATE = UUID.randomUUID();
    UUID holdingId = createInstanceAndHolding();
    UUID itemId = UUID.randomUUID();
    JsonObject lastCheckIn = new JsonObject().put("servicePointId", "7c5abc9f-f3d7-4856-b8d7-6712462ca007").put("staffMemberId", "12115707-d7c8-54e7-8287-22e97f7250a4").put("dateTime", "2020-01-02T13:02:46.000Z");
    JsonObject newItemRequest = new ItemRequestBuilder().withId(itemId).forHolding(holdingId).withInTransitDestinationServicePointId(TRANSIT_DESTINATION_SERVICE_POINT_ID_FOR_CREATE).withBarcode("645398607547").canCirculate().temporarilyInReadingRoom().withTagList(new JsonObject().put(Item.TAG_LIST_KEY, new JsonArray().add("test-tag"))).withLastCheckIn(lastCheckIn).withCopyNumber("cp").create();
    newItemRequest = itemsClient.create(newItemRequest).getJson();
    assertThat(newItemRequest.getString("copyNumber"), is("cp"));
    assertThat(newItemRequest.getString(Item.TRANSIT_DESTINATION_SERVICE_POINT_ID_KEY), is(TRANSIT_DESTINATION_SERVICE_POINT_ID_FOR_CREATE.toString()));
    JsonObject updateItemRequest = newItemRequest.copy().put("status", new JsonObject().put("name", "Checked out")).put("copyNumber", "updatedCp").put(Item.TRANSIT_DESTINATION_SERVICE_POINT_ID_KEY, TRANSIT_DESTINATION_SERVICE_POINT_ID_FOR_UPDATE).put("tags", new JsonObject().put("tagList", new JsonArray().add("")));
    itemsClient.replace(itemId, updateItemRequest);
    Response getResponse = itemsClient.getById(itemId);
    assertThat(getResponse.getStatusCode(), is(200));
    JsonObject updatedItem = getResponse.getJson();
    assertThat(getTags(updatedItem), hasItem(""));
    assertThat(updatedItem.containsKey("id"), is(true));
    assertThat(updatedItem.getString("title"), is("Long Way to a Small Angry Planet"));
    assertThat(updatedItem.getString("barcode"), is("645398607547"));
    assertThat(updatedItem.getJsonObject("status").getString("name"), is("Checked out"));
    assertThat(updatedItem.getJsonObject(Item.LAST_CHECK_IN).getString("servicePointId"), is("7c5abc9f-f3d7-4856-b8d7-6712462ca007"));
    assertThat(updatedItem.getJsonObject(Item.LAST_CHECK_IN).getString("staffMemberId"), is("12115707-d7c8-54e7-8287-22e97f7250a4"));
    assertThat(updatedItem.getJsonObject(Item.LAST_CHECK_IN).getString("dateTime"), is("2020-01-02T13:02:46.000Z"));
    assertThat(updatedItem.getJsonObject("status").getString("name"), is("Checked out"));
    JsonObject materialType = updatedItem.getJsonObject("materialType");
    assertThat(materialType.getString("id"), is(ApiTestSuite.getBookMaterialType()));
    assertThat(materialType.getString("name"), is("Book"));
    JsonObject permanentLoanType = updatedItem.getJsonObject("permanentLoanType");
    assertThat(permanentLoanType.getString("id"), is(ApiTestSuite.getCanCirculateLoanType()));
    assertThat(permanentLoanType.getString("name"), is("Can Circulate"));
    assertThat("Item should not have permanent location", updatedItem.containsKey("permanentLocation"), is(false));
    assertThat(updatedItem.getJsonObject("temporaryLocation").getString("name"), is("Reading Room"));
    selfLinkRespectsWayResourceWasReached(updatedItem);
    selfLinkShouldBeReachable(updatedItem);
    assertThat(updatedItem.getString("copyNumber"), is("updatedCp"));
    assertThat(updatedItem.getString(Item.TRANSIT_DESTINATION_SERVICE_POINT_ID_KEY), is(TRANSIT_DESTINATION_SERVICE_POINT_ID_FOR_UPDATE.toString()));
}
Also used : JsonArray(io.vertx.core.json.JsonArray) Response(org.folio.inventory.support.http.client.Response) JsonObject(io.vertx.core.json.JsonObject) UUID(java.util.UUID) ItemRequestBuilder(api.support.builders.ItemRequestBuilder) Test(org.junit.Test)

Aggregations

ItemRequestBuilder (api.support.builders.ItemRequestBuilder)96 Test (org.junit.Test)96 IndividualResource (org.folio.inventory.support.http.client.IndividualResource)83 Response (org.folio.inventory.support.http.client.Response)41 JsonObject (io.vertx.core.json.JsonObject)40 UUID (java.util.UUID)38 Parameters (junitparams.Parameters)29 HoldingRequestBuilder (api.support.builders.HoldingRequestBuilder)15 JsonArray (io.vertx.core.json.JsonArray)10 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)6 ItemsMoveRequestBuilder (api.support.builders.ItemsMoveRequestBuilder)5 DateTime (org.joda.time.DateTime)5 URL (java.net.URL)4 List (java.util.List)3 Date (java.util.Date)2 ApiTestSuite (api.ApiTestSuite)1 USER_ID (api.ApiTestSuite.USER_ID)1 ApiTestSuite.getCanCirculateLoanType (api.ApiTestSuite.getCanCirculateLoanType)1 ApiTestSuite.getDvdMaterialType (api.ApiTestSuite.getDvdMaterialType)1 ApiTestSuite.getMainLibraryLocation (api.ApiTestSuite.getMainLibraryLocation)1