use of api.support.builders.HoldingRequestBuilder in project mod-inventory by folio-org.
the class ItemApiExamples method cannotSearchForItemsByTitle.
@Test
public void cannotSearchForItemsByTitle() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
JsonObject smallAngryInstance = createInstance(smallAngryPlanet(UUID.randomUUID()));
UUID smallAngryHoldingId = holdingsStorageClient.create(new HoldingRequestBuilder().forInstance(UUID.fromString(smallAngryInstance.getString("id")))).getId();
itemsClient.create(new ItemRequestBuilder().forHolding(smallAngryHoldingId).book().canCirculate().withBarcode("645398607547"));
JsonObject nodInstance = createInstance(nod(UUID.randomUUID()));
UUID nodHoldingId = holdingsStorageClient.create(new HoldingRequestBuilder().forInstance(UUID.fromString(nodInstance.getString("id")))).getId();
itemsClient.create(new ItemRequestBuilder().forHolding(nodHoldingId).book().canCirculate().withBarcode("564566456546"));
final var searchGetCompleted = okapiClient.get(ApiRoot.items("query=title=*Small%20Angry*"));
Response searchGetResponse = searchGetCompleted.toCompletableFuture().get(5, SECONDS);
assertThat(searchGetResponse.getStatusCode(), is(200));
List<JsonObject> items = JsonArrayHelper.toList(searchGetResponse.getJson().getJsonArray("items"));
assertThat(items.size(), is(0));
assertThat(searchGetResponse.getJson().getInteger("totalRecords"), is(0));
}
use of api.support.builders.HoldingRequestBuilder 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);
}
use of api.support.builders.HoldingRequestBuilder in project mod-inventory by folio-org.
the class ItemApiExamples method createInstanceAndHolding.
private UUID createInstanceAndHolding() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
UUID instanceId = UUID.randomUUID();
createInstance(smallAngryPlanet(instanceId));
return holdingsStorageClient.create(new HoldingRequestBuilder().forInstance(instanceId)).getId();
}
use of api.support.builders.HoldingRequestBuilder 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);
}
use of api.support.builders.HoldingRequestBuilder in project mod-inventory by folio-org.
the class ItemApiExamples method canChangeBarcodeForExistingItem.
@Test
public void canChangeBarcodeForExistingItem() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
JsonObject nodInstance = createInstance(nod(UUID.randomUUID()));
UUID nodHoldingId = holdingsStorageClient.create(new HoldingRequestBuilder().forInstance(UUID.fromString(nodInstance.getString("id")))).getId();
IndividualResource nodItemResponse = itemsClient.create(new ItemRequestBuilder().forHolding(nodHoldingId).book().canCirculate().withBarcode("654647774352"));
JsonObject changedNodItem = nodItemResponse.getJson().copy().put("barcode", "645398607547");
URL nodItemLocation = new URL(String.format("%s/%s", ApiRoot.items(), nodItemResponse.getId()));
final var putItemCompleted = okapiClient.put(nodItemLocation, changedNodItem);
Response putItemResponse = putItemCompleted.toCompletableFuture().get(5, SECONDS);
assertThat(putItemResponse.getStatusCode(), is(204));
final var getItemCompleted = okapiClient.get(nodItemLocation);
Response getItemResponse = getItemCompleted.toCompletableFuture().get(5, SECONDS);
assertThat(getItemResponse.getStatusCode(), is(200));
assertThat(getItemResponse.getJson().getString("barcode"), is("645398607547"));
}
Aggregations