use of org.folio.inventory.support.http.client.IndividualResource in project mod-inventory by folio-org.
the class ItemApiExamples method canCreateItemWithAnIDAndHRID.
@Test
public void canCreateItemWithAnIDAndHRID() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
UUID itemId = UUID.randomUUID();
final String hrid = "it777";
UUID holdingId = createInstanceAndHolding();
IndividualResource postResponse = itemsClient.create(new ItemRequestBuilder().withId(itemId).withHrid(hrid).forHolding(holdingId).withBarcode("645398607547").temporarilyInReadingRoom().canCirculate().withTagList(new JsonObject().put(Item.TAG_LIST_KEY, new JsonArray().add("test-tag").add("test-tag2"))).temporarilyCourseReserves());
JsonObject createdItem = itemsClient.getById(postResponse.getId()).getJson();
assertThat(createdItem.containsKey("id"), is(true));
assertThat(createdItem.getString("id"), is(itemId.toString()));
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(getTags(createdItem), hasItems("test-tag", "test-tag2"));
assertThat(materialType.getString("id"), 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"));
selfLinkRespectsWayResourceWasReached(createdItem);
selfLinkShouldBeReachable(createdItem);
assertThat(createdItem.getString("hrid"), is(hrid));
}
use of org.folio.inventory.support.http.client.IndividualResource in project mod-inventory by folio-org.
the class ItemApiExamples method cannotUpdateItemToSameBarcodeAsExistingItem.
@Test
public void cannotUpdateItemToSameBarcodeAsExistingItem() 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();
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(400));
assertThat(putItemResponse.getBody(), is("Barcode must be unique, 645398607547 is already assigned to another item"));
}
use of org.folio.inventory.support.http.client.IndividualResource in project mod-inventory by folio-org.
the class ItemApiExamples method CanDeleteSingleItem.
@Test
public void CanDeleteSingleItem() throws InterruptedException, MalformedURLException, TimeoutException, ExecutionException {
JsonObject createdInstance = createInstance(smallAngryPlanet(UUID.randomUUID()));
UUID holdingId = holdingsStorageClient.create(new HoldingRequestBuilder().forInstance(UUID.fromString(createdInstance.getString("id")))).getId();
itemsClient.create(new ItemRequestBuilder().forHolding(holdingId).withBarcode("645398607547"));
IndividualResource itemToDeleteResponse = itemsClient.create(new ItemRequestBuilder().forHolding(holdingId).withBarcode("175848607547"));
itemsClient.create(new ItemRequestBuilder().forHolding(holdingId).withBarcode("645334645247"));
itemsClient.delete(itemToDeleteResponse.getId());
final var getAllCompleted = okapiClient.get(ApiRoot.items());
Response getAllResponse = getAllCompleted.toCompletableFuture().get(5, SECONDS);
assertThat(getAllResponse.getJson().getJsonArray("items").size(), is(2));
assertThat(getAllResponse.getJson().getInteger("totalRecords"), is(2));
}
use of org.folio.inventory.support.http.client.IndividualResource in project mod-inventory by folio-org.
the class ItemApiExamples method cannotChangeHRID.
@Test
public void cannotChangeHRID() throws Exception {
UUID holdingId = createInstanceAndHolding();
IndividualResource postResponse = itemsClient.create(new ItemRequestBuilder().forHolding(holdingId).withBarcode("645398607547").temporarilyInReadingRoom());
JsonObject createdItem = postResponse.getJson();
assertThat(createdItem.getString("hrid"), notNullValue());
JsonObject updatedItem = createdItem.copy().put("barcode", "645398607548").put("itemLevelCallNumber", "callNumber").put("hrid", "updatedHrid");
Response updateResponse = updateItem(updatedItem);
assertThat(updateResponse, hasValidationError("HRID can not be updated", "hrid", "updatedHrid"));
JsonObject existingItem = itemsClient.getById(postResponse.getId()).getJson();
assertThat(existingItem, is(createdItem));
}
use of org.folio.inventory.support.http.client.IndividualResource in project mod-inventory by folio-org.
the class ItemApiExamples method canCreateAnItemWithACirculationNoteWithoutSourceField.
@Test
public void canCreateAnItemWithACirculationNoteWithoutSourceField() 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);
checkInNote.remove("source");
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));
selfLinkRespectsWayResourceWasReached(createdItem);
selfLinkShouldBeReachable(createdItem);
}
Aggregations