use of org.folio.inventory.support.http.client.Response 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.Response 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.Response in project mod-inventory by folio-org.
the class ItemApiExamples method cannotCreateItemWithUnrecognisedStatusName.
@Test
public void cannotCreateItemWithUnrecognisedStatusName() throws InterruptedException, ExecutionException, TimeoutException {
JsonObject itemWithUnrecognizedStatus = new ItemRequestBuilder().forHolding(UUID.randomUUID()).withBarcode("645398607547").temporarilyInReadingRoom().create().put("status", new JsonObject().put("name", "Unrecognized name"));
final var postCompleted = okapiClient.post(items(""), itemWithUnrecognizedStatus);
Response response = postCompleted.toCompletableFuture().get(5, SECONDS);
assertThat(response, hasValidationError("Undefined status specified", "status.name", "Unrecognized name"));
}
use of org.folio.inventory.support.http.client.Response 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.Response in project mod-inventory by folio-org.
the class ItemApiExamples method cannotRemoveHRID.
@Test
public void cannotRemoveHRID() throws Exception {
UUID holdingId = createInstanceAndHolding();
IndividualResource postResponse = itemsClient.create(new ItemRequestBuilder().forHolding(holdingId).withHrid("it777").withBarcode("645398607547").temporarilyInReadingRoom());
JsonObject createdItem = postResponse.getJson();
assertThat(createdItem.getString("hrid"), notNullValue());
JsonObject updatedItem = createdItem.copy().put("barcode", "645398607548").put("itemLevelCallNumber", "callNumber");
updatedItem.remove("hrid");
Response updateResponse = updateItem(updatedItem);
assertThat(updateResponse, hasValidationError("HRID can not be updated", "hrid", null));
JsonObject existingItem = itemsClient.getById(postResponse.getId()).getJson();
assertThat(existingItem, is(createdItem));
}
Aggregations